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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/main by this push:
     new aab53fa7095 CAMEL-20461: camel-micrometer - Add statistics for context 
level
aab53fa7095 is described below

commit aab53fa709532f6dee263ef59312be67fb71022f
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Mar 6 16:19:28 2024 +0100

    CAMEL-20461: camel-micrometer - Add statistics for context level
---
 .../src/main/docs/micrometer.json                  | 14 ++++++++++
 .../metrics/CamelMetricsAutoConfiguration.java     | 27 ++++++++++++++++++
 .../metrics/CamelMetricsConfiguration.java         | 32 ++++++++++++++++++++++
 3 files changed, 73 insertions(+)

diff --git 
a/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json 
b/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
index d11fc1b7bed..47450cf7f53 100644
--- a/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
+++ b/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
@@ -77,6 +77,20 @@
       "sourceType": 
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration",
       "defaultValue": true
     },
+    {
+      "name": "camel.metrics.naming-strategy",
+      "type": "java.lang.String",
+      "description": "Controls the name style to use for metrics. Default = 
uses micrometer naming convention. Legacy = uses the classic naming style 
(camelCase)",
+      "sourceType": 
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration",
+      "defaultValue": "default"
+    },
+    {
+      "name": "camel.metrics.route-policy-level",
+      "type": "java.lang.String",
+      "description": "Sets the level of information to capture. Possible 
values are all,route,context. all = both context and routes. route = routes 
only. context = camel context only.",
+      "sourceType": 
"org.apache.camel.component.micrometer.springboot.metrics.CamelMetricsConfiguration",
+      "defaultValue": "all"
+    },
     {
       "name": "camel.metrics.uri-tag-dynamic",
       "type": "java.lang.Boolean",
diff --git 
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
 
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
index 2786630fd80..6de3b793dec 100644
--- 
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
+++ 
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsAutoConfiguration.java
@@ -19,9 +19,13 @@ package 
org.apache.camel.component.micrometer.springboot.metrics;
 import io.micrometer.core.instrument.MeterRegistry;
 import org.apache.camel.CamelContext;
 import 
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
+import 
org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
 import 
org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
+import 
org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy;
 import 
org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
+import 
org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryNamingStrategy;
 import 
org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
+import 
org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyNamingStrategy;
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
 import 
org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
@@ -45,6 +49,19 @@ public class CamelMetricsAutoConfiguration {
         if (configuration.isEnableRoutePolicy()) {
             MicrometerRoutePolicyFactory factory = new 
MicrometerRoutePolicyFactory();
             factory.setMeterRegistry(meterRegistry);
+            if ("legacy".equalsIgnoreCase(configuration.getNamingStrategy())) {
+                
factory.setNamingStrategy(MicrometerRoutePolicyNamingStrategy.LEGACY);
+            }
+            if ("all".equalsIgnoreCase(configuration.getRoutePolicyLevel())) {
+                factory.getPolicyConfiguration().setContextEnabled(true);
+                factory.getPolicyConfiguration().setRouteEnabled(true);
+            } else if 
("context".equalsIgnoreCase(configuration.getRoutePolicyLevel())) {
+                factory.getPolicyConfiguration().setContextEnabled(true);
+                factory.getPolicyConfiguration().setRouteEnabled(false);
+            } else {
+                factory.getPolicyConfiguration().setContextEnabled(false);
+                factory.getPolicyConfiguration().setRouteEnabled(true);
+            }
             camelContext.addRoutePolicyFactory(factory);
         }
 
@@ -52,12 +69,18 @@ public class CamelMetricsAutoConfiguration {
         if (configuration.isEnableExchangeEventNotifier()) {
             MicrometerExchangeEventNotifier notifier = new 
MicrometerExchangeEventNotifier();
             notifier.setMeterRegistry(meterRegistry);
+            if ("legacy".equalsIgnoreCase(configuration.getNamingStrategy())) {
+                
notifier.setNamingStrategy(MicrometerExchangeEventNotifierNamingStrategy.LEGACY);
+            }
             managementStrategy.addEventNotifier(notifier);
         }
 
         if (configuration.isEnableRouteEventNotifier()) {
             MicrometerRouteEventNotifier notifier = new 
MicrometerRouteEventNotifier();
             notifier.setMeterRegistry(meterRegistry);
+            if ("legacy".equalsIgnoreCase(configuration.getNamingStrategy())) {
+                
notifier.setNamingStrategy(MicrometerRouteEventNotifierNamingStrategy.LEGACY);
+            }
             managementStrategy.addEventNotifier(notifier);
         }
 
@@ -67,7 +90,11 @@ public class CamelMetricsAutoConfiguration {
             }
             MicrometerMessageHistoryFactory factory = new 
MicrometerMessageHistoryFactory();
             factory.setMeterRegistry(meterRegistry);
+            if ("legacy".equalsIgnoreCase(configuration.getNamingStrategy())) {
+                
factory.setNamingStrategy(MicrometerMessageHistoryNamingStrategy.LEGACY);
+            }
             camelContext.setMessageHistoryFactory(factory);
         }
     }
+
 }
\ No newline at end of file
diff --git 
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
 
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
index f31b115191a..2b0988cfa92 100644
--- 
a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
+++ 
b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/metrics/CamelMetricsConfiguration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.micrometer.springboot.metrics;
 
+import org.apache.camel.spi.Metadata;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
 @ConfigurationProperties(prefix = "camel.metrics")
@@ -42,6 +43,21 @@ public class CamelMetricsConfiguration {
      */
     private boolean enableRoutePolicy = true;
 
+    /**
+     * Sets the level of information to capture. Possible values are 
all,route,context.
+     *
+     * all = both context and routes.
+     * route = routes only.
+     * context = camel context only.
+     */
+    private String routePolicyLevel = "all";
+
+    /**
+     * Controls the name style to use for metrics.
+     * Default = uses micrometer naming convention. Legacy = uses the classic 
naming style (camelCase)
+     */
+    private String namingStrategy = "default";
+
     /**
      * Set whether to enable the MicrometerMessageHistoryFactory for capturing 
metrics
      * on individual route node processing times.
@@ -87,6 +103,22 @@ public class CamelMetricsConfiguration {
         this.enableRoutePolicy = enableRoutePolicy;
     }
 
+    public String getNamingStrategy() {
+        return namingStrategy;
+    }
+
+    public void setNamingStrategy(String namingStrategy) {
+        this.namingStrategy = namingStrategy;
+    }
+
+    public String getRoutePolicyLevel() {
+        return routePolicyLevel;
+    }
+
+    public void setRoutePolicyLevel(String routePolicyLevel) {
+        this.routePolicyLevel = routePolicyLevel;
+    }
+
     public boolean isEnableMessageHistory() {
         return enableMessageHistory;
     }

Reply via email to