This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch filter-kamelet2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 945206522767a151b465663e5dceab4a3a3e0714 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Feb 24 20:28:08 2024 +0100 CAMEL-18858: camel-core - Mark route as created by Kamelet so we know this, so we can filter out in tooling and whereelse (kamelet is a blackbox) --- .../metrics/routepolicy/MetricsRoutePolicy.java | 24 +++++++++++++++++----- .../ROOT/pages/camel-4x-upgrade-guide-4_5.adoc | 8 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java index f278fba42c9..17cacae8441 100644 --- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java +++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java @@ -26,6 +26,7 @@ import org.apache.camel.Exchange; import org.apache.camel.NonManagedService; import org.apache.camel.Route; import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.ManagementStrategy; import org.apache.camel.support.RoutePolicySupport; /** @@ -50,6 +51,8 @@ public class MetricsRoutePolicy extends RoutePolicySupport implements NonManaged private MetricsStatistics statistics; private Route route; private String namePattern = String.format("%s.%s.%s", NAME_TOKEN, ROUTE_ID_TOKEN, TYPE_TOKEN); + boolean registerKamelets; + boolean registerTemplates = true; private static final class MetricsStatistics { private final String routeId; @@ -139,6 +142,12 @@ public class MetricsRoutePolicy extends RoutePolicySupport implements NonManaged public void onInit(Route route) { super.onInit(route); + ManagementStrategy ms = route.getCamelContext().getManagementStrategy(); + if (ms != null && ms.getManagementAgent() != null) { + registerKamelets = ms.getManagementAgent().getRegisterRoutesCreateByKamelet(); + registerTemplates = ms.getManagementAgent().getRegisterRoutesCreateByTemplate(); + } + this.route = route; try { registryService = route.getCamelContext().hasService(MetricsRegistryService.class); @@ -156,11 +165,16 @@ public class MetricsRoutePolicy extends RoutePolicySupport implements NonManaged throw RuntimeCamelException.wrapRuntimeCamelException(e); } - // create statistics holder - // for know we record only all the timings of a complete exchange (responses) - // we have in-flight / total statistics already from camel-core - Timer responses = registryService.getMetricsRegistry().timer(createName("responses")); - statistics = new MetricsStatistics(route, responses); + // skip routes that should not be included + boolean skip = (route.isCreatedByKamelet() && !registerKamelets) + || (route.isCreatedByRouteTemplate() && !registerTemplates); + if (!skip) { + // create statistics holder + // for know we record only all the timings of a complete exchange (responses) + // we have in-flight / total statistics already from camel-core + Timer responses = registryService.getMetricsRegistry().timer(createName("responses")); + statistics = new MetricsStatistics(route, responses); + } } private String createName(String type) { diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_5.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_5.adoc index 17cf601e50c..379f81d2370 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_5.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_5.adoc @@ -39,3 +39,11 @@ listed from JMX will no longer include Kamelet routes. The old behaviour can be enabled by setting `registerRoutesCreateByKamelet=true` on the `ManagementAgent` object. See more in the xref:jmx.adoc[JMX] documentation. + +=== camel-micrometer and camel-metrics + +Due to Kamelets are changed to act more like a Camel component, and not expose internal details as JMX MBeans, then +micrometer and metrics no longer include statistics for those Kamelet routes. + +The old behaviour can be enabled by setting `registerRoutesCreateByKamelet=true` +on the `ManagementAgent` object. See more in the xref:jmx.adoc[JMX] documentation.