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

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new e8488b0  Auto configuration of metrics management strategies
     new b01d972  Merge pull request #205 from 
jamesnetherton/195-metrics-autoconfig
e8488b0 is described below

commit e8488b0c38381cf9ef512c3bab10377b679da77b
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Thu Sep 19 12:25:39 2019 +0100

    Auto configuration of metrics management strategies
    
    fixes #195
---
 .../deployment/MicroProfileMetricsProcessor.java   |  8 ++++
 .../runtime/CamelMicroProfileMetricsConfig.java    | 56 ++++++++++++++++++++++
 .../runtime/CamelMicroProfileMetricsRecorder.java  | 29 +++++++++++
 .../it/MicroProfileMetricsRouteBuilder.java        | 10 ----
 .../src/main/resources/application.properties      |  2 +-
 5 files changed, 94 insertions(+), 11 deletions(-)

diff --git 
a/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java
 
b/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java
index 95f3f06..53c9d75 100644
--- 
a/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java
+++ 
b/extensions/microprofile-metrics/deployment/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/deployment/MicroProfileMetricsProcessor.java
@@ -16,11 +16,13 @@
  */
 package org.apache.camel.quarkus.component.microprofile.metrics.deployment;
 
+import io.quarkus.arc.deployment.BeanContainerBuildItem;
 import io.quarkus.deployment.annotations.BuildStep;
 import io.quarkus.deployment.annotations.ExecutionTime;
 import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
 
+import 
org.apache.camel.quarkus.component.microprofile.metrics.runtime.CamelMicroProfileMetricsConfig;
 import 
org.apache.camel.quarkus.component.microprofile.metrics.runtime.CamelMicroProfileMetricsRecorder;
 import org.apache.camel.quarkus.core.deployment.CamelRegistryBuildItem;
 import org.eclipse.microprofile.metrics.MetricRegistry;
@@ -44,4 +46,10 @@ class MicroProfileMetricsProcessor {
             recorder.createApplicationRegistry()
         );
     }
+
+    @Record(ExecutionTime.RUNTIME_INIT)
+    @BuildStep
+    public void configureCamelContext(CamelMicroProfileMetricsRecorder 
recorder, CamelMicroProfileMetricsConfig config, BeanContainerBuildItem 
beanContainer) {
+        recorder.configureCamelContext(config, beanContainer.getValue());
+    }
 }
diff --git 
a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsConfig.java
 
b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsConfig.java
new file mode 100644
index 0000000..6a5c06c
--- /dev/null
+++ 
b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsConfig.java
@@ -0,0 +1,56 @@
+/*
+ * 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.quarkus.component.microprofile.metrics.runtime;
+
+import io.quarkus.runtime.annotations.ConfigItem;
+import io.quarkus.runtime.annotations.ConfigPhase;
+import io.quarkus.runtime.annotations.ConfigRoot;
+
+@ConfigRoot(name = "camel.metrics", phase = 
ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
+public final class CamelMicroProfileMetricsConfig {
+
+    /**
+     * Set whether to enable the MicroProfileMetricsRoutePolicyFactory for 
capturing metrics
+     * on route processing times.
+     */
+    @ConfigItem(defaultValue = "true")
+    public boolean enableRoutePolicy;
+
+    /**
+     * Set whether to enable the MicroProfileMetricsMessageHistoryFactory 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.
+     */
+    @ConfigItem(defaultValue = "false")
+    public boolean enableMessageHistory;
+
+    /**
+     * Set whether to enable the MicroProfileMetricsExchangeEventNotifier for 
capturing metrics
+     * on exchange processing times.
+     */
+    @ConfigItem(defaultValue = "true")
+    public boolean enableExchangeEventNotifier;
+
+    /**
+     * Set whether to enable the MicroProfileMetricsRouteEventNotifier for 
capturing metrics
+     * on the total number of routes and total number of routes running.
+     */
+    @ConfigItem(defaultValue = "true")
+    public boolean enableRouteEventNotifier;
+}
diff --git 
a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java
 
b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java
index 8e4576e..5ad76e5 100644
--- 
a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java
+++ 
b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java
@@ -16,9 +16,16 @@
  */
 package org.apache.camel.quarkus.component.microprofile.metrics.runtime;
 
