diff --git a/dmn-drools-quarkus-metrics/README.md b/dmn-drools-quarkus-metrics/README.md index ec9c8ca80e..643885361c 100644 --- a/dmn-drools-quarkus-metrics/README.md +++ b/dmn-drools-quarkus-metrics/README.md @@ -13,33 +13,20 @@ You will need: ### How to enable the feature -Import the following dependency in your `pom.xml`: +Import the following dependency in your `pom.xml` if you are using quarkus: ```XML org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon ``` -And add the following class in your quarkus project: - -```Java -package org.kie.kogito.examples; - -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.ext.Provider; - -import org.kie.addons.monitoring.system.interceptor.MetricsInterceptor; - -@Provider -public class MyInterceptor extends MetricsInterceptor { - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { - super.filter(requestContext, responseContext); - } -} +Otherwise, if you are using springboot import +```XML + + org.kie.kogito + monitoring-prometheus-springboot-addon ``` ### Architecture diff --git a/dmn-drools-quarkus-metrics/pom.xml b/dmn-drools-quarkus-metrics/pom.xml index 4631ab52d4..a82ebf713a 100755 --- a/dmn-drools-quarkus-metrics/pom.xml +++ b/dmn-drools-quarkus-metrics/pom.xml @@ -47,11 +47,7 @@ org.kie.kogito - monitoring-prometheus-addon - - - org.kie.kogito - monitoring-core + monitoring-prometheus-quarkus-addon io.quarkus diff --git a/dmn-drools-quarkus-metrics/src/main/java/org/kie/kogito/examples/MyInterceptor.java b/dmn-drools-quarkus-metrics/src/main/java/org/kie/kogito/examples/MyInterceptor.java deleted file mode 100644 index 06ef3e42af..0000000000 --- a/dmn-drools-quarkus-metrics/src/main/java/org/kie/kogito/examples/MyInterceptor.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.examples; - -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.ext.Provider; - -import org.kie.kogito.monitoring.core.system.interceptor.MetricsInterceptor; - -@Provider -public class MyInterceptor extends MetricsInterceptor { - - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { - super.filter(requestContext, responseContext); - } -} diff --git a/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/DroolsMetricsTest.java b/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/DroolsMetricsTest.java new file mode 100644 index 0000000000..ff5c50522d --- /dev/null +++ b/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/DroolsMetricsTest.java @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kie.kogito.examples; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; + +@QuarkusTest +public class DroolsMetricsTest { + + @Test + public void testDrlMetrics() { + given() + .body("{\"strings\": [\"hello\"]}") + .contentType(ContentType.JSON) + .when() + .post("/hello") + .then() + .statusCode(200); + + given() + .when() + .get("/metrics") + .then() + .statusCode(200) + .body(containsString("drl_match_fired_nanosecond_count{app_id=\"default-rule-monitoring-listener\",process_id=\"helloWorld\",} 1.0")); + } +} \ No newline at end of file diff --git a/kogito-travel-agency/basic/pom.xml b/kogito-travel-agency/basic/pom.xml index dbea543e9c..4f2ff46898 100644 --- a/kogito-travel-agency/basic/pom.xml +++ b/kogito-travel-agency/basic/pom.xml @@ -30,7 +30,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon io.quarkus diff --git a/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java b/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java deleted file mode 100644 index ce4a8c8d9b..0000000000 --- a/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.app; - -import org.kie.kogito.monitoring.prometheus.process.PrometheusProcessEventListener; -import org.kie.kogito.process.impl.DefaultProcessEventListenerConfig; - - -public class ProcessEventListenerConfig extends DefaultProcessEventListenerConfig { - - public ProcessEventListenerConfig() { - super(new PrometheusProcessEventListener("acme-travels")); - } -} diff --git a/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java b/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java deleted file mode 100644 index f796c21a96..0000000000 --- a/kogito-travel-agency/basic/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.kie.kogito.app; - -import org.drools.core.config.DefaultRuleEventListenerConfig; -import org.kie.kogito.monitoring.prometheus.rule.PrometheusMetricsDroolsListener; - -public class RuleEventListenerConfig extends DefaultRuleEventListenerConfig { - - - public RuleEventListenerConfig() { - super(new PrometheusMetricsDroolsListener("acme-travels")); - } -} diff --git a/kogito-travel-agency/extended/travels/pom.xml b/kogito-travel-agency/extended/travels/pom.xml index 00ec78d793..a8c6b3f3a0 100644 --- a/kogito-travel-agency/extended/travels/pom.xml +++ b/kogito-travel-agency/extended/travels/pom.xml @@ -54,7 +54,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon io.quarkus diff --git a/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java b/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java deleted file mode 100644 index 09ef3bf8d4..0000000000 --- a/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/ProcessEventListenerConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.app; - -import javax.enterprise.context.ApplicationScoped; - -import org.kie.kogito.monitoring.prometheus.process.PrometheusProcessEventListener; -import org.kie.kogito.process.impl.DefaultProcessEventListenerConfig; - -@ApplicationScoped -public class ProcessEventListenerConfig extends DefaultProcessEventListenerConfig { - - public ProcessEventListenerConfig() { - super(new PrometheusProcessEventListener("acme-travels")); - } -} diff --git a/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java b/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java deleted file mode 100644 index cb2a1f80f5..0000000000 --- a/kogito-travel-agency/extended/travels/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.app; - -import javax.enterprise.context.ApplicationScoped; - -import org.drools.core.config.DefaultRuleEventListenerConfig; -import org.kie.kogito.monitoring.prometheus.rule.PrometheusMetricsDroolsListener; - -@ApplicationScoped -public class RuleEventListenerConfig extends DefaultRuleEventListenerConfig { - - - public RuleEventListenerConfig() { - super(new PrometheusMetricsDroolsListener("acme-travels")); - } -} diff --git a/kogito-travel-agency/extended/travels/src/test/java/org/acme/travel/TravelIT.java b/kogito-travel-agency/extended/travels/src/test/java/org/acme/travel/TravelIT.java index 395cb940cd..c5795a0180 100644 --- a/kogito-travel-agency/extended/travels/src/test/java/org/acme/travel/TravelIT.java +++ b/kogito-travel-agency/extended/travels/src/test/java/org/acme/travel/TravelIT.java @@ -15,9 +15,6 @@ */ package org.acme.travel; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - import java.util.Date; import java.util.HashMap; import java.util.List; @@ -26,6 +23,8 @@ import javax.inject.Inject; import javax.inject.Named; +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; import org.acme.travels.Address; import org.acme.travels.Flight; import org.acme.travels.Hotel; @@ -42,8 +41,10 @@ import org.kie.kogito.testcontainers.quarkus.InfinispanQuarkusTestResource; import org.kie.kogito.testcontainers.quarkus.KafkaQuarkusTestResource; -import io.quarkus.test.common.QuarkusTestResource; -import io.quarkus.test.junit.QuarkusTest; +import static io.restassured.RestAssured.given; +import static org.hamcrest.core.StringContains.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; @QuarkusTest @QuarkusTestResource(value = InfinispanQuarkusTestResource.class) @@ -88,6 +89,17 @@ public void testTravelVisaRequired() { thenProcessIsActive(); } + @Test + public void testProcessMetrics() { + whenNewTravel(TRAVELLER_FROM_POLAND, TRIP_TO_POLAND); + given() + .when() + .get("/metrics") + .then() + .statusCode(200) + .body(containsString("kie_process_instance_running_total{app_id=\"default-process-monitoring-listener\",process_id=\"travels\",} 1.0")); + } + private void whenNewTravel(Traveller traveller, Trip trip) { Model m = travelsProcess.createModel(); Map parameters = new HashMap<>(); diff --git a/kogito-travel-agency/extended/visas/pom.xml b/kogito-travel-agency/extended/visas/pom.xml index ed1c4181f0..c6f9be1ceb 100644 --- a/kogito-travel-agency/extended/visas/pom.xml +++ b/kogito-travel-agency/extended/visas/pom.xml @@ -60,7 +60,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon io.quarkus diff --git a/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java b/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java deleted file mode 100644 index cb2a1f80f5..0000000000 --- a/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/RuleEventListenerConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.app; - -import javax.enterprise.context.ApplicationScoped; - -import org.drools.core.config.DefaultRuleEventListenerConfig; -import org.kie.kogito.monitoring.prometheus.rule.PrometheusMetricsDroolsListener; - -@ApplicationScoped -public class RuleEventListenerConfig extends DefaultRuleEventListenerConfig { - - - public RuleEventListenerConfig() { - super(new PrometheusMetricsDroolsListener("acme-travels")); - } -} diff --git a/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/VisaApplicationPrometheusProcessEventListener.java b/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/VisaApplicationPrometheusProcessEventListener.java index 0edf532cb3..f7b8075ea2 100644 --- a/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/VisaApplicationPrometheusProcessEventListener.java +++ b/kogito-travel-agency/extended/visas/src/main/java/org/kie/kogito/app/VisaApplicationPrometheusProcessEventListener.java @@ -22,9 +22,9 @@ import org.acme.travels.VisaApplication; import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl; import org.kie.api.event.process.ProcessCompletedEvent; -import org.kie.kogito.monitoring.core.MonitoringRegistry; -import org.kie.kogito.monitoring.prometheus.PrometheusRegistryProvider; -import org.kie.kogito.monitoring.prometheus.process.PrometheusProcessEventListener; +import org.kie.kogito.monitoring.core.common.MonitoringRegistry; +import org.kie.kogito.monitoring.prometheus.common.PrometheusRegistryProvider; +import org.kie.kogito.monitoring.prometheus.common.process.PrometheusProcessEventListener; public class VisaApplicationPrometheusProcessEventListener extends PrometheusProcessEventListener { diff --git a/kogito-travel-agency/extended/visas/src/main/resources/application.properties b/kogito-travel-agency/extended/visas/src/main/resources/application.properties index 53e8ac8192..aff6bfe767 100644 --- a/kogito-travel-agency/extended/visas/src/main/resources/application.properties +++ b/kogito-travel-agency/extended/visas/src/main/resources/application.properties @@ -45,3 +45,5 @@ mp.messaging.outgoing.kogito-usertaskinstances-events.value.serializer=org.apach mp.messaging.outgoing.kogito-variables-events.connector=smallrye-kafka mp.messaging.outgoing.kogito-variables-events.topic=kogito-variables-events mp.messaging.outgoing.kogito-variables-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer + +kogito.monitoring.process.useDefault=false \ No newline at end of file diff --git a/onboarding-example/hr/pom.xml b/onboarding-example/hr/pom.xml index 7b6d043520..56949c828e 100644 --- a/onboarding-example/hr/pom.xml +++ b/onboarding-example/hr/pom.xml @@ -22,7 +22,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon io.quarkus diff --git a/onboarding-example/hr/src/main/java/org/kie/kogito/examples/RuleEventListenerConfig.java b/onboarding-example/hr/src/main/java/org/kie/kogito/examples/RuleEventListenerConfig.java deleted file mode 100644 index a3114a7ea0..0000000000 --- a/onboarding-example/hr/src/main/java/org/kie/kogito/examples/RuleEventListenerConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.examples; - -import javax.enterprise.context.ApplicationScoped; - -import org.drools.core.config.DefaultRuleEventListenerConfig; -import org.kie.kogito.monitoring.prometheus.rule.PrometheusMetricsDroolsListener; - -@ApplicationScoped -public class RuleEventListenerConfig extends DefaultRuleEventListenerConfig { - - - public RuleEventListenerConfig() { - super(new PrometheusMetricsDroolsListener("onboarding")); - } -} diff --git a/onboarding-example/onboarding-quarkus/pom.xml b/onboarding-example/onboarding-quarkus/pom.xml index c2dd4266c7..88498a5232 100644 --- a/onboarding-example/onboarding-quarkus/pom.xml +++ b/onboarding-example/onboarding-quarkus/pom.xml @@ -22,7 +22,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-quarkus-addon org.kie.kogito diff --git a/onboarding-example/onboarding-quarkus/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java b/onboarding-example/onboarding-quarkus/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java deleted file mode 100644 index 1e6883bdab..0000000000 --- a/onboarding-example/onboarding-quarkus/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.examples; - -import javax.enterprise.context.ApplicationScoped; - -import org.kie.kogito.monitoring.prometheus.process.PrometheusProcessEventListener; -import org.kie.kogito.process.impl.DefaultProcessEventListenerConfig; - -@ApplicationScoped -public class ProcessEventListenerConfig extends DefaultProcessEventListenerConfig { - - public ProcessEventListenerConfig() { - super(new PrometheusProcessEventListener("onboarding")); - } -} diff --git a/onboarding-example/onboarding-springboot/pom.xml b/onboarding-example/onboarding-springboot/pom.xml index 0a06ce14dc..be39014adf 100644 --- a/onboarding-example/onboarding-springboot/pom.xml +++ b/onboarding-example/onboarding-springboot/pom.xml @@ -34,7 +34,7 @@ org.kie.kogito - monitoring-prometheus-addon + monitoring-prometheus-springboot-addon org.kie.kogito diff --git a/onboarding-example/onboarding-springboot/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java b/onboarding-example/onboarding-springboot/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java deleted file mode 100644 index 2db43ca4cb..0000000000 --- a/onboarding-example/onboarding-springboot/src/main/java/org/kie/kogito/examples/ProcessEventListenerConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2020 Red Hat, Inc. and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.kie.kogito.examples; - -import org.kie.kogito.monitoring.prometheus.process.PrometheusProcessEventListener; -import org.kie.kogito.process.impl.DefaultProcessEventListenerConfig; -import org.springframework.stereotype.Component; - -@Component -public class ProcessEventListenerConfig extends DefaultProcessEventListenerConfig { - - public ProcessEventListenerConfig() { - super(new PrometheusProcessEventListener("onboarding")); - } -}