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

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


The following commit(s) were added to refs/heads/main by this push:
     new 1a457477084 fix(components): Micrometer Prometheus configurable path
1a457477084 is described below

commit 1a457477084d0a946b71492c57ae8c41ce0e1e2f
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Mon Nov 11 15:04:31 2024 +0100

    fix(components): Micrometer Prometheus configurable path
    
    Closes CAMEL-21414
---
 .../main/camel-main-configuration-metadata.json       |  3 ++-
 .../prometheus/MicrometerPrometheusConfigurer.java    |  3 +++
 .../micrometer/prometheus/MicrometerPrometheus.java   | 19 ++++++++++++++++---
 .../MetricsConfigurationPropertiesConfigurer.java     |  4 ++++
 .../META-INF/camel-main-configuration-metadata.json   |  3 ++-
 core/camel-main/src/main/docs/main.adoc               |  5 +++--
 .../camel/main/HttpServerConfigurationProperties.java |  4 ++--
 .../camel/main/MetricsConfigurationProperties.java    | 13 +++++++++++++
 8 files changed, 45 insertions(+), 9 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index 71c78f669b8..737ef52221d 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -193,6 +193,7 @@
     { "name": "camel.metrics.enableRouteEventNotifier", "description": "Set 
whether to enable the MicrometerRouteEventNotifier for capturing metrics on the 
total number of routes and total number of routes running.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.metrics.enableRoutePolicy", "description": "Set whether 
to enable the MicrometerRoutePolicyFactory for capturing metrics on route 
processing times.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.metrics.namingStrategy", "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.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "default", "enum": [ "default", 
"legacy" ] },
+    { "name": "camel.metrics.path", "description": "The path endpoint used to 
expose the metrics.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "\/q\/metrics" },
     { "name": "camel.metrics.routePolicyLevel", "description": "Sets the level 
of information to capture. all = both context and routes.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "all", "enum": [ "all", 
"route", "context" ] },
     { "name": "camel.metrics.textFormatVersion", "description": "The 
text-format version to use with Prometheus scraping. 0.0.4 = text\/plain; 
version=0.0.4; charset=utf-8 1.0.0 = application\/openmetrics-text; 
version=1.0.0; charset=utf-8", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "0.0.4", "enum": [ "0.0.4", 
"1.0.0" ] },
     { "name": "camel.opentelemetry.enabled", "description": "To enable 
OpenTelemetry", "sourceType": 
"org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
@@ -275,7 +276,7 @@
     { "name": "camel.server.jwtKeystorePath", "description": "Path to the 
keystore file used for JWT tokens validation.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String" },
     { "name": "camel.server.jwtKeystoreType", "description": "Type of the 
keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String" },
     { "name": "camel.server.maxBodySize", "description": "Maximum HTTP body 
size the embedded HTTP server can accept.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", 
"javaType": "java.lang.Long" },
-    { "name": "camel.server.metricsEnabled", "description": "Whether to enable 
metrics. If enabled then you can access metrics on context-path: \/q\/metrics", 
"sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", 
"type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+    { "name": "camel.server.metricsEnabled", "description": "Whether to enable 
metrics. If enabled then you can access metrics on context-path: \/q\/metrics 
(default)", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.server.path", "description": "Context-path to use for 
embedded HTTP server", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "\/" },
     { "name": "camel.server.port", "description": "Port to use for binding 
embedded HTTP server", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", 
"javaType": "int", "defaultValue": 8080 },
     { "name": "camel.server.sendEnabled", "description": "Whether to enable 
sending messages to Camel via HTTP. This makes it possible to use Camel to send 
messages to Camel endpoint URIs via HTTP.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
diff --git 
a/components/camel-micrometer-prometheus/src/generated/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheusConfigurer.java
 
b/components/camel-micrometer-prometheus/src/generated/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheusConfigurer.java
index ebccf74c83f..265a436b053 100644
--- 
a/components/camel-micrometer-prometheus/src/generated/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheusConfigurer.java
+++ 
b/components/camel-micrometer-prometheus/src/generated/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheusConfigurer.java
@@ -38,6 +38,7 @@ public class MicrometerPrometheusConfigurer extends 
org.apache.camel.support.com
         case "enableRoutePolicy": 
target.setEnableRoutePolicy(property(camelContext, boolean.class, value)); 
return true;
         case "namingstrategy":
         case "namingStrategy": target.setNamingStrategy(property(camelContext, 
java.lang.String.class, value)); return true;
+        case "path": target.setPath(property(camelContext, 
java.lang.String.class, value)); return true;
         case "routepolicylevel":
         case "routePolicyLevel": 
target.setRoutePolicyLevel(property(camelContext, java.lang.String.class, 
value)); return true;
         case "textformatversion":
@@ -64,6 +65,7 @@ public class MicrometerPrometheusConfigurer extends 
org.apache.camel.support.com
         case "enableRoutePolicy": return boolean.class;
         case "namingstrategy":
         case "namingStrategy": return java.lang.String.class;
+        case "path": return java.lang.String.class;
         case "routepolicylevel":
         case "routePolicyLevel": return java.lang.String.class;
         case "textformatversion":
@@ -91,6 +93,7 @@ public class MicrometerPrometheusConfigurer extends 
org.apache.camel.support.com
         case "enableRoutePolicy": return target.isEnableRoutePolicy();
         case "namingstrategy":
         case "namingStrategy": return target.getNamingStrategy();
+        case "path": return target.getPath();
         case "routepolicylevel":
         case "routePolicyLevel": return target.getRoutePolicyLevel();
         case "textformatversion":
diff --git 
a/components/camel-micrometer-prometheus/src/main/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheus.java
 
b/components/camel-micrometer-prometheus/src/main/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheus.java
index 833c7ba4cd1..fa8b3d54152 100644
--- 
a/components/camel-micrometer-prometheus/src/main/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheus.java
+++ 
b/components/camel-micrometer-prometheus/src/main/java/org/apache/camel/component/micrometer/prometheus/MicrometerPrometheus.java
@@ -101,6 +101,8 @@ public class MicrometerPrometheus extends ServiceSupport 
implements CamelMetrics
     private String textFormatVersion = "0.0.4";
     @Metadata
     private String binders;
+    @Metadata(defaultValue = "/q/metrics")
+    private String path = "/q/metrics";
 
     @Override
     public CamelContext getCamelContext() {
@@ -210,6 +212,17 @@ public class MicrometerPrometheus extends ServiceSupport 
implements CamelMetrics
         this.textFormatVersion = textFormatVersion;
     }
 
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * The path endpoint used to expose the metrics.
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
     public String getBinders() {
         return binders;
     }
@@ -353,7 +366,7 @@ public class MicrometerPrometheus extends ServiceSupport 
implements CamelMetrics
 
         if (server != null && server.isMetricsEnabled() && router != null && 
platformHttpComponent != null) {
             setupHttpScraper();
-            LOG.info("MicrometerPrometheus enabled with HTTP scraping on 
/q/metrics");
+            LOG.info("MicrometerPrometheus enabled with HTTP scraping on {}", 
path);
         } else {
             LOG.info("MicrometerPrometheus enabled");
         }
@@ -387,7 +400,7 @@ public class MicrometerPrometheus extends ServiceSupport 
implements CamelMetrics
     }
 
     protected void setupHttpScraper() {
-        Route metrics = router.route("/q/metrics");
+        Route metrics = router.route(path);
         metrics.method(HttpMethod.GET);
 
         final String format
@@ -413,7 +426,7 @@ public class MicrometerPrometheus extends ServiceSupport 
implements CamelMetrics
         // use blocking handler as the task can take longer time to complete
         metrics.handler(new BlockingHandlerDecorator(handler, true));
 
-        platformHttpComponent.addHttpEndpoint("/q/metrics", "GET",
+        platformHttpComponent.addHttpEndpoint(path, "GET",
                 null, format, null);
     }
 }
diff --git 
a/core/camel-main/src/generated/java/org/apache/camel/main/MetricsConfigurationPropertiesConfigurer.java
 
b/core/camel-main/src/generated/java/org/apache/camel/main/MetricsConfigurationPropertiesConfigurer.java
index 96d224cc6fc..490b242d1f3 100644
--- 
a/core/camel-main/src/generated/java/org/apache/camel/main/MetricsConfigurationPropertiesConfigurer.java
+++ 
b/core/camel-main/src/generated/java/org/apache/camel/main/MetricsConfigurationPropertiesConfigurer.java
@@ -30,6 +30,7 @@ public class MetricsConfigurationPropertiesConfigurer extends 
org.apache.camel.s
         map.put("EnableRoutePolicy", boolean.class);
         map.put("Enabled", boolean.class);
         map.put("NamingStrategy", java.lang.String.class);
+        map.put("Path", java.lang.String.class);
         map.put("RoutePolicyLevel", java.lang.String.class);
         map.put("TextFormatVersion", java.lang.String.class);
         ALL_OPTIONS = map;
@@ -54,6 +55,7 @@ public class MetricsConfigurationPropertiesConfigurer extends 
org.apache.camel.s
         case "enabled": target.setEnabled(property(camelContext, 
boolean.class, value)); return true;
         case "namingstrategy":
         case "namingStrategy": target.setNamingStrategy(property(camelContext, 
java.lang.String.class, value)); return true;
+        case "path": target.setPath(property(camelContext, 
java.lang.String.class, value)); return true;
         case "routepolicylevel":
         case "routePolicyLevel": 
target.setRoutePolicyLevel(property(camelContext, java.lang.String.class, 
value)); return true;
         case "textformatversion":
@@ -88,6 +90,7 @@ public class MetricsConfigurationPropertiesConfigurer extends 
org.apache.camel.s
         case "enabled": return boolean.class;
         case "namingstrategy":
         case "namingStrategy": return java.lang.String.class;
+        case "path": return java.lang.String.class;
         case "routepolicylevel":
         case "routePolicyLevel": return java.lang.String.class;
         case "textformatversion":
@@ -114,6 +117,7 @@ public class MetricsConfigurationPropertiesConfigurer 
extends org.apache.camel.s
         case "enabled": return target.isEnabled();
         case "namingstrategy":
         case "namingStrategy": return target.getNamingStrategy();
+        case "path": return target.getPath();
         case "routepolicylevel":
         case "routePolicyLevel": return target.getRoutePolicyLevel();
         case "textformatversion":
diff --git 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 71c78f669b8..737ef52221d 100644
--- 
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ 
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -193,6 +193,7 @@
     { "name": "camel.metrics.enableRouteEventNotifier", "description": "Set 
whether to enable the MicrometerRouteEventNotifier for capturing metrics on the 
total number of routes and total number of routes running.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.metrics.enableRoutePolicy", "description": "Set whether 
to enable the MicrometerRoutePolicyFactory for capturing metrics on route 
processing times.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": true },
     { "name": "camel.metrics.namingStrategy", "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.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "default", "enum": [ "default", 
"legacy" ] },
+    { "name": "camel.metrics.path", "description": "The path endpoint used to 
expose the metrics.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "\/q\/metrics" },
     { "name": "camel.metrics.routePolicyLevel", "description": "Sets the level 
of information to capture. all = both context and routes.", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "all", "enum": [ "all", 
"route", "context" ] },
     { "name": "camel.metrics.textFormatVersion", "description": "The 
text-format version to use with Prometheus scraping. 0.0.4 = text\/plain; 
version=0.0.4; charset=utf-8 1.0.0 = application\/openmetrics-text; 
version=1.0.0; charset=utf-8", "sourceType": 
"org.apache.camel.main.MetricsConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "0.0.4", "enum": [ "0.0.4", 
"1.0.0" ] },
     { "name": "camel.opentelemetry.enabled", "description": "To enable 
OpenTelemetry", "sourceType": 
"org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
@@ -275,7 +276,7 @@
     { "name": "camel.server.jwtKeystorePath", "description": "Path to the 
keystore file used for JWT tokens validation.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String" },
     { "name": "camel.server.jwtKeystoreType", "description": "Type of the 
keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String" },
     { "name": "camel.server.maxBodySize", "description": "Maximum HTTP body 
size the embedded HTTP server can accept.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", 
"javaType": "java.lang.Long" },
-    { "name": "camel.server.metricsEnabled", "description": "Whether to enable 
metrics. If enabled then you can access metrics on context-path: \/q\/metrics", 
"sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", 
"type": "boolean", "javaType": "boolean", "defaultValue": "false" },
+    { "name": "camel.server.metricsEnabled", "description": "Whether to enable 
metrics. If enabled then you can access metrics on context-path: \/q\/metrics 
(default)", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.server.path", "description": "Context-path to use for 
embedded HTTP server", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", 
"javaType": "java.lang.String", "defaultValue": "\/" },
     { "name": "camel.server.port", "description": "Port to use for binding 
embedded HTTP server", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", 
"javaType": "int", "defaultValue": 8080 },
     { "name": "camel.server.sendEnabled", "description": "Whether to enable 
sending messages to Camel via HTTP. This makes it possible to use Camel to send 
messages to Camel endpoint URIs via HTTP.", "sourceType": 
"org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", 
"javaType": "boolean", "defaultValue": "false" },
diff --git a/core/camel-main/src/main/docs/main.adoc 
b/core/camel-main/src/main/docs/main.adoc
index 13a0bfb2888..f53f19f5eaa 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -206,7 +206,7 @@ The camel.server supports 23 options, which are listed 
below.
 | *camel.server.jwtKeystorePath* | Path to the keystore file used for JWT 
tokens validation. |  | String
 | *camel.server.jwtKeystoreType* | Type of the keystore used for JWT tokens 
validation (jks, pkcs12, etc.). |  | String
 | *camel.server.maxBodySize* | Maximum HTTP body size the embedded HTTP server 
can accept. |  | Long
-| *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then 
you can access metrics on context-path: /q/metrics | false | boolean
+| *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then 
you can access metrics on context-path: /q/metrics (default) | false | boolean
 | *camel.server.path* | Context-path to use for embedded HTTP server | / | 
String
 | *camel.server.port* | Port to use for binding embedded HTTP server | 8080 | 
int
 | *camel.server.sendEnabled* | Whether to enable sending messages to Camel via 
HTTP. This makes it possible to use Camel to send messages to Camel endpoint 
URIs via HTTP. | false | boolean
@@ -464,7 +464,7 @@ The camel.opentelemetry supports 5 options, which are 
listed below.
 
 
 === Camel Micrometer Metrics configurations
-The camel.metrics supports 10 options, which are listed below.
+The camel.metrics supports 11 options, which are listed below.
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -477,6 +477,7 @@ The camel.metrics supports 10 options, which are listed 
below.
 | *camel.metrics.enableRouteEvent{zwsp}Notifier* | Set whether to enable the 
MicrometerRouteEventNotifier for capturing metrics on the total number of 
routes and total number of routes running. | true | boolean
 | *camel.metrics.enableRoute{zwsp}Policy* | Set whether to enable the 
MicrometerRoutePolicyFactory for capturing metrics on route processing times. | 
true | boolean
 | *camel.metrics.namingStrategy* | Controls the name style to use for metrics. 
Default = uses micrometer naming convention. Legacy = uses the classic naming 
style (camelCase) | default | String
+| *camel.metrics.path* | The path endpoint used to expose the metrics. | 
/q/metrics | String
 | *camel.metrics.routePolicyLevel* | Sets the level of information to capture. 
all = both context and routes. | all | String
 | *camel.metrics.textFormat{zwsp}Version* | The text-format version to use 
with Prometheus scraping. 0.0.4 = text/plain; version=0.0.4; charset=utf-8 
1.0.0 = application/openmetrics-text; version=1.0.0; charset=utf-8 | 0.0.4 | 
String
 |===
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
index dcc30177cbc..0eaa8a2d8fb 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/HttpServerConfigurationProperties.java
@@ -221,7 +221,7 @@ public class HttpServerConfigurationProperties implements 
BootstrapCloseable {
     }
 
     /**
-     * Whether to enable metrics. If enabled then you can access metrics on 
context-path: /q/metrics
+     * Whether to enable metrics. If enabled then you can access metrics on 
context-path: /q/metrics (default)
      */
     public void setMetricsEnabled(boolean metricsEnabled) {
         this.metricsEnabled = metricsEnabled;
@@ -447,7 +447,7 @@ public class HttpServerConfigurationProperties implements 
BootstrapCloseable {
     }
 
     /**
-     * Whether to enable metrics. If enabled then you can access metrics on 
context-path: /q/metrics
+     * Whether to enable metrics. If enabled then you can access metrics on 
context-path: /q/metrics (default)
      */
     public HttpServerConfigurationProperties withMetricsEnabled(boolean 
metricsEnabled) {
         this.metricsEnabled = metricsEnabled;
diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java
 
b/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java
index 0fd2bcd8e2b..f86fce9d4cd 100644
--- 
a/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java
+++ 
b/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java
@@ -46,6 +46,8 @@ public class MetricsConfigurationProperties implements 
BootstrapCloseable {
     private String textFormatVersion = "0.0.4";
     @Metadata
     private String binders;
+    @Metadata(defaultValue = "/q/metrics")
+    private String path = "/q/metrics";
 
     public MetricsConfigurationProperties(MainConfigurationProperties parent) {
         this.parent = parent;
@@ -180,6 +182,17 @@ public class MetricsConfigurationProperties implements 
BootstrapCloseable {
         this.binders = binders;
     }
 
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     * The path endpoint used to expose the metrics.
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
     @Override
     public void close() {
         parent = null;

Reply via email to