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 2b270a72a1ed254e6e38f1dfef524cdd07e66899 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Nov 15 20:23:11 2023 +0100 CAMEL-20105: camel-micromemter - Make it easier to configure for camel-main --- .../MetricsConfigurationPropertiesConfigurer.java | 67 ++++++++++ .../camel-main-configuration-metadata.json | 5 + ...pache.camel.main.MetricsConfigurationProperties | 2 + core/camel-main/src/main/docs/main.adoc | 13 ++ .../org/apache/camel/main/BaseMainSupport.java | 28 +++++ .../camel/main/MainConfigurationProperties.java | 22 ++++ .../camel/main/MetricsConfigurationProperties.java | 138 +++++++++++++++++++++ .../maven/packaging/PrepareCamelMainMojo.java | 5 + 8 files changed, 280 insertions(+) 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 new file mode 100644 index 00000000000..e81062ff0eb --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/MetricsConfigurationPropertiesConfigurer.java @@ -0,0 +1,67 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.MetricsConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class MetricsConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.MetricsConfigurationProperties target = (org.apache.camel.main.MetricsConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "enableexchangeeventnotifier": + case "EnableExchangeEventNotifier": target.setEnableExchangeEventNotifier(property(camelContext, boolean.class, value)); return true; + case "enablemessagehistory": + case "EnableMessageHistory": target.setEnableMessageHistory(property(camelContext, boolean.class, value)); return true; + case "enablerouteeventnotifier": + case "EnableRouteEventNotifier": target.setEnableRouteEventNotifier(property(camelContext, boolean.class, value)); return true; + case "enableroutepolicy": + case "EnableRoutePolicy": target.setEnableRoutePolicy(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "enableexchangeeventnotifier": + case "EnableExchangeEventNotifier": return boolean.class; + case "enablemessagehistory": + case "EnableMessageHistory": return boolean.class; + case "enablerouteeventnotifier": + case "EnableRouteEventNotifier": return boolean.class; + case "enableroutepolicy": + case "EnableRoutePolicy": return boolean.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.MetricsConfigurationProperties target = (org.apache.camel.main.MetricsConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "enableexchangeeventnotifier": + case "EnableExchangeEventNotifier": return target.isEnableExchangeEventNotifier(); + case "enablemessagehistory": + case "EnableMessageHistory": return target.isEnableMessageHistory(); + case "enablerouteeventnotifier": + case "EnableRouteEventNotifier": return target.isEnableRouteEventNotifier(); + case "enableroutepolicy": + case "EnableRoutePolicy": return target.isEnableRoutePolicy(); + 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 3a89ff173c1..d5a1d229594 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 @@ -11,6 +11,7 @@ { "name": "camel.vault.gcp", "description": "Camel GCP Vault configurations", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration" }, { "name": "camel.vault.azure", "description": "Camel Azure Key Vault configurations", "sourceType": "org.apache.camel.vault.AzureVaultConfiguration" }, { "name": "camel.opentelemetry", "description": "Camel OpenTelemtry configurations", "sourceType": "org.apache.camel.main.OtelConfigurationProperties" }, + { "name": "camel.metrics", "description": "Camel Micrometer Metrics configurations", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties" }, { "name": "camel.faulttolerance", "description": "Fault Tolerance EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.FaultToleranceConfigurationProperties" }, { "name": "camel.resilience4j", "description": "Resilience4j EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.Resilience4jConfigurationProperties" }, { "name": "camel.lra", "description": "Camel Saga EIP (Long Running Actions) configurations", "sourceType": "org.apache.camel.main.LraConfigurationProperties" } @@ -178,6 +179,10 @@ { "name": "camel.lra.coordinatorUrl", "description": "The URL for the LRA coordinator service that orchestrates the transactions", "sourceType": "org.apache.camel.main.LraConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.lra.localParticipantContextPath", "description": "The context-path for the local participant. Is default \/lra-participant", "sourceType": "org.apache.camel.main.LraConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/lra-participant" }, { "name": "camel.lra.localParticipantUrl", "description": "The URL for the local participant", "sourceType": "org.apache.camel.main.LraConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, + { "name": "camel.metrics.enableExchangeEventNotifier", "description": "Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "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.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" }, { "name": "camel.opentelemetry.instrumentationName", "description": "A name uniquely identifying the instrumentation scope, such as the instrumentation library, package, or fully qualified class name. Must not be null.", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "camel" }, diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.MetricsConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.MetricsConfigurationProperties new file mode 100644 index 00000000000..fd356d7ac12 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.MetricsConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.MetricsConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc index 3dee56918ae..c855cacb293 100644 --- a/core/camel-main/src/main/docs/main.adoc +++ b/core/camel-main/src/main/docs/main.adoc @@ -344,6 +344,19 @@ The camel.opentelemetry supports 3 options, which are listed below. |=== +=== Camel Micrometer Metrics configurations +The camel.metrics supports 4 options, which are listed below. + +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *camel.metrics.enableExchange{zwsp}EventNotifier* | Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times. | true | boolean +| *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 +|=== + + === Fault Tolerance EIP Circuit Breaker configurations The camel.faulttolerance supports 13 options, which are listed below. diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index bbaff3f289e..fe09836d7f0 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -952,6 +952,7 @@ public abstract class BaseMainSupport extends BaseService { OrderedLocationProperties healthProperties = new OrderedLocationProperties(); OrderedLocationProperties lraProperties = new OrderedLocationProperties(); OrderedLocationProperties otelProperties = new OrderedLocationProperties(); + OrderedLocationProperties metricsProperties = new OrderedLocationProperties(); OrderedLocationProperties routeTemplateProperties = new OrderedLocationProperties(); OrderedLocationProperties beansProperties = new OrderedLocationProperties(); OrderedLocationProperties devConsoleProperties = new OrderedLocationProperties(); @@ -1015,6 +1016,12 @@ public abstract class BaseMainSupport extends BaseService { String option = key.substring(20); validateOptionAndValue(key, option, value); otelProperties.put(loc, optionKey(option), value); + } else if (key.startsWith("camel.metrics.")) { + // grab the value + String value = prop.getProperty(key); + String option = key.substring(14); + validateOptionAndValue(key, option, value); + metricsProperties.put(loc, optionKey(option), value); } else if (key.startsWith("camel.routeTemplate")) { // grab the value String value = prop.getProperty(key); @@ -1127,6 +1134,11 @@ public abstract class BaseMainSupport extends BaseService { setOtelProperties(camelContext, otelProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), autoConfiguredProperties); } + if (!metricsProperties.isEmpty() || mainConfigurationProperties.hasMetricsConfiguration()) { + LOG.debug("Auto-configuring Micrometer metrics from loaded properties: {}", metricsProperties.size()); + setMetricsProperties(camelContext, metricsProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), + autoConfiguredProperties); + } if (!devConsoleProperties.isEmpty()) { LOG.debug("Auto-configuring Dev Console from loaded properties: {}", devConsoleProperties.size()); setDevConsoleProperties(camelContext, devConsoleProperties, @@ -1396,6 +1408,22 @@ public abstract class BaseMainSupport extends BaseService { } } + private void setMetricsProperties( + CamelContext camelContext, OrderedLocationProperties metricsProperties, + boolean failIfNotSet, OrderedLocationProperties autoConfiguredProperties) + throws Exception { + + String loc = metricsProperties.getLocation("enabled"); + Object obj = metricsProperties.remove("enabled"); + if (ObjectHelper.isNotEmpty(obj)) { + autoConfiguredProperties.put(loc, "camel.metrics.enabled", obj.toString()); + } + boolean enabled = obj != null ? CamelContextHelper.parseBoolean(camelContext, obj.toString()) : true; + if (enabled) { + // TODO: + } + } + private void setDevConsoleProperties( CamelContext camelContext, OrderedLocationProperties properties, boolean failIfNotSet, OrderedLocationProperties autoConfiguredProperties) { diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java index 79273789d92..70300e16c70 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java @@ -54,6 +54,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< private HealthConfigurationProperties healthConfigurationProperties; private LraConfigurationProperties lraConfigurationProperties; private OtelConfigurationProperties otelConfigurationProperties; + private MetricsConfigurationProperties metricsConfigurationProperties; private ThreadPoolConfigurationProperties threadPoolProperties; private Resilience4jConfigurationProperties resilience4jConfigurationProperties; private FaultToleranceConfigurationProperties faultToleranceConfigurationProperties; @@ -77,6 +78,10 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< otelConfigurationProperties.close(); otelConfigurationProperties = null; } + if (metricsConfigurationProperties != null) { + metricsConfigurationProperties.close(); + metricsConfigurationProperties = null; + } if (threadPoolProperties != null) { threadPoolProperties.close(); threadPoolProperties = null; @@ -173,6 +178,23 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< return otelConfigurationProperties != null; } + /** + * To configure Micrometer metrics. + */ + public MetricsConfigurationProperties metrics() { + if (metricsConfigurationProperties == null) { + metricsConfigurationProperties = new MetricsConfigurationProperties(this); + } + return metricsConfigurationProperties; + } + + /** + * Whether there has been any Micrometer metrics configuration specified + */ + public boolean hasMetricsConfiguration() { + return metricsConfigurationProperties != null; + } + /** * To configure embedded HTTP server (for standalone applications; not Spring Boot or Quarkus) */ 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 new file mode 100644 index 00000000000..ca54f8122c6 --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/MetricsConfigurationProperties.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.main; + +import org.apache.camel.spi.BootstrapCloseable; +import org.apache.camel.spi.Configurer; +import org.apache.camel.spi.Metadata; + +/** + * Global configuration for Micrometer Metrics. + */ +@Configurer(bootstrap = true) +public class MetricsConfigurationProperties implements BootstrapCloseable { + + private MainConfigurationProperties parent; + + @Metadata(defaultValue = "true") + private boolean enableRoutePolicy = true; + private boolean enableMessageHistory; + @Metadata(defaultValue = "true") + private boolean enableExchangeEventNotifier = true; + @Metadata(defaultValue = "true") + private boolean enableRouteEventNotifier = true; + + public MetricsConfigurationProperties(MainConfigurationProperties parent) { + this.parent = parent; + } + + public MainConfigurationProperties end() { + return parent; + } + + public boolean isEnableRoutePolicy() { + return enableRoutePolicy; + } + + /** + * Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times. + */ + public void setEnableRoutePolicy(boolean enableRoutePolicy) { + this.enableRoutePolicy = enableRoutePolicy; + } + + public boolean isEnableMessageHistory() { + return enableMessageHistory; + } + + /** + * 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. + */ + public void setEnableMessageHistory(boolean enableMessageHistory) { + this.enableMessageHistory = enableMessageHistory; + } + + public boolean isEnableExchangeEventNotifier() { + return enableExchangeEventNotifier; + } + + /** + * Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times. + */ + public void setEnableExchangeEventNotifier(boolean enableExchangeEventNotifier) { + this.enableExchangeEventNotifier = enableExchangeEventNotifier; + } + + public boolean isEnableRouteEventNotifier() { + return enableRouteEventNotifier; + } + + /** + * Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and + * total number of routes running. + */ + public void setEnableRouteEventNotifier(boolean enableRouteEventNotifier) { + this.enableRouteEventNotifier = enableRouteEventNotifier; + } + + @Override + public void close() { + parent = null; + } + + /** + * Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times. + */ + public MetricsConfigurationProperties withEnableRoutePolicy(boolean enableRoutePolicy) { + this.enableRoutePolicy = enableRoutePolicy; + return this; + } + + /** + * 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. + */ + public MetricsConfigurationProperties withEnableMessageHistory(boolean enableMessageHistory) { + this.enableMessageHistory = enableMessageHistory; + return this; + } + + /** + * Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times. + */ + public MetricsConfigurationProperties withEnableExchangeEventNotifier(boolean enableExchangeEventNotifier) { + this.enableExchangeEventNotifier = enableExchangeEventNotifier; + return this; + } + + /** + * Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and + * total number of routes running. + */ + public MetricsConfigurationProperties witheEnableRouteEventNotifier(boolean enableRouteEventNotifier) { + this.enableRouteEventNotifier = enableRouteEventNotifier; + return this; + } + +} diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java index e5d80ece234..43789467da0 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java @@ -206,6 +206,8 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { prefix = "camel.lra."; } else if (file.getName().contains("Otel")) { prefix = "camel.opentelemetry."; + } else if (file.getName().contains("Metrics")) { + prefix = "camel.metrics."; } else if (file.getName().contains("HttpServer")) { prefix = "camel.server."; } else if (file.getName().contains("ThreadPoolProfileConfigurationProperties")) { @@ -321,6 +323,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo { model.getGroups().add(new MainGroupModel( "camel.opentelemetry", "Camel OpenTelemtry configurations", "org.apache.camel.main.OtelConfigurationProperties")); + model.getGroups().add(new MainGroupModel( + "camel.metrics", "Camel Micrometer Metrics configurations", + "org.apache.camel.main.MetricsConfigurationProperties")); model.getGroups() .add(new MainGroupModel( "camel.faulttolerance", "Fault Tolerance EIP Circuit Breaker configurations",