You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/12/19 11:43:58 UTC

(camel) 04/07: Experiment

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

davsclaus pushed a commit to branch mm
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 49419bf12ac29d9183c56633ddf4ee1b340745b2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 19 11:32:31 2023 +0100

    Experiment
---
 .../component/micrometer/MicrometerConstants.java  |  1 +
 .../MicrometerRouteEventNotifier.java              | 31 ++++++++++++++++++++--
 ...MicrometerRouteEventNotifierNamingStrategy.java | 13 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java
index 67dd47b0b45..a748f629763 100644
--- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java
+++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java
@@ -53,6 +53,7 @@ public final class MicrometerConstants {
     public static final String DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME = "camel.exchange.event.notifier";
     public static final String DEFAULT_CAMEL_ROUTES_ADDED = "camel.routes.added";
     public static final String DEFAULT_CAMEL_ROUTES_RUNNING = "camel.routes.running";
+    public static final String DEFAULT_CAMEL_ROUTES_RELOADED = "camel.routes.reloaded";
     public static final String DEFAULT_CAMEL_ROUTES_EXCHANGES_INFLIGHT = "camel.exchanges.inflight";
 
     public static final String ROUTE_ID_TAG = "routeId";
diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java
index c5617dd819b..6c638e031ce 100644
--- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java
+++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java
@@ -22,6 +22,7 @@ import io.micrometer.core.instrument.Gauge;
 import org.apache.camel.spi.CamelEvent;
 import org.apache.camel.spi.CamelEvent.RouteAddedEvent;
 import org.apache.camel.spi.CamelEvent.RouteEvent;
+import org.apache.camel.spi.CamelEvent.RouteReloadedEvent;
 import org.apache.camel.spi.CamelEvent.RouteRemovedEvent;
 import org.apache.camel.spi.CamelEvent.RouteStartedEvent;
 import org.apache.camel.spi.CamelEvent.RouteStoppedEvent;
@@ -30,6 +31,10 @@ public class MicrometerRouteEventNotifier extends AbstractMicrometerEventNotifie
 
     private final AtomicLong routesAdded = new AtomicLong();
     private final AtomicLong routesRunning = new AtomicLong();
+    private final AtomicLong routesReloaded = new AtomicLong();
+    private Gauge gaugeAdded;
+    private Gauge gaugeRunning;
+    private Gauge gaugeReloaded;
     private MicrometerRouteEventNotifierNamingStrategy namingStrategy = MicrometerRouteEventNotifierNamingStrategy.DEFAULT;
 
     public MicrometerRouteEventNotifier() {
@@ -47,16 +52,36 @@ public class MicrometerRouteEventNotifier extends AbstractMicrometerEventNotifie
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        Gauge.builder(namingStrategy.getRouteAddedName(), routesAdded, value -> (double) value.get())
+
+        gaugeAdded = Gauge.builder(namingStrategy.getRouteAddedName(), routesAdded, value -> (double) value.get())
+                .baseUnit("routes")
+                .tags(namingStrategy.getTags(getCamelContext()))
+                .register(getMeterRegistry());
+        gaugeRunning = Gauge.builder(namingStrategy.getRouteRunningName(), routesRunning, value -> (double) value.get())
                 .baseUnit("routes")
                 .tags(namingStrategy.getTags(getCamelContext()))
                 .register(getMeterRegistry());
-        Gauge.builder(namingStrategy.getRouteRunningName(), routesRunning, value -> (double) value.get())
+        gaugeReloaded = Gauge.builder(namingStrategy.getRouteReloadedName(), routesReloaded, value -> (double) value.get())
                 .baseUnit("routes")
                 .tags(namingStrategy.getTags(getCamelContext()))
                 .register(getMeterRegistry());
     }
 
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        if (gaugeAdded != null) {
+            getMeterRegistry().remove(gaugeAdded);
+        }
+        if (gaugeRunning != null) {
+            getMeterRegistry().remove(gaugeRunning);
+        }
+        if (gaugeReloaded != null) {
+            getMeterRegistry().remove(gaugeReloaded);
+        }
+    }
+
     @Override
     public void notify(CamelEvent eventObject) {
         if (eventObject instanceof RouteAddedEvent) {
@@ -67,6 +92,8 @@ public class MicrometerRouteEventNotifier extends AbstractMicrometerEventNotifie
             routesRunning.incrementAndGet();
         } else if (eventObject instanceof RouteStoppedEvent) {
             routesRunning.decrementAndGet();
+        } else if (eventObject instanceof RouteReloadedEvent) {
+            routesReloaded.incrementAndGet();
         }
     }
 }
diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java
index 094567ee790..693275c80ad 100644
--- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java
+++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java
@@ -26,6 +26,7 @@ import org.apache.camel.spi.CamelEvent.RouteEvent;
 
 import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG;
 import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_ADDED;
+import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RELOADED;
 import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RUNNING;
 import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG;
 import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;
@@ -48,6 +49,11 @@ public interface MicrometerRouteEventNotifierNamingStrategy {
         public String getRouteRunningName() {
             return DEFAULT_CAMEL_ROUTES_RUNNING;
         }
+
+        @Override
+        public String getRouteReloadedName() {
+            return DEFAULT_CAMEL_ROUTES_RELOADED;
+        }
     };
 
     /**
@@ -64,6 +70,11 @@ public interface MicrometerRouteEventNotifierNamingStrategy {
             return formatName(DEFAULT_CAMEL_ROUTES_RUNNING);
         }
 
+        @Override
+        public String getRouteReloadedName() {
+            return formatName(DEFAULT_CAMEL_ROUTES_RELOADED);
+        }
+
         @Override
         public String formatName(String name) {
             return MicrometerUtils.legacyName(name);
@@ -78,6 +89,8 @@ public interface MicrometerRouteEventNotifierNamingStrategy {
 
     String getRouteRunningName();
 
+    String getRouteReloadedName();
+
     default Tags getTags(CamelContext camelContext) {
         return Tags.of(
                 SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),