This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git


The following commit(s) were added to refs/heads/camel-quarkus-main by this 
push:
     new 005b6bd  Use MicroMeter metrics instead of MicroProfile Metrics
005b6bd is described below

commit 005b6bd9f396d60ca6cb98d87f7a9f3c4b053c40
Author: James Netherton <[email protected]>
AuthorDate: Tue Jan 25 10:42:18 2022 +0000

    Use MicroMeter metrics instead of MicroProfile Metrics
---
 observability/README.adoc                           |  7 +++----
 observability/pom.xml                               |  6 +++++-
 .../src/main/resources/application.properties       |  3 +++
 .../org/acme/observability/ObservabilityTest.java   | 21 ++++++++++++++++-----
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/observability/README.adoc b/observability/README.adoc
index 55169fe..5c990f0 100644
--- a/observability/README.adoc
+++ b/observability/README.adoc
@@ -31,12 +31,11 @@ To view all Camel metrics do:
 $ curl localhost:8080/q/metrics/application
 ----
 
-To pick out specific metrics you can either use `grep` or the 
`https://stedolan.github.io/jq/[jq]` library :
+To retrieve metrics in JSON format, pass the `Accept` HTTP header in the 
request:
 
 [source,shell]
 ----
-$ curl -s -H"Accept: application/json" localhost:8080/q/metrics/application \
-    | jq 
'.["camel.context.exchanges.completed.total;camelContext=camel-quarkus-observability"]'
+$ curl -s -H"Accept: application/json" localhost:8080/q/metrics/application
 ----
 
 === Health endpoint
@@ -58,7 +57,7 @@ The JSON output will contain a checks for verifying whether 
the `CamelContext` a
 This example project contains a custom liveness check class 
`CustomLivenessCheck` and custom readiness check class `CustomReadinessCheck` 
which leverage the Camel health API.
 You'll see these listed in the health JSON as 'custom-liveness-check' and 
'custom-readiness-check'. On every 5th invocation of these checks, the health 
status of `custom-liveness-check` will be reported as DOWN.
 
-You can also directly leverage MicroProfile Metrics APIs to create checks. 
Class `CamelUptimeHealthCheck` demonstrates how to register a readiness check.
+You can also directly leverage MicroProfile Health APIs to create checks. 
Class `CamelUptimeHealthCheck` demonstrates how to register a readiness check.
 
 ==== Tracing
 
diff --git a/observability/pom.xml b/observability/pom.xml
index c7ba18a..1b29557 100644
--- a/observability/pom.xml
+++ b/observability/pom.xml
@@ -88,13 +88,17 @@
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
-            <artifactId>camel-quarkus-microprofile-metrics</artifactId>
+            <artifactId>camel-quarkus-micrometer</artifactId>
         </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-opentracing</artifactId>
         </dependency>
         <dependency>
+            <groupId>io.micrometer</groupId>
+            <artifactId>micrometer-registry-prometheus</artifactId>
+        </dependency>
+        <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy</artifactId>
         </dependency>
diff --git a/observability/src/main/resources/application.properties 
b/observability/src/main/resources/application.properties
index 6337bd2..5b14547 100644
--- a/observability/src/main/resources/application.properties
+++ b/observability/src/main/resources/application.properties
@@ -26,6 +26,9 @@ quarkus.jaeger.sampler-type = const
 quarkus.jaeger.sampler-param = 1
 quarkus.jaeger.endpoint = http://localhost:14268/api/traces
 
+# Allow metrics to be exported as JSON. Not strictly required and is disabled 
by default
+quarkus.micrometer.export.json.enabled = true
+
 #
 # Camel
 #
diff --git 
a/observability/src/test/java/org/acme/observability/ObservabilityTest.java 
b/observability/src/test/java/org/acme/observability/ObservabilityTest.java
index b0f65fe..6d4b979 100644
--- a/observability/src/test/java/org/acme/observability/ObservabilityTest.java
+++ b/observability/src/test/java/org/acme/observability/ObservabilityTest.java
@@ -19,6 +19,7 @@ package org.acme.observability;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
 import org.apache.camel.CamelContext;
 import org.hamcrest.Matchers;
 import org.junit.jupiter.api.Test;
@@ -27,20 +28,30 @@ import static io.restassured.RestAssured.given;
 import static org.hamcrest.CoreMatchers.hasItems;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
 public class ObservabilityTest {
 
     @Test
     public void metrics() {
-        // Verify a expected Camel metric is available
-        given()
+        // Verify Camel metrics are available
+        JsonPath path = given()
                 .when().accept(ContentType.JSON)
-                .get("/q/metrics/application")
+                .get("/q/metrics")
                 .then()
                 .statusCode(200)
-                .body(
-                        
"'camel.context.status;camelContext=camel-quarkus-observability'", is(3));
+                .extract()
+                .body()
+                .jsonPath();
+
+        long camelMetricCount = path.getMap("$.")
+                .keySet()
+                .stream()
+                .filter(key -> key.toString().startsWith("Camel"))
+                .count();
+
+        assertTrue(camelMetricCount > 0);
     }
 
     @Test

Reply via email to