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 6f487542ec592c7efd4749780e461c093d6ca3ec Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Nov 16 09:32:36 2023 +0100 CAMEL-20105: camel-micromemter - Make it easier to configure for camel-main --- .../main/camel-main-configuration-metadata.json | 1 + .../prometheus/MicrometerPrometheusConfigurer.java | 6 ++++ .../prometheus/MicrometerPrometheus.java | 33 +++++++++++++++++++--- .../MetricsConfigurationPropertiesConfigurer.java | 6 ++++ .../camel-main-configuration-metadata.json | 1 + core/camel-main/src/main/docs/main.adoc | 3 +- .../camel/main/MetricsConfigurationProperties.java | 28 ++++++++++++++++++ 7 files changed, 73 insertions(+), 5 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 92bef5801ed..22167f65ed6 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 @@ -185,6 +185,7 @@ { "name": "camel.metrics.enableMessageHistory", "description": "Set whether to enable the MicrometerMessageHistoryFactory for capturing metrics on individual route node processing times. Depending on the number of configured route nodes, there is the potential to create a large volume of metrics. Therefore, this option is disabled by default.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "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.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" }, { "name": "camel.opentelemetry.encoding", "description": "Sets whether the header keys need to be encoded (connector specific) or not. The value is a boolean. Dashes need for instances to be encoded for JMS property keys.", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.opentelemetry.excludePatterns", "description": "Adds an exclude pattern that will disable tracing for Camel messages that matches the pattern. Multiple patterns can be separated by comma.", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, 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 2f934e1d64e..abad014040c 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 @@ -31,6 +31,8 @@ public class MicrometerPrometheusConfigurer extends org.apache.camel.support.com case "EnableRouteEventNotifier": target.setEnableRouteEventNotifier(property(camelContext, boolean.class, value)); return true; case "enableroutepolicy": case "EnableRoutePolicy": target.setEnableRoutePolicy(property(camelContext, boolean.class, value)); return true; + case "textformatversion": + case "TextFormatVersion": target.setTextFormatVersion(property(camelContext, java.lang.String.class, value)); return true; default: return false; } } @@ -48,6 +50,8 @@ public class MicrometerPrometheusConfigurer extends org.apache.camel.support.com case "EnableRouteEventNotifier": return boolean.class; case "enableroutepolicy": case "EnableRoutePolicy": return boolean.class; + case "textformatversion": + case "TextFormatVersion": return java.lang.String.class; default: return null; } } @@ -66,6 +70,8 @@ public class MicrometerPrometheusConfigurer extends org.apache.camel.support.com case "EnableRouteEventNotifier": return target.isEnableRouteEventNotifier(); case "enableroutepolicy": case "EnableRoutePolicy": return target.isEnableRoutePolicy(); + case "textformatversion": + case "TextFormatVersion": return target.getTextFormatVersion(); default: return null; } } 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 61efbba632b..1f20b3e3841 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 @@ -18,6 +18,7 @@ package org.apache.camel.component.micrometer.prometheus; import io.micrometer.prometheus.PrometheusConfig; import io.micrometer.prometheus.PrometheusMeterRegistry; +import io.prometheus.client.exporter.common.TextFormat; import io.vertx.core.Handler; import io.vertx.core.http.HttpMethod; import io.vertx.ext.web.Route; @@ -53,7 +54,6 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics private VertxPlatformHttpRouter router; private PlatformHttpComponent platformHttpComponent; - // TODO: 0.0.4 or 1.0.0 text format // TODO: option include JVM metrics // TODO: option include platform-http metrics // TODO: include easily with jbang @@ -70,6 +70,8 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics private boolean enableExchangeEventNotifier = true; @Metadata(defaultValue = "true") private boolean enableRouteEventNotifier = true; + @Metadata(defaultValue = "0.0.4", enums = "0.0.4,1.0.0") + private String textFormatVersion = "0.0.4"; @Override public CamelContext getCamelContext() { @@ -130,6 +132,20 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics this.enableRouteEventNotifier = enableRouteEventNotifier; } + public String getTextFormatVersion() { + return textFormatVersion; + } + + /** + * 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 + */ + public void setTextFormatVersion(String textFormatVersion) { + this.textFormatVersion = textFormatVersion; + } + @Override protected void doStart() throws Exception { super.doStart(); @@ -177,13 +193,22 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics protected void setupHttpScraper() { Route metrics = router.route("/q/metrics"); metrics.method(HttpMethod.GET); - metrics.produces("text/plain;version=0.0.4;charset=utf-8"); + + final String format = "0.0.4".equals(textFormatVersion) ? TextFormat.CONTENT_TYPE_004 : TextFormat.CONTENT_TYPE_OPENMETRICS_100; + metrics.produces(format); Handler<RoutingContext> handler = new Handler<RoutingContext>() { @Override public void handle(RoutingContext ctx) { - ctx.response().putHeader("content-type", "text/plain;version=0.0.4;charset=utf-8"); - String data = meterRegistry.scrape(); + String ct = format; + // the client may ask for version 1.0.0 via accept header + String ah = ctx.request().getHeader("Accept"); + if (ah != null && ah.contains("application/openmetrics-text")) { + ct = TextFormat.chooseContentType(ah); + } + + ctx.response().putHeader("Content-Type", ct); + String data = meterRegistry.scrape(ct); ctx.end(data); } }; 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 a20fbbf666e..ed323ad35fd 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 @@ -31,6 +31,8 @@ public class MetricsConfigurationPropertiesConfigurer extends org.apache.camel.s case "EnableRoutePolicy": target.setEnableRoutePolicy(property(camelContext, boolean.class, value)); return true; case "enabled": case "Enabled": target.setEnabled(property(camelContext, boolean.class, value)); return true; + case "textformatversion": + case "TextFormatVersion": target.setTextFormatVersion(property(camelContext, java.lang.String.class, value)); return true; default: return false; } } @@ -48,6 +50,8 @@ public class MetricsConfigurationPropertiesConfigurer extends org.apache.camel.s case "EnableRoutePolicy": return boolean.class; case "enabled": case "Enabled": return boolean.class; + case "textformatversion": + case "TextFormatVersion": return java.lang.String.class; default: return null; } } @@ -66,6 +70,8 @@ public class MetricsConfigurationPropertiesConfigurer extends org.apache.camel.s case "EnableRoutePolicy": return target.isEnableRoutePolicy(); case "enabled": case "Enabled": return target.isEnabled(); + case "textformatversion": + case "TextFormatVersion": return target.getTextFormatVersion(); default: return null; } } 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 92bef5801ed..22167f65ed6 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 @@ -185,6 +185,7 @@ { "name": "camel.metrics.enableMessageHistory", "description": "Set whether to enable the MicrometerMessageHistoryFactory for capturing metrics on individual route node processing times. Depending on the number of configured route nodes, there is the potential to create a large volume of metrics. Therefore, this option is disabled by default.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "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.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" }, { "name": "camel.opentelemetry.encoding", "description": "Sets whether the header keys need to be encoded (connector specific) or not. The value is a boolean. Dashes need for instances to be encoded for JMS property keys.", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.opentelemetry.excludePatterns", "description": "Adds an exclude pattern that will disable tracing for Camel messages that matches the pattern. Multiple patterns can be separated by comma.", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 22cbfb5a276..426dff178b1 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -347,7 +347,7 @@ The camel.opentelemetry supports 4 options, which are listed below. === Camel Micrometer Metrics configurations -The camel.metrics supports 5 options, which are listed below. +The camel.metrics supports 6 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== @@ -357,6 +357,7 @@ The camel.metrics supports 5 options, which are listed below. | *camel.metrics.enableMessage{zwsp}History* | Set whether to enable the MicrometerMessageHistoryFactory for capturing metrics on individual route node processing times. Depending on the number of configured route nodes, there is the potential to create a large volume of metrics. Therefore, this option is disabled by default. | false | boolean | *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.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/MetricsConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java index d9985fcf26f..dd55c2951c3 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 @@ -36,6 +36,8 @@ public class MetricsConfigurationProperties implements BootstrapCloseable { private boolean enableExchangeEventNotifier = true; @Metadata(defaultValue = "true") private boolean enableRouteEventNotifier = true; + @Metadata(defaultValue = "0.0.4", enums = "0.0.4,1.0.0") + private String textFormatVersion = "0.0.4"; public MetricsConfigurationProperties(MainConfigurationProperties parent) { this.parent = parent; @@ -105,6 +107,20 @@ public class MetricsConfigurationProperties implements BootstrapCloseable { this.enableRouteEventNotifier = enableRouteEventNotifier; } + public String getTextFormatVersion() { + return textFormatVersion; + } + + /** + * 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 + */ + public void setTextFormatVersion(String textFormatVersion) { + this.textFormatVersion = textFormatVersion; + } + @Override public void close() { parent = null; @@ -155,4 +171,16 @@ public class MetricsConfigurationProperties implements BootstrapCloseable { return this; } + /** + * 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 + */ + public MetricsConfigurationProperties withTextFormatVersion(String textFormatVersion) { + this.textFormatVersion = textFormatVersion; + return this; + } + + }