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 a2e3befa30b9e5efe698104860be7dbdf75b381c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Nov 16 09:16:11 2023 +0100 CAMEL-20105: camel-micromemter - Make it easier to configure for camel-main --- .../main/camel-main-configuration-metadata.json | 1 + .../prometheus/MicrometerPrometheus.java | 22 ++++++++++------------ .../http/main/DefaultMainHttpServerFactory.java | 1 + .../platform/http/main/MainHttpServer.java | 13 +++++++++++++ ...ttpServerConfigurationPropertiesConfigurer.java | 6 ++++++ .../camel-main-configuration-metadata.json | 1 + core/camel-main/src/main/docs/main.adoc | 3 ++- .../main/HttpServerConfigurationProperties.java | 20 ++++++++++++++++++++ 8 files changed, 54 insertions(+), 13 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 5521078c575..92bef5801ed 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 @@ -242,6 +242,7 @@ { "name": "camel.server.healthCheckEnabled", "description": "Whether to enable health-check console. If enabled then you can access health-check status on context-path: \/q\/health", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.host", "description": "Hostname to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.0.0" }, { "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.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.uploadEnabled", "description": "Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload\/delete files via HTTP PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the uploadSourceDir option.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "t [...] 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 37cd13762ce..61efbba632b 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 @@ -31,8 +31,8 @@ import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventN import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory; import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory; import org.apache.camel.component.platform.http.PlatformHttpComponent; +import org.apache.camel.component.platform.http.main.MainHttpServer; import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter; -import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpServer; import org.apache.camel.spi.CamelMetricsService; import org.apache.camel.spi.Configurer; import org.apache.camel.spi.ManagementStrategy; @@ -49,16 +49,14 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics private static final Logger LOG = LoggerFactory.getLogger(MicrometerPrometheus.class); - private VertxPlatformHttpServer server; + private MainHttpServer server; private VertxPlatformHttpRouter router; private PlatformHttpComponent platformHttpComponent; - // TODO: option to configure prometheus (on or off) // TODO: 0.0.4 or 1.0.0 text format - // TODO: rename to camel-micrometer-main + // TODO: option include JVM metrics + // TODO: option include platform-http metrics // TODO: include easily with jbang - // TODO: camel.server.metricsEnabled=true|false - // TODO: camel.server.otelEnabled=true|false // TODO: docs private CamelContext camelContext; @@ -164,11 +162,11 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics camelContext.setMessageHistoryFactory(factory); } - server = camelContext.hasService(VertxPlatformHttpServer.class); + server = camelContext.hasService(MainHttpServer.class); router = VertxPlatformHttpRouter.lookup(camelContext); platformHttpComponent = camelContext.getComponent("platform-http", PlatformHttpComponent.class); - if (server != null && router != null && platformHttpComponent != null) { + if (server != null && server.isMetricsEnabled() && router != null && platformHttpComponent != null) { setupHttpScraper(); LOG.info("MicrometerPrometheus enabled with HTTP scraping on /q/metrics"); } else { @@ -177,9 +175,9 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics } protected void setupHttpScraper() { - Route metrcis = router.route("/q/metrics"); - metrcis.method(HttpMethod.GET); - metrcis.produces("text/plain;version=0.0.4;charset=utf-8"); + Route metrics = router.route("/q/metrics"); + metrics.method(HttpMethod.GET); + metrics.produces("text/plain;version=0.0.4;charset=utf-8"); Handler<RoutingContext> handler = new Handler<RoutingContext>() { @Override @@ -191,7 +189,7 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics }; // use blocking handler as the task can take longer time to complete - metrcis.handler(new BlockingHandlerDecorator(handler, true)); + metrics.handler(new BlockingHandlerDecorator(handler, true)); platformHttpComponent.addHttpEndpoint("/q/metrics", null, null); } diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java index f5bac97f9ec..967e536ba6b 100644 --- a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/DefaultMainHttpServerFactory.java @@ -53,6 +53,7 @@ public class DefaultMainHttpServerFactory implements CamelContextAware, MainHttp server.setUseGlobalSslContextParameters(configuration.isUseGlobalSslContextParameters()); server.setDevConsoleEnabled(configuration.isDevConsoleEnabled()); server.setHealthCheckEnabled(configuration.isHealthCheckEnabled()); + server.setMetricsEnabled(configuration.isMetricsEnabled()); server.setUploadEnabled(configuration.isUploadEnabled()); server.setUploadSourceDir(configuration.getUploadSourceDir()); diff --git a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java index e80cf310cc3..0738a279265 100644 --- a/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java +++ b/components/camel-platform-http-main/src/main/java/org/apache/camel/component/platform/http/main/MainHttpServer.java @@ -81,6 +81,7 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, private VertxPlatformHttpServerConfiguration configuration = new VertxPlatformHttpServerConfiguration(); private boolean devConsoleEnabled; private boolean healthCheckEnabled; + private boolean metricsEnabled; private boolean uploadEnabled; private String uploadSourceDir; @@ -124,6 +125,17 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, this.healthCheckEnabled = healthCheckEnabled; } + public boolean isMetricsEnabled() { + return metricsEnabled; + } + + /** + * Whether metrics is enabled (q/metrics) + */ + public void setMetricsEnabled(boolean metricsEnabled) { + this.metricsEnabled = metricsEnabled; + } + public boolean isUploadEnabled() { return uploadEnabled; } @@ -241,6 +253,7 @@ public class MainHttpServer extends ServiceSupport implements CamelContextAware, } setupUploadConsole(uploadSourceDir); } + // metrics will be setup in camel-micrometer-prometheus } protected void setupStartupSummary() throws Exception { diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java index 07c8e29295b..7479623930b 100644 --- a/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HttpServerConfigurationPropertiesConfigurer.java @@ -31,6 +31,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "Host": target.setHost(property(camelContext, java.lang.String.class, value)); return true; case "maxbodysize": case "MaxBodySize": target.setMaxBodySize(property(camelContext, java.lang.Long.class, value)); return true; + case "metricsenabled": + case "MetricsEnabled": target.setMetricsEnabled(property(camelContext, boolean.class, value)); return true; case "path": case "Path": target.setPath(property(camelContext, java.lang.String.class, value)); return true; case "port": @@ -58,6 +60,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "Host": return java.lang.String.class; case "maxbodysize": case "MaxBodySize": return java.lang.Long.class; + case "metricsenabled": + case "MetricsEnabled": return boolean.class; case "path": case "Path": return java.lang.String.class; case "port": @@ -86,6 +90,8 @@ public class HttpServerConfigurationPropertiesConfigurer extends org.apache.came case "Host": return target.getHost(); case "maxbodysize": case "MaxBodySize": return target.getMaxBodySize(); + case "metricsenabled": + case "MetricsEnabled": return target.isMetricsEnabled(); case "path": case "Path": return target.getPath(); case "port": 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 5521078c575..92bef5801ed 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 @@ -242,6 +242,7 @@ { "name": "camel.server.healthCheckEnabled", "description": "Whether to enable health-check console. If enabled then you can access health-check status on context-path: \/q\/health", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" }, { "name": "camel.server.host", "description": "Hostname to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.0.0" }, { "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.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.uploadEnabled", "description": "Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload\/delete files via HTTP PUT\/DELETE on context-path: \/q\/upload\/{name}. You must also configure the uploadSourceDir option.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "t [...] diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 9eb1ebfe7a9..22cbfb5a276 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -154,7 +154,7 @@ The camel.main supports 126 options, which are listed below. === Camel Embedded HTTP Server (only for standalone; not Spring Boot or Quarkus) configurations -The camel.server supports 10 options, which are listed below. +The camel.server supports 11 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== @@ -164,6 +164,7 @@ The camel.server supports 10 options, which are listed below. | *camel.server.healthCheck{zwsp}Enabled* | Whether to enable health-check console. If enabled then you can access health-check status on context-path: /q/health | false | boolean | *camel.server.host* | Hostname to use for binding embedded HTTP server | 0.0.0.0 | 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.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.uploadEnabled* | Whether to enable file upload via HTTP (not intended for production use). This functionality is for development to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can upload/delete files via HTTP PUT/DELETE on context-path: /q/upload/\{name}. You must also configure the uploadSourceDir option. | false | boolean 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 2d9fb21e1ef..31ca9b144ec 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 @@ -41,6 +41,7 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { private boolean devConsoleEnabled; private boolean healthCheckEnabled; + private boolean metricsEnabled; private boolean uploadEnabled; private String uploadSourceDir; @@ -149,6 +150,17 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { this.healthCheckEnabled = healthCheckEnabled; } + public boolean isMetricsEnabled() { + return metricsEnabled; + } + + /** + * Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics + */ + public void setMetricsEnabled(boolean metricsEnabled) { + this.metricsEnabled = metricsEnabled; + } + public boolean isUploadEnabled() { return uploadEnabled; } @@ -242,6 +254,14 @@ public class HttpServerConfigurationProperties implements BootstrapCloseable { return this; } + /** + * Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics + */ + public HttpServerConfigurationProperties withMetricsEnabled(boolean metricsEnabled) { + this.metricsEnabled = metricsEnabled; + return this; + } + /** * Whether to enable file upload via HTTP (not intended for production use). This functionality is for development * to be able to reload Camel routes and code with source changes (if reload is enabled). If enabled then you can