You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/11/26 18:39:16 UTC
[camel-spring-boot] 01/04: CAMEL-18754: camel-micrometer - Add auto configuration for capturing metrics. WIP
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
commit 322ee00e390d0f6c3f8655b54f8d81b1951d7599
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Nov 26 12:53:57 2022 +0100
CAMEL-18754: camel-micrometer - Add auto configuration for capturing metrics. WIP
---
.../src/main/docs/micrometer.json | 33 +++++++++
.../CamelMicrometerAutoConfiguration.java | 82 ++++++++++++++++++++++
.../springboot/CamelMicrometerConfiguration.java | 82 ++++++++++++++++++++++
.../src/main/resources/META-INF/spring.factories | 3 +-
4 files changed, 199 insertions(+), 1 deletion(-)
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 c550e60be08..3872996642d 100644
--- a/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
+++ b/components-starter/camel-micrometer-starter/src/main/docs/micrometer.json
@@ -10,6 +10,11 @@
"type": "org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon$CustomizerProperties",
"sourceType": "org.apache.camel.component.micrometer.springboot.MicrometerComponentConfiguration",
"sourceMethod": "getCustomizer()"
+ },
+ {
+ "name": "camel.metrics",
+ "type": "org.apache.camel.component.micrometer.springboot.CamelMicrometerConfiguration",
+ "sourceType": "org.apache.camel.component.micrometer.springboot.CamelMicrometerConfiguration"
}
],
"properties": [
@@ -43,6 +48,34 @@
"type": "io.micrometer.core.instrument.MeterRegistry",
"description": "To use a custom configured MetricRegistry. The option is a io.micrometer.core.instrument.MeterRegistry type.",
"sourceType": "org.apache.camel.component.micrometer.springboot.MicrometerComponentConfiguration"
+ },
+ {
+ "name": "camel.metrics.enable-exchange-event-notifier",
+ "type": "java.lang.Boolean",
+ "description": "Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times.",
+ "sourceType": "org.apache.camel.component.micrometer.springboot.CamelMicrometerConfiguration",
+ "defaultValue": true
+ },
+ {
+ "name": "camel.metrics.enable-message-history",
+ "type": "java.lang.Boolean",
+ "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.component.micrometer.springboot.CamelMicrometerConfiguration",
+ "defaultValue": false
+ },
+ {
+ "name": "camel.metrics.enable-route-event-notifier",
+ "type": "java.lang.Boolean",
+ "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.component.micrometer.springboot.CamelMicrometerConfiguration",
+ "defaultValue": true
+ },
+ {
+ "name": "camel.metrics.enable-route-policy",
+ "type": "java.lang.Boolean",
+ "description": "Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times.",
+ "sourceType": "org.apache.camel.component.micrometer.springboot.CamelMicrometerConfiguration",
+ "defaultValue": true
}
],
"hints": []
diff --git a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerAutoConfiguration.java b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerAutoConfiguration.java
new file mode 100644
index 00000000000..24b8f647855
--- /dev/null
+++ b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerAutoConfiguration.java
@@ -0,0 +1,82 @@
+/*
+ * 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.component.micrometer.springboot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
+import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
+import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
+import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
+import org.apache.camel.spi.CamelContextCustomizer;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.ConditionalOnHierarchicalProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Lazy;
+
+@Conditional(ConditionalOnCamelContextAndAutoConfigurationBeans.class)
+@EnableConfigurationProperties({CamelMicrometerConfiguration.class})
+@ConditionalOnHierarchicalProperties({"camel.metrics"})
+@AutoConfigureAfter({CamelAutoConfiguration.class})
+public class CamelMicrometerAutoConfiguration {
+
+ @Autowired
+ private ApplicationContext applicationContext;
+ private final CamelContext camelContext;
+ @Autowired
+ private CamelMicrometerConfiguration configuration;
+
+ public CamelMicrometerAutoConfiguration(
+ CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Lazy
+ @Bean
+ public CamelContextCustomizer configureMicrometer() {
+ return new CamelContextCustomizer() {
+ @Override
+ public void configure(CamelContext camelContext) {
+ if (configuration.isEnableRoutePolicy()) {
+ camelContext.addRoutePolicyFactory(new MicrometerRoutePolicyFactory());
+ }
+
+ ManagementStrategy managementStrategy = camelContext.getManagementStrategy();
+ if (configuration.isEnableExchangeEventNotifier()) {
+ managementStrategy.addEventNotifier(new MicrometerExchangeEventNotifier());
+ }
+
+ if (configuration.isEnableRouteEventNotifier()) {
+ managementStrategy.addEventNotifier(new MicrometerRouteEventNotifier());
+ }
+
+ if (configuration.isEnableMessageHistory()) {
+ if (!camelContext.isMessageHistory()) {
+ camelContext.setMessageHistory(true);
+ }
+ camelContext.setMessageHistoryFactory(new MicrometerMessageHistoryFactory());
+ }
+ }
+ };
+ }
+}
\ No newline at end of file
diff --git a/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerConfiguration.java b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerConfiguration.java
new file mode 100644
index 00000000000..a1eced0e87c
--- /dev/null
+++ b/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/CamelMicrometerConfiguration.java
@@ -0,0 +1,82 @@
+/*
+ * 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.component.micrometer.springboot;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.metrics")
+public class CamelMicrometerConfiguration {
+
+ /**
+ * Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics
+ * on route processing times.
+ */
+ private boolean enableRoutePolicy = true;
+
+ /**
+ * 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.
+ */
+ private boolean enableMessageHistory;
+
+ /**
+ * Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics
+ * on exchange processing times.
+ */
+ private boolean enableExchangeEventNotifier = true;
+
+ /**
+ * Set whether to enable the MicrometerRouteEventNotifier for capturing metrics
+ * on the total number of routes and total number of routes running.
+ */
+ private boolean enableRouteEventNotifier = true;
+
+ public boolean isEnableRoutePolicy() {
+ return enableRoutePolicy;
+ }
+
+ public void setEnableRoutePolicy(boolean enableRoutePolicy) {
+ this.enableRoutePolicy = enableRoutePolicy;
+ }
+
+ public boolean isEnableMessageHistory() {
+ return enableMessageHistory;
+ }
+
+ public void setEnableMessageHistory(boolean enableMessageHistory) {
+ this.enableMessageHistory = enableMessageHistory;
+ }
+
+ public boolean isEnableExchangeEventNotifier() {
+ return enableExchangeEventNotifier;
+ }
+
+ public void setEnableExchangeEventNotifier(boolean enableExchangeEventNotifier) {
+ this.enableExchangeEventNotifier = enableExchangeEventNotifier;
+ }
+
+ public boolean isEnableRouteEventNotifier() {
+ return enableRouteEventNotifier;
+ }
+
+ public void setEnableRouteEventNotifier(boolean enableRouteEventNotifier) {
+ this.enableRouteEventNotifier = enableRouteEventNotifier;
+ }
+}
diff --git a/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories b/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories
index 6e4a81d9954..c84e6558f15 100644
--- a/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories
+++ b/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories
@@ -17,5 +17,6 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.camel.component.micrometer.springboot.MicrometerComponentAutoConfiguration,\
-org.apache.camel.component.micrometer.springboot.MicrometerComponentConverter
+org.apache.camel.component.micrometer.springboot.MicrometerComponentConverter,\
+org.apache.camel.component.micrometer.springboot.CamelMicrometerConfiguration