Skip to content

Commit

Permalink
feat(preset): add preset template and rule for Hibernate JFR
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Dec 20, 2024
1 parent f447e9e commit c3d4567
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 34 deletions.
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.1.Final</org.hibernate.orm.hibernate.jfr.version><!-- TODO is there some way to grab the Hibernate version used by Quarkus to match these version? -->
<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.contains(\"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));
}
}

0 comments on commit c3d4567

Please sign in to comment.