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.git
commit 2e437b7e79b797193a78b5c263e6d3ca8ff40007 Author: Christian Ohr <christian....@gmail.com> AuthorDate: Wed May 16 12:48:19 2018 +0200 CAMEL-11600:fix some issues with distribution config --- .../src/main/docs/metrics-component.adoc | 4 +- .../camel/component/metrics/MetricsTypeTest.java | 35 ---- .../src/main/docs/micrometer-component.adoc | 65 ++++--- .../micrometer/AbstractMicrometerProducer.java | 5 +- .../DistributionStatisticConfigFilter.java | 122 +++++++++++-- .../camel/component/micrometer/MetricsType.java | 55 ------ .../component/micrometer/MicrometerComponent.java | 25 +-- .../component/micrometer/MicrometerConstants.java | 7 + .../component/micrometer/MicrometerEndpoint.java | 13 +- .../component/micrometer/MicrometerUtils.java | 26 ++- .../AbstractMicrometerEventNotifier.java | 7 - .../MicrometerExchangeEventNotifier.java | 54 ++---- ...rometerExchangeEventNotifierNamingStrategy.java | 25 ++- .../MicrometerRouteEventNotifier.java | 28 +-- ...MicrometerRouteEventNotifierNamingStrategy.java | 54 ++++++ .../messagehistory/MicrometerMessageHistory.java | 10 +- .../MicrometerMessageHistoryNamingStrategy.java | 17 ++ .../routepolicy/MicrometerRoutePolicy.java | 11 +- .../MicrometerRoutePolicyNamingStrategy.java | 21 ++- .../component/micrometer/CounterEndpointTest.java | 3 +- .../DistributionSummaryEndpointTest.java | 3 +- .../component/micrometer/MetricsTypeTest.java | 33 ---- .../micrometer/MicrometerComponentTest.java | 19 +- .../micrometer/MicrometerEndpointTest.java | 3 +- .../component/micrometer/TimerEndpointTest.java | 3 +- .../AbstractMicrometerEventNotifierTest.java | 3 +- .../MicrometerExchangeEventNotifierTest.java | 10 +- .../MicrometerRouteEventNotifierTest.java | 7 +- ...ExceptionRouteMicrometerMessageHistoryTest.java | 2 - .../ManagedMicrometerRoutePolicyTest.java | 3 - examples/camel-example-micrometer/README.md | 7 +- .../camel-example-micrometer/src/data/message1.xml | 24 --- .../camel-example-micrometer/src/data/message2.xml | 24 --- .../example/micrometer/CamelPrometheusExample.java | 42 +++-- .../example/micrometer/ScheduledRouteBuilder.java | 13 +- .../example/micrometer/ScrapeRouteBuilder.java | 14 +- .../camel/example/micrometer/IntegrationTest.java | 5 +- .../camel-micrometer-starter/pom.xml | 53 ++++++ .../MicrometerComponentAutoConfiguration.java | 128 +++++++++++++ .../MicrometerComponentConfiguration.java | 65 +++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 ++ .../src/main/resources/META-INF/spring.factories | 19 ++ .../src/main/resources/META-INF/spring.provides | 17 ++ platforms/spring-boot/components-starter/pom.xml | 1 + 45 files changed, 908 insertions(+), 391 deletions(-) diff --git a/components/camel-metrics/src/main/docs/metrics-component.adoc b/components/camel-metrics/src/main/docs/metrics-component.adoc index bbc994b..71354cd 100644 --- a/components/camel-metrics/src/main/docs/metrics-component.adoc +++ b/components/camel-metrics/src/main/docs/metrics-component.adoc @@ -500,7 +500,7 @@ following options: |Name |Default |Description |useJmx |false |Whether to report fine grained statistics to JMX by using the `com.codahale.metrics.JmxReporter`. + -Notice that if JMX is enabled on CamelContext +Notice that if JMX is percentileHistogramEnabled on CamelContext then a `MetricsRegistryService` mbean is enlisted under the services type in the JMX tree. That mbean has a single operation to output the statistics using json. Setting `useJmx` to true is only needed if you @@ -576,7 +576,7 @@ The following options is supported on the factory: |Name |Default |Description |useJmx |false |Whether to report fine grained statistics to JMX by using the `com.codahale.metrics.JmxReporter`. + -Notice that if JMX is enabled on CamelContext +Notice that if JMX is percentileHistogramEnabled on CamelContext then a `MetricsRegistryService` mbean is enlisted under the services type in the JMX tree. That mbean has a single operation to output the statistics using json. Setting `useJmx` to true is only needed if you diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java deleted file mode 100644 index 2e77114..0000000 --- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsTypeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.metrics; - -import java.util.EnumSet; - -import org.junit.Test; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -public class MetricsTypeTest { - - @Test - public void testGetByName() throws Exception { - for (MetricsType type : EnumSet.allOf(MetricsType.class)) { - MetricsType t = MetricsType.getByName(type.toString()); - assertThat(t, is(type)); - } - } -} diff --git a/components/camel-micrometer/src/main/docs/micrometer-component.adoc b/components/camel-micrometer/src/main/docs/micrometer-component.adoc index 17d8293..f30ef12 100644 --- a/components/camel-micrometer/src/main/docs/micrometer-component.adoc +++ b/components/camel-micrometer/src/main/docs/micrometer-component.adoc @@ -23,7 +23,7 @@ collecting and visualizing statistics. The component also provides a `MicrometerRoutePolicyFactory` which allows to expose route statistics using Micrometer as well as `EventNotifier` implementations for counting -routes and timing Exchanges. +routes and timing exchanges from their creation to their completion. Maven users need to add the following dependency to their `pom.xml` for this component: @@ -76,7 +76,7 @@ with the following path and query parameters: [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type -| *metricsType* | *Required* Type of metrics | | MetricsType +| *metricsType* | *Required* Type of metrics | | Type | *metricsName* | *Required* Name of metrics | | String | *tags* | Tags of metrics | | Tag> |=== @@ -100,10 +100,11 @@ with the following path and query parameters: ### [[MicrometerComponent-registry]]Meter Registry -By default the Camel Micrometer component creates a `SimpleMeterRegistry` instance. -This default registry, however, should be replaced with a custom one by providing -a `MeterRegistry` bean. MeterRegistries primarily determine the backend monitoring system -in use. A CompositeMeterRegistry can be used to address more than one monitoring target. +By default the Camel Micrometer component creates a `SimpleMeterRegistry` instance, suitable +mainly for testing. +You should define a dedicated registry by providing +a `MeterRegistry` bean. Micrometer registries primarily determine the backend monitoring system +to be used. A `CompositeMeterRegistry` can be used to address more than one monitoring target. For example using Spring Java Configuration: @@ -174,8 +175,8 @@ E.g. the URI parameter `tags=X=${header.Y}` would assign the current value of he #### Headers -The meter name defined in URI can be overridden by using a header with name `CamelMetricsName`. -The meter tags defined as URI parameters can be augmented by using a header with name `CamelMetricsTags`. +The meter name defined in URI can be overridden by populating a header with name `CamelMetricsName`. +The meter tags defined as URI parameters can be augmented by populating a header with name `CamelMetricsTags`. For example @@ -184,16 +185,15 @@ For example from("direct:in") .setHeader(MicrometerConstants.HEADER_METRIC_NAME, constant("new.name")) .setHeader(MicrometerConstants.HEADER_METRIC_TAGS, constant(Tags.of("dynamic-key", "dynamic-value"))) - .to("metrics:counter:name.not.used?tags=static-key=static-value") + .to("metrics:counter:name.not.used?tags=key=value") .to("direct:out"); ---- will update a counter with name `new.name` instead of `name.not.used` using the -tag `dynamic-key` with value `dynamic-value` in addition to the tag `static-key` with value `static-value`. +tag `dynamic-key` with value `dynamic-value` in addition to the tag `key` with value `value`. All Metrics specific headers are removed from the message once the Micrometer endpoint finishes processing of exchange. While processing exchange -Micrometer endpoint will catch all exceptions and write log entry using -level `warn`. +Micrometer endpoint will catch all exceptions and write log entry using level `warn`. ### [[MicrometerComponent-counter]]Counter @@ -314,7 +314,6 @@ if header `X` contains a value that evaluates to 3.0, this value is registered w [source,java] ---- -// nothing is added to simple.histogram; warning is logged from("direct:in") .to("micrometer:summary:simple.histogram?value=${header.X}") .to("direct:out"); @@ -365,7 +364,7 @@ and warning is logged. [source,java] ---- -// measure time taken by route "calculate" +// measure time spent in route "direct:calculate" from("direct:in") .to("micrometer:timer:simple.timer?action=start") .to("direct:calculate") @@ -402,12 +401,12 @@ from("direct:in") ### MicrometerRoutePolicyFactory This factory allows to add a RoutePolicy for each -route which exposes route utilization statistics using Micrometer. +route in order to exposes route utilization statistics using Micrometer. This factory can be used in Java and XML as the examples below demonstrates. -NOTE: Instead of using the MicrometerRoutePolicyFactory you can define a -MicrometerRoutePolicy per route you want to instrument, in case you only +NOTE: Instead of using the `MicrometerRoutePolicyFactory` you can define a +dedicated `MicrometerRoutePolicy` per route you want to instrument, in case you only want to instrument a few selected routes. From Java you just add the factory to the `CamelContext` as shown below: @@ -421,7 +420,7 @@ And from XML DSL you define a <bean> as follows: [source,xml] ---- - <!-- use camel-metrics route policy to gather metrics for all routes --> + <!-- use camel-micrometer route policy to gather metrics for all routes --> <bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory"/> ---- @@ -431,22 +430,19 @@ following options: [width="100%",cols="10%,10%,80%",options="header",] |======================================================================= |Name |Default |Description -|prettyPrint |false |Whether to use pretty print when outputting -statistics in json format -|meterRegistry | |Allow to use a shared `MeterRegistry`. If none is provided then Camel -will create a shared instance used by the this CamelContext. +|prettyPrint |false |Whether to use pretty print when outputting statistics in json format +|meterRegistry | |Allow to use a shared `MeterRegistry`. If none is provided then Camel will create a shared instance used by the this CamelContext. |durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration in when dumping the statistics as json. |======================================================================= -If JMX is enabled in the CamelContext, the MBean is registered in the `type=services` tree +If JMX is percentileHistogramEnabled in the CamelContext, the MBean is registered in the `type=services` tree with `name=MicrometerRoutePolicy`. ### MicrometerMessageHistoryFactory -This factory allows to use metrics to -capture Message History performance -statistics while routing messages. It works by using a metrics Timer for +This factory allows to use metrics to capture Message History performance +statistics while routing messages. It works by using a Micrometer Timer for each node in all the routes. This factory can be used in Java and XML as the examples below demonstrates. @@ -461,7 +457,7 @@ And from XML DSL you define a <bean> as follows: [source,xml] ---- - <!-- use camel-metrics message history to gather metrics for all messages being routed --> + <!-- use camel-micrometer message history to gather metrics for all messages being routed --> <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory"/> ---- @@ -470,11 +466,8 @@ The following options is supported on the factory: [width="100%",cols="10%,10%,80%",options="header",] |======================================================================= |Name |Default |Description -|prettyPrint |false |Whether to use pretty print when outputting -statistics in json format -|meterRegistry | |Allow to use a shared -`MeterRegistry`. If none is provided then Camel -will create a shared instance used by the this CamelContext. +|prettyPrint |false |Whether to use pretty print when outputting statistics in json format +|meterRegistry | |Allow to use a shared `MeterRegistry`. If none is provided then Camel will create a shared instance used by the this CamelContext. |durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration when dumping the statistics as json. |======================================================================= @@ -490,7 +483,7 @@ MicrometerMessageHistoryService service = context.hasService(MicrometerMessageHi String json = service.dumpStatisticsAsJson(); ---- -If JMX is enabled in the CamelContext, the MBean is registered in the `type=services` tree +If JMX is percentileHistogramEnabled in the CamelContext, the MBean is registered in the `type=services` tree with `name=MicrometerMessageHistory`. @@ -518,7 +511,7 @@ MicrometerEventNotifierService service = context.hasService(MicrometerEventNotif String json = service.dumpStatisticsAsJson(); ---- -If JMX is enabled in the CamelContext, the MBean is registered in the `type=services` tree +If JMX is percentileHistogramEnabled in the CamelContext, the MBean is registered in the `type=services` tree with `name=MicrometerEventNotifier`. @@ -567,3 +560,7 @@ and add a `JmxMeterRegistry` instance: The `HierarchicalNameMapper` strategy determines how meter name and tags are assembled into an MBean name. +### Example + +`camel-example-micrometer` provides an example how to set up Micrometer monitoring with +Camel using String Java configuration and a Prometheus backend. diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/AbstractMicrometerProducer.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/AbstractMicrometerProducer.java index e21beb3..2579ae4 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/AbstractMicrometerProducer.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/AbstractMicrometerProducer.java @@ -59,7 +59,8 @@ public abstract class AbstractMicrometerProducer<T extends Meter> extends Defaul simple(exchange, tag.getKey(), String.class), simple(exchange, tag.getValue(), String.class))) .reduce(Tags.empty(), Tags::and, Tags::and) - .and(Tags.of(CAMEL_CONTEXT_TAG, getEndpoint().getCamelContext().getName())); + .and(Tags.of( + CAMEL_CONTEXT_TAG, getEndpoint().getCamelContext().getName())); try { doProcess(exchange, finalMetricsName, finalTags); } catch (Exception e) { @@ -82,7 +83,7 @@ public abstract class AbstractMicrometerProducer<T extends Meter> extends Defaul protected abstract void doProcess(Exchange exchange, MicrometerEndpoint endpoint, T meter); - protected <T> T simple(Exchange exchange, String expression, Class<T> clazz) { + protected <C> C simple(Exchange exchange, String expression, Class<C> clazz) { if (expression != null) { Expression simple = SimpleLanguage.simple(expression); if (simple != null) { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionStatisticConfigFilter.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionStatisticConfigFilter.java index 4d5f9da..f95861d 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionStatisticConfigFilter.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionStatisticConfigFilter.java @@ -17,13 +17,15 @@ package org.apache.camel.component.micrometer; import java.time.Duration; +import java.util.function.Predicate; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; +import static org.apache.camel.component.micrometer.MicrometerConstants.ALWAYS; +import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_METERS; /** - * Example filter for adding common distribution statistics for all Timers and Distribution - * Summaries. + * Filter for adding distribution statistics to Timers and Distribution Summaries. * Configure and add this to the {@link io.micrometer.core.instrument.MeterRegistry} * if desired: * @@ -35,20 +37,23 @@ import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; */ public class DistributionStatisticConfigFilter implements MeterFilter { + private Predicate<Meter.Id> appliesTo = ALWAYS; private Long maximumExpectedValue; private Long minimumExpectedValue; - private Boolean enabled; + private Boolean publishPercentileHistogram = true; + private Integer percentilePrecision; private Integer bufferLength; private Duration expiry; - private double[] percentiles = new double[] {0.5D, 0.75D, 0.9D, 0.99D, 0.999D }; + private double[] percentiles; private long[] slas; @Override public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { - if (id.getTag(MicrometerConstants.CAMEL_CONTEXT_TAG) != null) { + if (CAMEL_METERS.and(appliesTo).test(id)) { return DistributionStatisticConfig.builder() - .percentilesHistogram(enabled) + .percentilesHistogram(publishPercentileHistogram) .percentiles(percentiles) + .percentilePrecision(percentilePrecision) .maximumExpectedValue(maximumExpectedValue) .minimumExpectedValue(minimumExpectedValue) .sla(slas) @@ -60,31 +65,120 @@ public class DistributionStatisticConfigFilter implements MeterFilter { return config; } - public void setMaximumExpectedValue(Long maximumExpectedValue) { + /** + * Restrict a condition under which this config applies to a Camel meter + * + * @param appliesTo predicate that must return true so that this config applies + */ + public DistributionStatisticConfigFilter andAppliesTo(Predicate<Meter.Id> appliesTo) { + this.appliesTo = this.appliesTo.and(appliesTo); + return this; + } + + /** + * Add a condition under which this config applies to a Camel meter + * + * @param appliesTo predicate that must return true so that this config applies + */ + public DistributionStatisticConfigFilter orAppliesTo(Predicate<Meter.Id> appliesTo) { + this.appliesTo = this.appliesTo.or(appliesTo); + return this; + } + + /** + * Sets the maximum expected value for a distribution summary value. + * Controls the number of buckets shipped by publishPercentileHistogram as well as controlling the + * accuracy and memory footprint of the underlying HdrHistogram structure. + * + * @param maximumExpectedValue the maximum expected value for a distribution summary value + */ + public DistributionStatisticConfigFilter setMaximumExpectedValue(Long maximumExpectedValue) { this.maximumExpectedValue = maximumExpectedValue; + return this; } - public void setMinimumExpectedValue(Long minimumExpectedValue) { + /** + * Sets the minimum expected value for a distribution summary value. + * Controls the number of buckets shipped by publishPercentileHistogram as well as controlling the + * accuracy and memory footprint of the underlying HdrHistogram structure. + * + * @param minimumExpectedValue the minimum expected value for a distribution summary value + */ + public DistributionStatisticConfigFilter setMinimumExpectedValue(Long minimumExpectedValue) { this.minimumExpectedValue = minimumExpectedValue; + return this; + } + + /** + * Sets the maximum expected duration for a timer value + * Controls the number of buckets shipped by publishPercentileHistogram as well as controlling the + * accuracy and memory footprint of the underlying HdrHistogram structure. + * + * @param maximumExpectedDuration the maximum expected duration for a timer value + */ + public DistributionStatisticConfigFilter setMaximumExpectedDuration(Duration maximumExpectedDuration) { + this.maximumExpectedValue = maximumExpectedDuration.toNanos(); + return this; + } + + /** + * Sets the minimum expected duration for a timer value + * Controls the number of buckets shipped by publishPercentileHistogram as well as controlling the + * accuracy and memory footprint of the underlying HdrHistogram structure. + * + * @param minimumExpectedDuration the minimum expected duration for a timer value + */ + public DistributionStatisticConfigFilter setMinimumExpectedDuration(Duration minimumExpectedDuration) { + this.minimumExpectedValue = minimumExpectedDuration.toNanos(); + return this; } - public void setEnabled(Boolean enabled) { - this.enabled = enabled; + /** + * Whether to publish aggregatable percentile approximations for Prometheus or Atlas. + * Has no effect on systems that do not support aggregatable percentile approximations. + * This defaults to true. + * + * @param publishPercentileHistogram Whether to publish aggregatable percentile approximations. + */ + public DistributionStatisticConfigFilter setPublishPercentileHistogram(Boolean publishPercentileHistogram) { + this.publishPercentileHistogram = publishPercentileHistogram; + return this; } - public void setBufferLength(Integer bufferLength) { + public DistributionStatisticConfigFilter setBufferLength(Integer bufferLength) { this.bufferLength = bufferLength; + return this; } - public void setExpiry(Duration expiry) { + public DistributionStatisticConfigFilter setExpiry(Duration expiry) { this.expiry = expiry; + return this; } - public void setPercentiles(double[] percentiles) { + /** + * Calculate and publish percentile values. These values are non-aggregatable across dimensions. + * + * @param percentiles array of percentiles to be published + */ + public DistributionStatisticConfigFilter setPercentiles(double[] percentiles) { this.percentiles = percentiles; + return this; + } + + public DistributionStatisticConfigFilter setPercentilePrecision(Integer percentilePrecision) { + this.percentilePrecision = percentilePrecision; + return this; } - public void setSlas(long[] slas) { + /** + * Publish a cumulative histogram with buckets defined by your SLAs. Used together with publishPercentileHistogram + * on a monitoring system that supports aggregatable percentiles, this setting adds additional buckets to the published histogram. + * Used on a system that does not support aggregatable percentiles, this setting causes a histogram to be published with only these buckets. + * + * @param slas array of percentiles to be published + */ + public DistributionStatisticConfigFilter setSlas(long[] slas) { this.slas = slas; + return this; } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MetricsType.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MetricsType.java deleted file mode 100644 index af9303d..0000000 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MetricsType.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public enum MetricsType { - - GAUGE("gauge"), - COUNTER("counter"), - FUNCTION_COUNTER("functionCounter"), - TIMER("timer"), - FUNCTION_TIMER("functionTimer"), - LONG_TASK_TIMER("longTaskTimer"), - DISTRIBUTION_SUMMARY("summary"); - - private static final Map<String, MetricsType> MAP = new HashMap<>(); - - private final String name; - - static { - for (MetricsType type : EnumSet.allOf(MetricsType.class)) { - MAP.put(type.name, type); - } - } - - MetricsType(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - - public static MetricsType getByName(String name) { - return MAP.get(name); - } -} diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerComponent.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerComponent.java index 0138e5b..99b3975 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerComponent.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerComponent.java @@ -17,14 +17,12 @@ package org.apache.camel.component.micrometer; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.Endpoint; -import org.apache.camel.RuntimeCamelException; import org.apache.camel.impl.UriEndpointComponent; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.Registry; @@ -37,7 +35,7 @@ import org.slf4j.LoggerFactory; */ public class MicrometerComponent extends UriEndpointComponent { - public static final MetricsType DEFAULT_METER_TYPE = MetricsType.COUNTER; + public static final Meter.Type DEFAULT_METER_TYPE = Meter.Type.COUNTER; private static final Logger LOG = LoggerFactory.getLogger(MicrometerComponent.class); @@ -55,7 +53,7 @@ public class MicrometerComponent extends UriEndpointComponent { metricsRegistry = MicrometerUtils.getOrCreateMeterRegistry(camelRegistry, MicrometerConstants.METRICS_REGISTRY_NAME); } String metricsName = getMetricsName(remaining); - MetricsType metricsType = getMetricsType(remaining); + Meter.Type metricsType = getMetricsType(remaining); Iterable<Tag> tags = getMetricsTag(parameters); LOG.debug("Metrics type: {}; name: {}; tags: {}", metricsType, metricsName, tags); @@ -69,18 +67,11 @@ public class MicrometerComponent extends UriEndpointComponent { return name == null ? remaining : name; } - MetricsType getMetricsType(String remaining) { - String name = StringHelper.before(remaining, ":"); - MetricsType type; - if (name == null) { - type = DEFAULT_METER_TYPE; - } else { - type = MetricsType.getByName(name); - } - if (type == null) { - throw new RuntimeCamelException("Unknown meter type \"" + name + "\""); - } - return type; + Meter.Type getMetricsType(String remaining) { + String type = StringHelper.before(remaining, ":"); + return type == null + ? DEFAULT_METER_TYPE + : MicrometerUtils.getByName(type); } Iterable<Tag> getMetricsTag(Map<String, Object> parameters) { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java index 845cb44..5e0d1e4 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerConstants.java @@ -16,6 +16,9 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Predicate; +import io.micrometer.core.instrument.Meter; + public final class MicrometerConstants { public static final String HEADER_PREFIX = "CamelMetrics"; @@ -42,6 +45,10 @@ public final class MicrometerConstants { public static final String SERVICE_NAME = "serviceName"; public static final String ENDPOINT_NAME = "endpointName"; + public static final Predicate<Meter.Id> CAMEL_METERS = id -> id.getTag(CAMEL_CONTEXT_TAG) != null; + public static final Predicate<Meter.Id> TIMERS = id -> id.getType() == Meter.Type.TIMER; + public static final Predicate<Meter.Id> DISTRIBUTION_SUMMARIES = id -> id.getType() == Meter.Type.DISTRIBUTION_SUMMARY; + public static final Predicate<Meter.Id> ALWAYS = id -> true; private MicrometerConstants() { } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerEndpoint.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerEndpoint.java index e1303fa..077f506 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerEndpoint.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerEndpoint.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import org.apache.camel.Component; @@ -39,7 +40,7 @@ public class MicrometerEndpoint extends DefaultEndpoint { @UriPath(description = "Type of metrics") @Metadata(required = "true") - protected final MetricsType metricsType; + protected final Meter.Type metricsType; @UriPath(description = "Name of metrics") @Metadata(required = "true") protected final String metricsName; @@ -54,7 +55,7 @@ public class MicrometerEndpoint extends DefaultEndpoint { @UriParam(description = "Decrement value expression when using counter type") private String decrement; - public MicrometerEndpoint(String uri, Component component, MeterRegistry registry, MetricsType metricsType, String metricsName, Iterable<Tag> tags) { + public MicrometerEndpoint(String uri, Component component, MeterRegistry registry, Meter.Type metricsType, String metricsName, Iterable<Tag> tags) { super(uri, component); this.registry = registry; this.metricsType = metricsType; @@ -69,11 +70,11 @@ public class MicrometerEndpoint extends DefaultEndpoint { @Override public Producer createProducer() { - if (metricsType == MetricsType.COUNTER) { + if (metricsType == Meter.Type.COUNTER) { return new CounterProducer(this); - } else if (metricsType == MetricsType.DISTRIBUTION_SUMMARY) { + } else if (metricsType == Meter.Type.DISTRIBUTION_SUMMARY) { return new DistributionSummaryProducer(this); - } else if (metricsType == MetricsType.TIMER) { + } else if (metricsType == Meter.Type.TIMER) { return new TimerProducer(this); } else { throw new IllegalArgumentException("Metrics type " + metricsType + " is not supported"); @@ -97,7 +98,7 @@ public class MicrometerEndpoint extends DefaultEndpoint { return tags; } - public MetricsType getMetricsType() { + public Meter.Type getMetricsType() { return metricsType; } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerUtils.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerUtils.java index ccb129d3..c911333 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerUtils.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerUtils.java @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -6,21 +6,21 @@ * (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 + * 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; import java.util.Set; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.Registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +29,24 @@ public abstract class MicrometerUtils { private static final Logger LOG = LoggerFactory.getLogger(MicrometerUtils.class); + public static Meter.Type getByName(String meterName) { + switch (meterName) { + case "summary": return Meter.Type.DISTRIBUTION_SUMMARY; + case "counter": return Meter.Type.COUNTER; + case "timer": return Meter.Type.TIMER; + default: throw new RuntimeCamelException("Unsupported meter type " + meterName); + } + } + + public static String getName(Meter.Type type) { + switch (type) { + case DISTRIBUTION_SUMMARY: return "summary"; + case COUNTER: return "counter"; + case TIMER: return "timer"; + default: throw new RuntimeCamelException("Unsupported meter type " + type); + } + } + public static MeterRegistry getOrCreateMeterRegistry(Registry camelRegistry, String registryName) { LOG.debug("Looking up MeterRegistry from Camel Registry for name \"{}\"", registryName); MeterRegistry result = getMeterRegistryFromCamelRegistry(camelRegistry, registryName); diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/AbstractMicrometerEventNotifier.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/AbstractMicrometerEventNotifier.java index fcb89bb..c1e62a6 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/AbstractMicrometerEventNotifier.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/AbstractMicrometerEventNotifier.java @@ -105,13 +105,6 @@ public abstract class AbstractMicrometerEventNotifier<T extends EventObject> ext } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } - - - try { - - } catch (Exception e) { - throw ObjectHelper.wrapRuntimeCamelException(e); - } } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifier.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifier.java index 1f75221..a7a1158 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifier.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifier.java @@ -19,6 +19,7 @@ package org.apache.camel.component.micrometer.eventnotifier; import java.util.EventObject; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; +import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.Timer; import org.apache.camel.Exchange; import org.apache.camel.management.event.AbstractExchangeEvent; @@ -26,17 +27,11 @@ import org.apache.camel.management.event.ExchangeCompletedEvent; import org.apache.camel.management.event.ExchangeCreatedEvent; import org.apache.camel.management.event.ExchangeFailedEvent; import org.apache.camel.management.event.ExchangeSentEvent; -import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME; -import static org.apache.camel.component.micrometer.MicrometerConstants.ENDPOINT_NAME; -import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.FAILED_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; public class MicrometerExchangeEventNotifier extends AbstractMicrometerEventNotifier<AbstractExchangeEvent> { private Predicate<Exchange> ignoreExchanges = exchange -> false; - private MicrometerExchangeEventNotifierNamingStrategy namingStrategy = (exchange, endpoint) -> DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME; + private MicrometerExchangeEventNotifierNamingStrategy namingStrategy = MicrometerExchangeEventNotifierNamingStrategy.DEFAULT; public MicrometerExchangeEventNotifier() { super(AbstractExchangeEvent.class); @@ -59,35 +54,22 @@ public class MicrometerExchangeEventNotifier extends AbstractMicrometerEventNoti } @Override - public boolean isEnabled(EventObject eventObject) { - return super.isEnabled(eventObject) && !ignoreExchanges.test(((AbstractExchangeEvent) eventObject).getExchange()); - } - - @Override - protected void doStart() throws Exception { - super.doStart(); - } - - @Override public void notify(EventObject eventObject) { - if (eventObject instanceof ExchangeSentEvent) { - handleSentEvent((ExchangeSentEvent) eventObject); - } else if (eventObject instanceof ExchangeCreatedEvent) { - handleCreatedEvent((ExchangeCreatedEvent) eventObject); - } else if (eventObject instanceof ExchangeCompletedEvent || eventObject instanceof ExchangeFailedEvent) { - handleDoneEvent((AbstractExchangeEvent) eventObject); + if (!(getIgnoreExchanges().test(((AbstractExchangeEvent) eventObject).getExchange()))) { + if (eventObject instanceof ExchangeSentEvent) { + handleSentEvent((ExchangeSentEvent) eventObject); + } else if (eventObject instanceof ExchangeCreatedEvent) { + handleCreatedEvent((ExchangeCreatedEvent) eventObject); + } else if (eventObject instanceof ExchangeCompletedEvent || eventObject instanceof ExchangeFailedEvent) { + handleDoneEvent((AbstractExchangeEvent) eventObject); + } } } protected void handleSentEvent(ExchangeSentEvent sentEvent) { - Timer.builder(namingStrategy.getName(sentEvent.getExchange(), sentEvent.getEndpoint())) - .tag(CAMEL_CONTEXT_TAG, getCamelContext().getName()) - .tag(SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName()) - .tag(ENDPOINT_NAME, sentEvent.getEndpoint().getEndpointUri()) - .tag(FAILED_TAG, Boolean.toString(sentEvent.getExchange().isFailed())) - .tag(EVENT_TYPE_TAG, sentEvent.getClass().getSimpleName()) - .register(getMeterRegistry()) - .record(sentEvent.getTimeTaken(), TimeUnit.MILLISECONDS); + String name = namingStrategy.getName(sentEvent.getExchange(), sentEvent.getEndpoint()); + Tags tags = namingStrategy.getTags(sentEvent, sentEvent.getEndpoint()); + getMeterRegistry().timer(name, tags).record(sentEvent.getTimeTaken(), TimeUnit.MILLISECONDS); } protected void handleCreatedEvent(ExchangeCreatedEvent createdEvent) { @@ -95,19 +77,13 @@ public class MicrometerExchangeEventNotifier extends AbstractMicrometerEventNoti createdEvent.getExchange().setProperty("eventTimer:" + name, Timer.start(getMeterRegistry())); } - protected void handleDoneEvent(AbstractExchangeEvent doneEvent) { String name = namingStrategy.getName(doneEvent.getExchange(), doneEvent.getExchange().getFromEndpoint()); + Tags tags = namingStrategy.getTags(doneEvent, doneEvent.getExchange().getFromEndpoint()); // Would have preferred LongTaskTimer, but you cannot set the FAILED_TAG once it is registered Timer.Sample sample = (Timer.Sample) doneEvent.getExchange().removeProperty("eventTimer:" + name); if (sample != null) { - sample.stop(Timer.builder(name) - .tag(CAMEL_CONTEXT_TAG, getCamelContext().getName()) - .tag(SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName()) - .tag(ENDPOINT_NAME, doneEvent.getExchange().getFromEndpoint().getEndpointUri()) - .tag(FAILED_TAG, Boolean.toString(doneEvent.getExchange().isFailed())) - .tag(EVENT_TYPE_TAG, doneEvent.getClass().getSimpleName()) - .register(getMeterRegistry())); + sample.stop(getMeterRegistry().timer(name, tags)); } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java index 274bbaa..483a51c 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java @@ -6,22 +6,43 @@ * (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 + * 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.eventnotifier; +import java.util.function.Predicate; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tags; import org.apache.camel.Endpoint; import org.apache.camel.Exchange; +import org.apache.camel.management.event.AbstractExchangeEvent; +import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME; +import static org.apache.camel.component.micrometer.MicrometerConstants.ENDPOINT_NAME; +import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.FAILED_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; public interface MicrometerExchangeEventNotifierNamingStrategy { + Predicate<Meter.Id> EVENT_NOTIFIERS = id -> MicrometerEventNotifierService.class.getSimpleName().equals(id.getTag(SERVICE_NAME)); + MicrometerExchangeEventNotifierNamingStrategy DEFAULT = (event, endpoint) -> DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME; + String getName(Exchange exchange, Endpoint endpoint); + default Tags getTags(AbstractExchangeEvent event, Endpoint endpoint) { + return Tags.of( + CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(), + SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(), + EVENT_TYPE_TAG, event.getClass().getSimpleName(), + ENDPOINT_NAME, endpoint.getEndpointUri(), + FAILED_TAG, Boolean.toString(event.getExchange().isFailed()) + ); + } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java index d31ff21..4b9d337 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifier.java @@ -24,34 +24,36 @@ import org.apache.camel.management.event.RouteAddedEvent; import org.apache.camel.management.event.RouteRemovedEvent; import org.apache.camel.management.event.RouteStartedEvent; import org.apache.camel.management.event.RouteStoppedEvent; -import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_ADDED; -import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RUNNING; -import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; public class MicrometerRouteEventNotifier extends AbstractMicrometerEventNotifier<AbstractRouteEvent> { private final AtomicLong routesAdded = new AtomicLong(); private final AtomicLong routesRunning = new AtomicLong(); + private MicrometerRouteEventNotifierNamingStrategy namingStrategy = MicrometerRouteEventNotifierNamingStrategy.DEFAULT; public MicrometerRouteEventNotifier() { super(AbstractRouteEvent.class); } + public MicrometerRouteEventNotifierNamingStrategy getNamingStrategy() { + return namingStrategy; + } + + public void setNamingStrategy(MicrometerRouteEventNotifierNamingStrategy namingStrategy) { + this.namingStrategy = namingStrategy; + } + @Override protected void doStart() throws Exception { super.doStart(); - Gauge.builder(DEFAULT_CAMEL_ROUTES_ADDED, routesAdded, value -> Long.valueOf(value.get()).doubleValue()) - .tag(SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName()) - .tag(CAMEL_CONTEXT_TAG, getCamelContext().getName()) - .tag(EVENT_TYPE_TAG, AbstractRouteEvent.class.getSimpleName()) + Gauge.builder(namingStrategy.getRouteAddedName(), routesAdded, value -> Long.valueOf(value.get()).doubleValue()) + .baseUnit("routes") + .tags(namingStrategy.getTags(getCamelContext())) .register(getMeterRegistry()); - Gauge.builder(DEFAULT_CAMEL_ROUTES_RUNNING, routesRunning, value -> Long.valueOf(value.get()).doubleValue()) - .tag(SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName()) - .tag(CAMEL_CONTEXT_TAG, getCamelContext().getName()) - .tag(EVENT_TYPE_TAG, AbstractRouteEvent.class.getSimpleName()) + Gauge.builder(namingStrategy.getRouteRunningName(), routesRunning, value -> Long.valueOf(value.get()).doubleValue()) + .baseUnit("routes") + .tags(namingStrategy.getTags(getCamelContext())) .register(getMeterRegistry()); } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java new file mode 100644 index 0000000..6966047 --- /dev/null +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerRouteEventNotifierNamingStrategy.java @@ -0,0 +1,54 @@ +/** + * 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.eventnotifier; + +import java.util.function.Predicate; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tags; +import org.apache.camel.CamelContext; +import org.apache.camel.management.event.AbstractRouteEvent; +import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_ADDED; +import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RUNNING; +import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; + +public interface MicrometerRouteEventNotifierNamingStrategy { + + Predicate<Meter.Id> EVENT_NOTIFIERS = id -> MicrometerEventNotifierService.class.getSimpleName().equals(id.getTag(SERVICE_NAME)); + MicrometerRouteEventNotifierNamingStrategy DEFAULT = new MicrometerRouteEventNotifierNamingStrategy() { + @Override + public String getRouteAddedName() { + return DEFAULT_CAMEL_ROUTES_ADDED; + } + + @Override + public String getRouteRunningName() { + return DEFAULT_CAMEL_ROUTES_RUNNING; + } + }; + + String getRouteAddedName(); + String getRouteRunningName(); + + default Tags getTags(CamelContext camelContext) { + return Tags.of( + SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(), + CAMEL_CONTEXT_TAG, camelContext.getName(), + EVENT_TYPE_TAG, AbstractRouteEvent.class.getSimpleName()); + } +} diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistory.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistory.java index 2d45b70..993f626 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistory.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistory.java @@ -22,10 +22,6 @@ import org.apache.camel.MessageHistory; import org.apache.camel.NamedNode; import org.apache.camel.Route; import org.apache.camel.impl.DefaultMessageHistory; -import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.NODE_ID_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG; -import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; /** * A micrometer metrics based {@link MessageHistory}. This could also use {@link #elapsed} @@ -51,10 +47,8 @@ public class MicrometerMessageHistory extends DefaultMessageHistory { public void nodeProcessingDone() { super.nodeProcessingDone(); Timer timer = Timer.builder(namingStrategy.getName(route, getNode())) - .tag(CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName()) - .tag(SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName()) - .tag(ROUTE_ID_TAG, getRouteId()) - .tag(NODE_ID_TAG, getNode().getId()) + .tags(namingStrategy.getTags(route, getNode())) + .description(getNode().getDescriptionText()) .register(meterRegistry); sample.stop(timer); } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryNamingStrategy.java index bada69c..37d1cb6 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryNamingStrategy.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryNamingStrategy.java @@ -16,17 +16,34 @@ */ package org.apache.camel.component.micrometer.messagehistory; +import java.util.function.Predicate; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tags; import org.apache.camel.NamedNode; import org.apache.camel.Route; +import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME; +import static org.apache.camel.component.micrometer.MicrometerConstants.NODE_ID_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; /** * Provides a strategy to derive a meter name from the route and node */ public interface MicrometerMessageHistoryNamingStrategy { + Predicate<Meter.Id> MESSAGE_HISTORIES = id -> MicrometerMessageHistoryService.class.getSimpleName().equals(id.getTag(SERVICE_NAME)); MicrometerMessageHistoryNamingStrategy DEFAULT = (route, node) -> DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME; String getName(Route route, NamedNode node); + default Tags getTags(Route route, NamedNode node) { + return Tags.of( + CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName(), + SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName(), + ROUTE_ID_TAG, route.getId(), + NODE_ID_TAG, node.getId() + ); + } + } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicy.java index 4d3b012..830530f 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicy.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicy.java @@ -27,11 +27,8 @@ import org.apache.camel.component.micrometer.MicrometerUtils; import org.apache.camel.support.RoutePolicySupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ServiceHelper; -import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTE_POLICY_METER_NAME; -import static org.apache.camel.component.micrometer.MicrometerConstants.FAILED_TAG; import static org.apache.camel.component.micrometer.MicrometerConstants.METRICS_REGISTRY_NAME; -import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG; import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; /** @@ -47,7 +44,6 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana private MetricsStatistics statistics; private MicrometerRoutePolicyNamingStrategy namingStrategy = MicrometerRoutePolicyNamingStrategy.DEFAULT; - private static final class MetricsStatistics { private final MeterRegistry meterRegistry; private final Route route; @@ -68,11 +64,8 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana Timer.Sample sample = (Timer.Sample) exchange.removeProperty(propertyName(exchange)); if (sample != null) { Timer timer = Timer.builder(namingStrategy.getName(route)) + .tags(namingStrategy.getTags(route, exchange)) .description(route.getDescription()) - .tag(CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName()) - .tag(SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName()) - .tag(ROUTE_ID_TAG, route.getId()) - .tag(FAILED_TAG, Boolean.toString(exchange.isFailed())) .register(meterRegistry); sample.stop(timer); } @@ -119,12 +112,10 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana @Override public void onInit(Route route) { super.onInit(route); - if (getMeterRegistry() == null) { setMeterRegistry(MicrometerUtils.getOrCreateMeterRegistry( route.getRouteContext().getCamelContext().getRegistry(), METRICS_REGISTRY_NAME)); } - try { MicrometerRoutePolicyService registryService = route.getRouteContext().getCamelContext().hasService(MicrometerRoutePolicyService.class); if (registryService == null) { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyNamingStrategy.java index 83e76c7..52369e8 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyNamingStrategy.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyNamingStrategy.java @@ -16,16 +16,35 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.function.Predicate; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.Tags; +import org.apache.camel.Exchange; import org.apache.camel.Route; +import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG; import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTE_POLICY_METER_NAME; +import static org.apache.camel.component.micrometer.MicrometerConstants.FAILED_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG; +import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME; /** - * Provides a strategy to derive a meter name from the route + * Provides a strategy to derive a meter name and tags */ public interface MicrometerRoutePolicyNamingStrategy { + Predicate<Meter.Id> ROUTE_POLICIES = id -> MicrometerRoutePolicyService.class.getSimpleName().equals(id.getTag(SERVICE_NAME)); + MicrometerRoutePolicyNamingStrategy DEFAULT = route -> DEFAULT_CAMEL_ROUTE_POLICY_METER_NAME; String getName(Route route); + default Tags getTags(Route route, Exchange exchange) { + return Tags.of( + CAMEL_CONTEXT_TAG, route.getRouteContext().getCamelContext().getName(), + SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(), + ROUTE_ID_TAG, route.getId(), + FAILED_TAG, Boolean.toString(exchange.isFailed()) + ); + } + } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterEndpointTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterEndpointTest.java index e2f4d3c..1248a3b 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterEndpointTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterEndpointTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import org.apache.camel.Producer; @@ -48,7 +49,7 @@ public class CounterEndpointTest { @Before public void setUp() { - endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.COUNTER, METRICS_NAME, Tags.empty()); + endpoint = new MicrometerEndpoint(null, null, registry, Meter.Type.COUNTER, METRICS_NAME, Tags.empty()); inOrder = Mockito.inOrder(registry); } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryEndpointTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryEndpointTest.java index 5150400..e995700 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryEndpointTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryEndpointTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import org.apache.camel.Producer; @@ -48,7 +49,7 @@ public class DistributionSummaryEndpointTest { @Before public void setUp() { - endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.DISTRIBUTION_SUMMARY, METRICS_NAME, Tags.empty()); + endpoint = new MicrometerEndpoint(null, null, registry, Meter.Type.DISTRIBUTION_SUMMARY, METRICS_NAME, Tags.empty()); inOrder = Mockito.inOrder(registry); } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricsTypeTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricsTypeTest.java deleted file mode 100644 index f9df5fb..0000000 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricsTypeTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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; - -import java.util.EnumSet; -import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - -public class MetricsTypeTest { - - @Test - public void testGetByName() { - for (MetricsType type : EnumSet.allOf(MetricsType.class)) { - MetricsType t = MetricsType.getByName(type.toString()); - assertThat(t, is(type)); - } - } -} diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentTest.java index bbb2c17..92dcfb5 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentTest.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import org.apache.camel.CamelContext; @@ -93,36 +94,30 @@ public class MicrometerComponentTest { @Test public void testCreateNewEndpointForCounter() { - Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, MetricsType.COUNTER, "a name", Tags.empty()); - assertThat(endpoint, is(notNullValue())); - assertThat(endpoint, is(instanceOf(MicrometerEndpoint.class))); - } - - @Test - public void testCreateNewEndpointForGauge() { - MicrometerEndpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, MetricsType.GAUGE, "a name", Tags.empty()); + Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, Meter.Type.COUNTER, "a name", Tags.empty()); assertThat(endpoint, is(notNullValue())); assertThat(endpoint, is(instanceOf(MicrometerEndpoint.class))); } @Test public void testCreateNewEndpointForHistogram() { - Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, MetricsType.DISTRIBUTION_SUMMARY, "a name", Tags.empty()); + Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, Meter.Type.DISTRIBUTION_SUMMARY, "a name", Tags.empty()); assertThat(endpoint, is(notNullValue())); assertThat(endpoint, is(instanceOf(MicrometerEndpoint.class))); } @Test public void testCreateNewEndpointForTimer() { - Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, MetricsType.TIMER, "a name", Tags.empty()); + Endpoint endpoint = new MicrometerEndpoint(null, null, metricRegistry, Meter.Type.TIMER, "a name", Tags.empty()); assertThat(endpoint, is(notNullValue())); assertThat(endpoint, is(instanceOf(MicrometerEndpoint.class))); } @Test public void testGetMetricsType() { - for (MetricsType type : EnumSet.allOf(MetricsType.class)) { - assertThat(component.getMetricsType(type.toString() + ":metrics-name"), is(type)); + Meter.Type[] supportedTypes = {Meter.Type.COUNTER, Meter.Type.DISTRIBUTION_SUMMARY, Meter.Type.TIMER}; + for (Meter.Type type : supportedTypes) { + assertThat(component.getMetricsType(MicrometerUtils.getName(type) + ":metrics-name"), is(type)); } } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerEndpointTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerEndpointTest.java index 0fa4d86..733686d 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerEndpointTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerEndpointTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import org.apache.camel.Exchange; @@ -57,7 +58,7 @@ public class MicrometerEndpointTest { @Before public void setUp() { - endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.COUNTER, METRICS_NAME, Tags.empty()) { + endpoint = new MicrometerEndpoint(null, null, registry, Meter.Type.COUNTER, METRICS_NAME, Tags.empty()) { @Override public Producer createProducer() { return null; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerEndpointTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerEndpointTest.java index 57d12dd..be0a0ac 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerEndpointTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerEndpointTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import org.apache.camel.Producer; @@ -47,7 +48,7 @@ public class TimerEndpointTest { @Before public void setUp() { - endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.TIMER, METRICS_NAME, Tags.empty()); + endpoint = new MicrometerEndpoint(null, null, registry, Meter.Type.TIMER, METRICS_NAME, Tags.empty()); inOrder = Mockito.inOrder(registry); } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/AbstractMicrometerEventNotifierTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/AbstractMicrometerEventNotifierTest.java index 37cd628..8b8540f 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/AbstractMicrometerEventNotifierTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/AbstractMicrometerEventNotifierTest.java @@ -6,14 +6,13 @@ * (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 + * 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.eventNotifier; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerExchangeEventNotifierTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerExchangeEventNotifierTest.java index e983882..8802d09 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerExchangeEventNotifierTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerExchangeEventNotifierTest.java @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -6,32 +6,26 @@ * (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 + * 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.eventNotifier; import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.Timer; -import org.apache.camel.CamelExchangeException; import org.apache.camel.CamelExecutionException; -import org.apache.camel.Endpoint; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.micrometer.eventnotifier.AbstractMicrometerEventNotifier; import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier; -import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.support.ExpressionAdapter; import org.junit.Test; -import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME; public class MicrometerExchangeEventNotifierTest extends AbstractMicrometerEventNotifierTest { diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerRouteEventNotifierTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerRouteEventNotifierTest.java index f25fb9c..a1c685b 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerRouteEventNotifierTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventNotifier/MicrometerRouteEventNotifierTest.java @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -6,23 +6,20 @@ * (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 + * 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.eventNotifier; import io.micrometer.core.instrument.Gauge; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.micrometer.eventnotifier.AbstractMicrometerEventNotifier; import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier; -import org.apache.camel.spi.EventNotifier; import org.junit.Test; import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_ADDED; import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RUNNING; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ExceptionRouteMicrometerMessageHistoryTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ExceptionRouteMicrometerMessageHistoryTest.java index 24de85a..8c3e3d4 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ExceptionRouteMicrometerMessageHistoryTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ExceptionRouteMicrometerMessageHistoryTest.java @@ -19,8 +19,6 @@ package org.apache.camel.component.micrometer.messagehistory; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.CamelContext; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/ManagedMicrometerRoutePolicyTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/ManagedMicrometerRoutePolicyTest.java index 18e60e5..a6b7c8b 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/ManagedMicrometerRoutePolicyTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/ManagedMicrometerRoutePolicyTest.java @@ -18,13 +18,10 @@ package org.apache.camel.component.micrometer.routepolicy; import java.util.List; import java.util.Set; -import javax.management.MBeanInfo; import javax.management.MBeanServer; -import javax.management.ObjectInstance; import javax.management.ObjectName; import io.micrometer.core.instrument.Meter; import org.apache.camel.builder.RouteBuilder; -import org.junit.Ignore; import org.junit.Test; public class ManagedMicrometerRoutePolicyTest extends AbstractMicrometerRoutePolicyTest { diff --git a/examples/camel-example-micrometer/README.md b/examples/camel-example-micrometer/README.md index 1523225..8fd6123 100644 --- a/examples/camel-example-micrometer/README.md +++ b/examples/camel-example-micrometer/README.md @@ -34,7 +34,12 @@ This example uses [Prometheus](https://prometheus.io) as monitoring backend. * Start up Prometheus -Optionally, you can install a metrics visualizer like [Grafana](https://grafana.com/). +Optionally, you can install a metrics visualizer, e.g. [Grafana](https://grafana.com/): + +* Download the package for your platform and unpack it on your local host +* Add your Prometheus server as a data source +* Import a [suitable dashboard](https://grafana.com/dashboards/4701) +* Add some graphs to display Camel metrics (this is out of scope for this example). ### Run diff --git a/examples/camel-example-micrometer/src/data/message1.xml b/examples/camel-example-micrometer/src/data/message1.xml deleted file mode 100644 index 1a85d06..0000000 --- a/examples/camel-example-micrometer/src/data/message1.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<person user="james"> - <firstName>James</firstName> - <lastName>Strachan</lastName> - <city>London</city> -</person> \ No newline at end of file diff --git a/examples/camel-example-micrometer/src/data/message2.xml b/examples/camel-example-micrometer/src/data/message2.xml deleted file mode 100644 index 73c88bf..0000000 --- a/examples/camel-example-micrometer/src/data/message2.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - 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. - ---> -<person user="hiram"> - <firstName>Hiram</firstName> - <lastName>Chirino</lastName> - <city>Tampa</city> -</person> \ No newline at end of file diff --git a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/CamelPrometheusExample.java b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/CamelPrometheusExample.java index 89eee21..345b95b 100644 --- a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/CamelPrometheusExample.java +++ b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/CamelPrometheusExample.java @@ -6,17 +6,17 @@ * (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 + * 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.example.micrometer; +import java.time.Duration; import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; @@ -28,16 +28,18 @@ import io.micrometer.prometheus.PrometheusMeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.component.micrometer.DistributionStatisticConfigFilter; import org.apache.camel.component.micrometer.MicrometerConstants; -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.spring.javaconfig.CamelConfiguration; import org.apache.camel.spring.javaconfig.Main; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import static org.apache.camel.component.micrometer.MicrometerConstants.DISTRIBUTION_SUMMARIES; +import static org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryNamingStrategy.MESSAGE_HISTORIES; +import static org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyNamingStrategy.ROUTE_POLICIES; -//START SNIPPET: RouteConfig +//START SNIPPET: CamelPrometheusExample @Configuration @ComponentScan @@ -55,20 +57,38 @@ public class CamelPrometheusExample extends CamelConfiguration { @Override protected void setupCamelContext(CamelContext camelContext) { camelContext.addRoutePolicyFactory(new MicrometerRoutePolicyFactory()); - camelContext.getManagementStrategy().addEventNotifier(new MicrometerRouteEventNotifier()); - camelContext.getManagementStrategy().addEventNotifier(new MicrometerExchangeEventNotifier()); + camelContext.setMessageHistoryFactory(new MicrometerMessageHistoryFactory()); } + /** + * Set up registry. When using Spring Boot, this is provided for you, and you have to provide + * a bean of type MeterRegistryCustomizer in order to apply common tags, filters, etc. + */ @Bean(name = MicrometerConstants.METRICS_REGISTRY_NAME) public PrometheusMeterRegistry meterRegistry() { - // Register the meter registry and some standard meters PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); - // Configure meter registry to expose + DistributionStatisticConfigFilter timerMeterFilter = new DistributionStatisticConfigFilter() + .andAppliesTo(ROUTE_POLICIES) + .orAppliesTo(MESSAGE_HISTORIES) + .setPublishPercentileHistogram(true) + .setMinimumExpectedDuration(Duration.ofMillis(1L)) + .setMaximumExpectedDuration(Duration.ofMillis(150L)); + + DistributionStatisticConfigFilter summaryMeterFilter = new DistributionStatisticConfigFilter() + .andAppliesTo(DISTRIBUTION_SUMMARIES) + .setPublishPercentileHistogram(true) + .setMinimumExpectedValue(1L) + .setMaximumExpectedValue(100L); + meterRegistry.config() + // Application name. Required by Grafana JVM Dashboard 4701. .commonTags(Tags.of("application", "CamelPrometheusExample")) - .meterFilter(new DistributionStatisticConfigFilter()); + .meterFilter(timerMeterFilter) + .meterFilter(summaryMeterFilter); + + // Add JVM metrics. Using Spring Boot, these are added automatically new ClassLoaderMetrics().bindTo(meterRegistry); new JvmMemoryMetrics().bindTo(meterRegistry); @@ -80,5 +100,5 @@ public class CamelPrometheusExample extends CamelConfiguration { } } -//END SNIPPET: RouteConfig +//END SNIPPET: CamelPrometheusExample diff --git a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScheduledRouteBuilder.java b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScheduledRouteBuilder.java index 2bfa68a..ac187a3 100644 --- a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScheduledRouteBuilder.java +++ b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScheduledRouteBuilder.java @@ -6,37 +6,38 @@ * (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 + * 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.example.micrometer; import java.util.Random; +import org.apache.camel.LoggingLevel; import org.apache.camel.builder.RouteBuilder; import org.springframework.stereotype.Component; @Component public class ScheduledRouteBuilder extends RouteBuilder { + static final String TIMER_ROUTE_ID = "timer:foo"; private Random random = new Random(System.currentTimeMillis()); @Override public void configure() throws Exception { - from("timer:foo?period=10s&fixedRate=true") - .routeId("timer:foo") + from("timer:foo?period=1s&fixedRate=true") + .routeId(TIMER_ROUTE_ID) .setHeader("random").exchange(exchange -> random.nextInt(100)) + .log(LoggingLevel.INFO, "Delay is ${header.random}") .to("direct:bar"); from("direct:bar") .routeId("direct:bar") - .to("micrometer:summary:histo?value=${header.random}") + .to("micrometer:summary:summary?value=${header.random}") .to("micrometer:timer:timer?action=start") .delay().exchange(exchange -> random.nextInt(100)) .to("micrometer:timer:timer?action=stop"); diff --git a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScrapeRouteBuilder.java b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScrapeRouteBuilder.java index a932a47..2fd3eb4 100644 --- a/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScrapeRouteBuilder.java +++ b/examples/camel-example-micrometer/src/main/java/org/apache/camel/example/micrometer/ScrapeRouteBuilder.java @@ -6,23 +6,28 @@ * (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 + * 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.example.micrometer; import io.micrometer.prometheus.PrometheusMeterRegistry; +import org.apache.camel.LoggingLevel; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +/** + * Route Builder that exposes teh endpoint used by Prometheus to scrape + * monitoring data from the Camel application. When running in a Spring + * Boot 2.x environment, this is not required as Spring Boot already exposes + * this endpoint by default. + */ @Component public class ScrapeRouteBuilder extends RouteBuilder { @@ -36,7 +41,8 @@ public class ScrapeRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("netty4-http:http://0.0.0.0:8088/metrics") - .routeId("netty4-http-scrape") + .routeId("netty4-http:scrape") + .log(LoggingLevel.INFO, "Scraping metrics") .transform().method(prometheusMeterRegistry, "scrape"); } diff --git a/examples/camel-example-micrometer/src/test/java/org/apache/camel/example/micrometer/IntegrationTest.java b/examples/camel-example-micrometer/src/test/java/org/apache/camel/example/micrometer/IntegrationTest.java index d4e88e9..102b11f 100644 --- a/examples/camel-example-micrometer/src/test/java/org/apache/camel/example/micrometer/IntegrationTest.java +++ b/examples/camel-example-micrometer/src/test/java/org/apache/camel/example/micrometer/IntegrationTest.java @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -6,14 +6,13 @@ * (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 + * 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.example.micrometer; diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/pom.xml b/platforms/spring-boot/components-starter/camel-micrometer-starter/pom.xml new file mode 100644 index 0000000..80627ac --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/pom.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components-starter</artifactId> + <version>2.22.0-SNAPSHOT</version> + </parent> + <artifactId>camel-micrometer-starter</artifactId> + <packaging>jar</packaging> + <name>Spring-Boot Starter :: Camel :: Micrometer</name> + <description>Spring-Boot Starter for Camel Micrometer based monitoring component</description> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <version>${spring-boot-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-micrometer</artifactId> + <version>${project.version}</version> + </dependency> + <!--START OF GENERATED CODE--> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-spring-boot-starter</artifactId> + </dependency> + <!--END OF GENERATED CODE--> + </dependencies> +</project> diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentAutoConfiguration.java new file mode 100644 index 0000000..530eb10 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentAutoConfiguration.java @@ -0,0 +1,128 @@ +/** + * 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 java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Generated; +import org.apache.camel.CamelContext; +import org.apache.camel.component.micrometer.MicrometerComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spi.HasId; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.CamelPropertiesHelper; +import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +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.Configuration; +import org.springframework.context.annotation.Lazy; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@Configuration +@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class, + MicrometerComponentAutoConfiguration.GroupConditions.class}) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + MicrometerComponentConfiguration.class}) +public class MicrometerComponentAutoConfiguration { + + private static final Logger LOGGER = LoggerFactory + .getLogger(MicrometerComponentAutoConfiguration.class); + @Autowired + private ApplicationContext applicationContext; + @Autowired + private CamelContext camelContext; + @Autowired + private MicrometerComponentConfiguration configuration; + @Autowired(required = false) + private List<ComponentCustomizer<MicrometerComponent>> customizers; + + static class GroupConditions extends GroupCondition { + public GroupConditions() { + super("camel.component", "camel.component.micrometer"); + } + } + + @Lazy + @Bean(name = "micrometer-component") + @ConditionalOnMissingBean(MicrometerComponent.class) + public MicrometerComponent configureMicrometerComponent() throws Exception { + MicrometerComponent component = new MicrometerComponent(); + component.setCamelContext(camelContext); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, + false); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + Object value = entry.getValue(); + Class<?> paramClass = value.getClass(); + if (paramClass.getName().endsWith("NestedConfiguration")) { + Class nestedClass = null; + try { + nestedClass = (Class) paramClass.getDeclaredField( + "CAMEL_NESTED_CLASS").get(null); + HashMap<String, Object> nestedParameters = new HashMap<>(); + IntrospectionSupport.getProperties(value, nestedParameters, + null, false); + Object nestedProperty = nestedClass.newInstance(); + CamelPropertiesHelper.setCamelProperties(camelContext, + nestedProperty, nestedParameters, false); + entry.setValue(nestedProperty); + } catch (NoSuchFieldException e) { + } + } + } + CamelPropertiesHelper.setCamelProperties(camelContext, component, + parameters, false); + if (ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<MicrometerComponent> customizer : customizers) { + boolean useCustomizer = (customizer instanceof HasId) + ? HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.micrometer.customizer", + ((HasId) customizer).getId()) + : HierarchicalPropertiesEvaluator.evaluate( + applicationContext.getEnvironment(), + "camel.component.customizer", + "camel.component.micrometer.customizer"); + if (useCustomizer) { + LOGGER.debug("Configure component {}, with customizer {}", + component, customizer); + customizer.customize(component); + } + } + } + return component; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentConfiguration.java new file mode 100644 index 0000000..13c108d --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/java/org/apache/camel/component/micrometer/springboot/MicrometerComponentConfiguration.java @@ -0,0 +1,65 @@ +/** + * 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 javax.annotation.Generated; +import io.micrometer.core.instrument.MeterRegistry; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +/** + * To collect various metrics directly from Camel routes using the DropWizard + * metrics library. + * + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") +@ConfigurationProperties(prefix = "camel.component.micrometer") +public class MicrometerComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { + + /** + * To use a custom configured MetricRegistry. + */ + @NestedConfigurationProperty + private MeterRegistry metricsRegistry; + /** + * Whether the component should resolve property placeholders on itself when + * starting. Only properties which are of String type can use property + * placeholders. + */ + private Boolean resolvePropertyPlaceholders = true; + + public MeterRegistry getMetricsRegistry() { + return metricsRegistry; + } + + public void setMetricsRegistry(MeterRegistry metricsRegistry) { + this.metricsRegistry = metricsRegistry; + } + + public Boolean getResolvePropertyPlaceholders() { + return resolvePropertyPlaceholders; + } + + public void setResolvePropertyPlaceholders( + Boolean resolvePropertyPlaceholders) { + this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; + } +} \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/LICENSE.txt b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/NOTICE.txt b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..a0bb564 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,19 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.camel.component.micrometer.springboot.MicrometerComponentAutoConfiguration diff --git a/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.provides b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.provides new file mode 100644 index 0000000..e4e52b0 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-micrometer-starter/src/main/resources/META-INF/spring.provides @@ -0,0 +1,17 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +provides: camel-micrometer diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml index fbf27e1..e31ad2f 100644 --- a/platforms/spring-boot/components-starter/pom.xml +++ b/platforms/spring-boot/components-starter/pom.xml @@ -224,6 +224,7 @@ <module>camel-mail-starter</module> <module>camel-master-starter</module> <module>camel-metrics-starter</module> + <module>camel-micrometer-starter</module> <module>camel-milo-starter</module> <module>camel-mina2-starter</module> <module>camel-mllp-starter</module> -- To stop receiving notification emails like this one, please contact acosent...@apache.org.