Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preset): add preset template and rule for Hibernate JFR #750

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.15.2</quarkus.platform.version>
<quarkus-quinoa.version>2.5.1</quarkus-quinoa.version>
<org.hibernate.orm.hibernate.jfr.version>6.6.4.Final</org.hibernate.orm.hibernate.jfr.version><!-- TODO is there some way to grab the Hibernate version used by Quarkus to match this version? -->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a discussion about this here: quarkusio/quarkus#45552

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quarkus 3.15.2 with the Panache/Hibernate extension pulls in Hibernate 6.6.1, which I originally used in this PR to keep the Hibernate JFR version in sync. But, it runs into hibernate/hibernate-orm#9180 , so I upgraded to a later bugfix version to work around this.

<org.codehaus.mojo.build.helper.plugin.version>3.6.0</org.codehaus.mojo.build.helper.plugin.version>
<org.codehaus.mojo.exec.plugin.version>3.5.0</org.codehaus.mojo.exec.plugin.version>
<assembly-plugin.version>3.7.1</assembly-plugin.version>
Expand Down Expand Up @@ -199,6 +200,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jfr</artifactId>
<version>${org.hibernate.orm.hibernate.jfr.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/docker/include/rule_presets/hibernate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "hibernate",
"description": "Preset Automated Rule for enabling Hibernate ORM events when available",
"eventSpecifier": "template=Hibernate,type=PRESET",
"matchExpression": "jfrEventTypeIds(target).exists(x, x.startsWith(\"org.hibernate.orm.\"))",
"enabled": false
}
2 changes: 1 addition & 1 deletion src/main/docker/include/rule_presets/quarkus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "quarkus",
"description": "Preset Automated Rule for enabling Quarkus framework-specific events when available",
"eventSpecifier": "template=Quarkus,type=PRESET",
"matchExpression": "jfrEventTypeIds(target).exists(x, x.startsWith(\"quarkus\"))",
"matchExpression": "jfrEventTypeIds(target).exists(x, x.startsWith(\"quarkus.\"))",
"enabled": false
}
42 changes: 42 additions & 0 deletions src/main/docker/include/template_presets/hibernate.jfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration version="2.0" label="Hibernate" description="Hibernate ORM events" provider="Cryostat">
<event name="org.hibernate.orm.CacheGet">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.CachePut">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.DirtyCalculationEvent">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.FlushEvent">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.JdbcBatchExecution">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.JdbcConnectionAcquisition">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.JdbcConnectionRelease">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.JdbcPreparedStatementCreation">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.JdbcPreparedStatementExecution">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.PartialFlushEvent">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.PrePartialFlushEvent">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.SessionClosed">
<setting name="enabled">true</setting>
</event>
<event name="org.hibernate.orm.SessionOpen">
<setting name="enabled">true</setting>
</event>
</configuration>
18 changes: 9 additions & 9 deletions src/main/docker/include/template_presets/quarkus.jfc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration version="2.0" label="Quarkus" description="Quarkus-specific REST events" provider="Cryostat">
<event name="quarkus.Rest">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestStart">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestEnd">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.Rest">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestStart">
<setting name="enabled">true</setting>
</event>
<event name="quarkus.RestEnd">
<setting name="enabled">true</setting>
</event>
</configuration>
34 changes: 17 additions & 17 deletions src/test/java/itest/PresetRulesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package itest;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -29,10 +31,14 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@QuarkusIntegrationTest
public class PresetRulesIT extends StandardSelfTest {

static final String[] RULE_NAMES = new String[] {"quarkus", "hibernate"};

@Test
public void shouldListPresetRules() throws Exception {
CompletableFuture<JsonArray> future = new CompletableFuture<>();
Expand All @@ -46,32 +52,26 @@ public void shouldListPresetRules() throws Exception {
future.complete(ar.result().bodyAsJsonArray());
});
JsonArray response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(response.size(), Matchers.equalTo(1));
MatcherAssert.assertThat(response.size(), Matchers.equalTo(RULE_NAMES.length));
}

@Test
public void shouldHavePresetQuarkusRule() throws Exception {
String url = "/api/v4/rules/quarkus";
static List<String> ruleNames() {
return Arrays.asList(RULE_NAMES);
}

@ParameterizedTest
@MethodSource("ruleNames")
public void shouldHavePresetRules(String ruleName) throws Exception {
String url = String.format("/api/v4/rules/%s", ruleName);
File file =
downloadFile(url, "quarkus", ".json")
downloadFile(url, ruleName, ".json")
.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.toFile();

ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree(file);

MatcherAssert.assertThat(json.get("name").asText(), Matchers.equalTo("quarkus"));
MatcherAssert.assertThat(
json.get("description").asText(),
Matchers.equalTo(
"Preset Automated Rule for enabling Quarkus framework-specific events when"
+ " available"));
MatcherAssert.assertThat(
json.get("eventSpecifier").asText(),
Matchers.equalTo("template=Quarkus,type=PRESET"));
MatcherAssert.assertThat(
json.get("matchExpression").asText(),
Matchers.equalTo("jfrEventTypeIds(target).exists(x, x.startsWith(\"quarkus\"))"));
MatcherAssert.assertThat(json.get("name").asText(), Matchers.equalTo(ruleName));
MatcherAssert.assertThat(json.get("enabled").asBoolean(), Matchers.is(false));
}
}
25 changes: 18 additions & 7 deletions src/test/java/itest/PresetTemplatesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package itest;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -33,10 +35,14 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

@QuarkusIntegrationTest
public class PresetTemplatesIT extends StandardSelfTest {

static final String[] TEMPLATE_NAMES = new String[] {"Quarkus", "Hibernate"};

@Test
public void shouldListPresetTemplates() throws Exception {
CompletableFuture<JsonArray> future = new CompletableFuture<>();
Expand All @@ -50,14 +56,19 @@ public void shouldListPresetTemplates() throws Exception {
future.complete(ar.result().bodyAsJsonArray());
});
JsonArray response = future.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS);
MatcherAssert.assertThat(response.size(), Matchers.equalTo(1));
MatcherAssert.assertThat(response.size(), Matchers.equalTo(TEMPLATE_NAMES.length));
}

@Test
public void shouldHavePresetQuarkusTemplate() throws Exception {
String url = "/api/v4/event_templates/PRESET/Quarkus";
static List<String> templateNames() {
return Arrays.asList(TEMPLATE_NAMES);
}

@ParameterizedTest
@MethodSource("templateNames")
public void shouldHaveExpectedPresetTemplates(String templateName) throws Exception {
String url = String.format("/api/v4/event_templates/PRESET/%s", templateName);
File file =
downloadFile(url, "quarkus", ".jfc")
downloadFile(url, templateName, ".jfc")
.get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.toFile();

Expand All @@ -77,7 +88,7 @@ public void shouldHavePresetQuarkusTemplate() throws Exception {

MatcherAssert.assertThat(labelAttr, Matchers.notNullValue());

String templateName = labelAttr.getExplicitValue();
MatcherAssert.assertThat(templateName, Matchers.equalTo("Quarkus"));
String name = labelAttr.getExplicitValue();
MatcherAssert.assertThat(name, Matchers.equalTo(templateName));
}
}
Loading