+import io.quarkus.arc.runtime.BeanContainer;
 import io.quarkus.runtime.annotations.Recorder;
 import io.smallrye.metrics.MetricRegistries;
 
+import org.apache.camel.CamelContext;
+import 
org.apache.camel.component.microprofile.metrics.event.notifier.exchange.MicroProfileMetricsExchangeEventNotifier;
+import 
org.apache.camel.component.microprofile.metrics.event.notifier.route.MicroProfileMetricsRouteEventNotifier;
+import 
org.apache.camel.component.microprofile.metrics.message.history.MicroProfileMetricsMessageHistoryFactory;
+import 
org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyFactory;
+import org.apache.camel.spi.ManagementStrategy;
 import org.eclipse.microprofile.metrics.MetricRegistry;
 
 @Recorder
@@ -27,4 +34,26 @@ public class CamelMicroProfileMetricsRecorder {
     public MetricRegistry createApplicationRegistry() {
         return MetricRegistries.get(MetricRegistry.Type.APPLICATION);
     }
+
+    public void configureCamelContext(CamelMicroProfileMetricsConfig config, 
BeanContainer beanContainer) {
+        CamelContext camelContext = beanContainer.instance(CamelContext.class);
+        ManagementStrategy managementStrategy = 
camelContext.getManagementStrategy();
+
+        if (config.enableRoutePolicy) {
+            camelContext.addRoutePolicyFactory(new 
MicroProfileMetricsRoutePolicyFactory());
+        }
+
+        if (config.enableMessageHistory) {
+            camelContext.setMessageHistory(true);
+            camelContext.setMessageHistoryFactory(new 
MicroProfileMetricsMessageHistoryFactory());
+        }
+
+        if (config.enableExchangeEventNotifier) {
+            managementStrategy.addEventNotifier(new 
MicroProfileMetricsExchangeEventNotifier());
+        }
+
+        if (config.enableRouteEventNotifier) {
+            managementStrategy.addEventNotifier(new 
MicroProfileMetricsRouteEventNotifier());
+        }
+    }
 }
diff --git 
a/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsRouteBuilder.java
 
b/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsRouteBuilder.java
index 9819415..e3d76fd 100644
--- 
a/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsRouteBuilder.java
+++ 
b/integration-tests/microprofile-metrics/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/it/MicroProfileMetricsRouteBuilder.java
@@ -17,22 +17,12 @@
 package org.apache.camel.quarkus.component.microprofile.metrics.it;
 
 import org.apache.camel.builder.RouteBuilder;
-import 
org.apache.camel.component.microprofile.metrics.event.notifier.exchange.MicroProfileMetricsExchangeEventNotifier;
-import 
org.apache.camel.component.microprofile.metrics.event.notifier.route.MicroProfileMetricsRouteEventNotifier;
-import 
org.apache.camel.component.microprofile.metrics.message.history.MicroProfileMetricsMessageHistoryFactory;
-import 
org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyFactory;
 import static 
org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.HEADER_HISTOGRAM_VALUE;
 import static 
org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.HEADER_METER_MARK;
 
 public class MicroProfileMetricsRouteBuilder extends RouteBuilder {
     @Override
     public void configure() {
-        // Configure (optional) factories & event notifiers
-        getContext().addRoutePolicyFactory(new 
MicroProfileMetricsRoutePolicyFactory());
-        getContext().setMessageHistoryFactory(new 
MicroProfileMetricsMessageHistoryFactory());
-        getContext().getManagementStrategy().addEventNotifier(new 
MicroProfileMetricsExchangeEventNotifier());
-        getContext().getManagementStrategy().addEventNotifier(new 
MicroProfileMetricsRouteEventNotifier());
-
         from("direct:counter")
             .to("microprofile-metrics:counter:camel-quarkus-counter");
 
diff --git 
a/integration-tests/microprofile-metrics/src/main/resources/application.properties
 
b/integration-tests/microprofile-metrics/src/main/resources/application.properties
index 35419b3..430f808 100644
--- 
a/integration-tests/microprofile-metrics/src/main/resources/application.properties
+++ 
b/integration-tests/microprofile-metrics/src/main/resources/application.properties
@@ -19,4 +19,4 @@
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.context.messageHistory = true
+quarkus.camel.metrics.enable-message-history = true

Reply via email to