From c3d4567f21473fffb382c51cea9cddb52b0998c7 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 19 Dec 2024 19:12:53 -0500 Subject: [PATCH] feat(preset): add preset template and rule for Hibernate JFR --- pom.xml | 6 +++ .../include/rule_presets/hibernate.json | 7 ++++ .../docker/include/rule_presets/quarkus.json | 2 +- .../include/template_presets/hibernate.jfc | 42 +++++++++++++++++++ .../include/template_presets/quarkus.jfc | 18 ++++---- src/test/java/itest/PresetRulesIT.java | 34 +++++++-------- src/test/java/itest/PresetTemplatesIT.java | 25 +++++++---- 7 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 src/main/docker/include/rule_presets/hibernate.json create mode 100644 src/main/docker/include/template_presets/hibernate.jfc diff --git a/pom.xml b/pom.xml index bf8862207..9df10920d 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ io.quarkus.platform 3.15.2 2.5.1 + 6.6.1.Final 3.6.0 3.5.0 3.7.1 @@ -199,6 +200,11 @@ io.quarkus quarkus-hibernate-validator + + org.hibernate.orm + hibernate-jfr + ${org.hibernate.orm.hibernate.jfr.version} + io.quarkus quarkus-jdbc-postgresql diff --git a/src/main/docker/include/rule_presets/hibernate.json b/src/main/docker/include/rule_presets/hibernate.json new file mode 100644 index 000000000..f407835ad --- /dev/null +++ b/src/main/docker/include/rule_presets/hibernate.json @@ -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 +} diff --git a/src/main/docker/include/rule_presets/quarkus.json b/src/main/docker/include/rule_presets/quarkus.json index f3817a61e..d5e9995b8 100644 --- a/src/main/docker/include/rule_presets/quarkus.json +++ b/src/main/docker/include/rule_presets/quarkus.json @@ -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 } diff --git a/src/main/docker/include/template_presets/hibernate.jfc b/src/main/docker/include/template_presets/hibernate.jfc new file mode 100644 index 000000000..c691a7786 --- /dev/null +++ b/src/main/docker/include/template_presets/hibernate.jfc @@ -0,0 +1,42 @@ + + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + diff --git a/src/main/docker/include/template_presets/quarkus.jfc b/src/main/docker/include/template_presets/quarkus.jfc index 30e761f50..da6c764d7 100644 --- a/src/main/docker/include/template_presets/quarkus.jfc +++ b/src/main/docker/include/template_presets/quarkus.jfc @@ -1,12 +1,12 @@ - - true - - - true - - - true - + + true + + + true + + + true + diff --git a/src/test/java/itest/PresetRulesIT.java b/src/test/java/itest/PresetRulesIT.java index a4b561b62..f843fc6f2 100644 --- a/src/test/java/itest/PresetRulesIT.java +++ b/src/test/java/itest/PresetRulesIT.java @@ -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; @@ -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 future = new CompletableFuture<>(); @@ -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 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)); } } diff --git a/src/test/java/itest/PresetTemplatesIT.java b/src/test/java/itest/PresetTemplatesIT.java index 8e0a62bfe..19b69a583 100644 --- a/src/test/java/itest/PresetTemplatesIT.java +++ b/src/test/java/itest/PresetTemplatesIT.java @@ -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; @@ -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 future = new CompletableFuture<>(); @@ -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 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(); @@ -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)); } }