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 37b7aa31471088f6e830069b4fb42429185ef7a4 Author: Christian Ohr <christian....@gmail.com> AuthorDate: Fri May 4 17:14:18 2018 +0200 CAMEL-11600:version update, checkstyle --- components/camel-micrometer/pom.xml | 5 + .../src/main/docs/micrometer-component.adoc | 343 ++++++--------------- .../micrometer/AbstractMicrometerProducer.java | 14 +- .../component/micrometer/CounterProducer.java | 10 +- .../DistributionStatisticConfigFilter.java | 21 +- .../micrometer/DistributionSummaryProducer.java | 10 +- .../component/micrometer/MicrometerComponent.java | 24 +- .../component/micrometer/MicrometerEndpoint.java | 16 +- .../camel/component/micrometer/TimerProducer.java | 10 +- .../micrometer/json/AbstractMicrometerService.java | 46 +-- .../micrometer/json/MicrometerModule.java | 115 ++++--- .../messagehistory/MicrometerMessageHistory.java | 6 +- .../MicrometerMessageHistoryFactory.java | 27 +- .../MicrometerMessageHistoryService.java | 6 +- .../routepolicy/MicrometerRegistryService.java | 6 +- .../routepolicy/MicrometerRoutePolicy.java | 20 +- .../routepolicy/MicrometerRoutePolicyFactory.java | 9 +- .../spi/InstrumentedThreadPoolFactory.java | 15 +- .../spi/TimedScheduledExecutorService.java | 29 +- .../micrometer/AbstractMicrometerProducerTest.java | 34 +- .../component/micrometer/CounterEndpointTest.java | 27 +- .../component/micrometer/CounterProducerTest.java | 27 +- .../component/micrometer/CounterRouteTest.java | 19 +- .../DistributionSummaryEndpointTest.java | 19 +- .../DistributionSummaryProducerTest.java | 14 +- .../micrometer/DistributionSummaryRouteTest.java | 15 +- .../micrometer/MetricComponentSpringTest.java | 8 +- .../component/micrometer/MetricsTypeTest.java | 4 +- .../micrometer/MicrometerComponentRouteTest.java | 7 +- .../micrometer/MicrometerComponentTest.java | 8 +- .../micrometer/MicrometerEndpointTest.java | 24 +- .../component/micrometer/TimerEndpointTest.java | 4 +- .../component/micrometer/TimerProducerTest.java | 42 +-- .../camel/component/micrometer/TimerRouteTest.java | 18 +- ...ExceptionRouteMicrometerMessageHistoryTest.java | 12 +- .../messagehistory/ManagedMessageHistoryTest.java | 8 +- .../MicrometerMessageHistoryTest.java | 5 +- .../AbstractMicrometerRoutePolicyTest.java | 22 +- .../ManagedMicrometerRoutePolicyTest.java | 19 +- ...MicrometerRoutePolicyMulticastSubRouteTest.java | 7 +- .../MicrometerRoutePolicySubRouteTest.java | 8 +- .../routepolicy/MicrometerRoutePolicyTest.java | 7 +- .../spi/InstrumentedThreadPoolFactoryTest.java | 28 +- parent/pom.xml | 2 +- 44 files changed, 489 insertions(+), 631 deletions(-) diff --git a/components/camel-micrometer/pom.xml b/components/camel-micrometer/pom.xml index 93aa07a..273f497 100644 --- a/components/camel-micrometer/pom.xml +++ b/components/camel-micrometer/pom.xml @@ -54,6 +54,11 @@ <artifactId>micrometer-core</artifactId> <version>${micrometer-version}</version> </dependency> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-registry-jmx</artifactId> + <version>${micrometer-version}</version> + </dependency> <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> diff --git a/components/camel-micrometer/src/main/docs/micrometer-component.adoc b/components/camel-micrometer/src/main/docs/micrometer-component.adoc index d4bb70f..f587f7c 100644 --- a/components/camel-micrometer/src/main/docs/micrometer-component.adoc +++ b/components/camel-micrometer/src/main/docs/micrometer-component.adoc @@ -1,7 +1,7 @@ -[[metrics-component]] -== Metrics Component +[[micrometer-component]] +== Micrometer Component ifdef::env-github[] -*Available as of Camel version 2.14.0* +*Available as of Camel version 2.22.0* :caution-caption: :boom: :important-caption: :exclamation: @@ -10,17 +10,17 @@ ifdef::env-github[] :warning-caption: :warning: endif::[] -### Metrics Component +### Micrometer Component -The **metrics:** component allows to collect various metrics directly +The **micrometer:** component allows to collect various metrics directly from Camel routes. Supported metric types -are link:#MetricsComponent-counter[counter], link:#MetricsComponent-histogram[histogram], -link:#MetricsComponent-meter[meter], link:#MetricsComponent-timer[timer] and link:#MetricsComponent-gauge[gauge]. http://metrics.dropwizard.io[Metrics] provides +are link:#MicrometerComponent-counter[counter], link:#MicrometerComponent-distributionSummary[summary], +and link:#MicrometerComponent-timer[timer]. http://micrometer.io/[Micrometer] provides simple way to measure behaviour of application. Configurable -reporting backend is enabling different integration options for +reporting backends (via Micrometer registries) is enabling different integration options for collecting and visualizing statistics. The component also provides -a `MetricsRoutePolicyFactory` which allows to expose route statistics -using Dropwizard Metrics, see bottom of page for details. +a `MicrometerRoutePolicyFactory` which allows to expose route statistics +using Micrometer, see bottom of page for details. Maven users will need to add the following dependency to their `pom.xml` for this component: @@ -29,7 +29,7 @@ for this component: ---- <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-metrics</artifactId> + <artifactId>camel-micrometer</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> @@ -39,20 +39,20 @@ for this component: [source] ---- -metrics:[ meter | counter | histogram | timer | gauge ]:metricname[?options] +micrometer:[ counter | summary | timer ]:metricname[?options] ---- ### Options // component options: START -The Metrics component supports 2 options which are listed below. +The Micrometer component supports the following options: [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type -| *metricRegistry* (advanced) | To use a custom configured MetricRegistry. | | MetricRegistry +| *metricRegistry* (advanced) | To use a custom configured MetricRegistry. | | MeterRegistry | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |=== // component options: END @@ -62,12 +62,12 @@ The Metrics component supports 2 options which are listed below. The Metrics endpoint is configured using URI syntax: ---- -metrics:metricsType:meterName +micrometer:metricsType:meterName ---- with the following path and query parameters: -==== Path Parameters (2 parameters): +==== Path Parameters: [width="100%",cols="2,5,^1,2",options="header"] @@ -78,17 +78,16 @@ with the following path and query parameters: |=== -==== Query Parameters (7 parameters): +==== Query Parameters: [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *tags* (producer) | Tags that accompany the metric. Comma-separated list of key=value pairs | | String | *action* (producer) | Action when using timer type | | MetricsTimerAction | *decrement* (producer) | Decrement value when using counter type | | Long | *increment* (producer) | Increment value when using counter type | | Long -| *mark* (producer) | Mark when using meter type | | Long -| *subject* (producer) | Subject value when using gauge type | | Object | *value* (producer) | Value value when using histogram type | | Long | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |=== @@ -96,13 +95,12 @@ with the following path and query parameters: -### [[MetricsComponent-registry]]Metric Registry +### [[MicrometerComponent-registry]]Meter Registry -Camel Metrics component uses by default a `MetricRegistry` instance with -a `Slf4jReporter` that has a 60 second reporting interval. -This default registry can be replaced with a custom one by providing -a `MetricRegistry` bean. If multiple `MetricRegistry` beans exist in the -application, the one with name `metricRegistry` is used. +The Camel Micrometer component uses by default a `SimpleMeterRegistry` instance. +This default registry 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. For example using Spring Java Configuration: @@ -122,9 +120,9 @@ public static class MyConfig extends SingleRouteCamelConfiguration { }; } - @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME) - public MetricRegistry getMetricRegistry() { - MetricRegistry registry = ...; + @Bean(name = MicrometerComponent.METRICS_REGISTRY_NAME) + public MeterRegistry getMeterRegistry() { + MeterRegistry registry = ...; return registry; } } @@ -144,55 +142,54 @@ class MyBean extends RouteBuilder { @Produces // If multiple MetricRegistry beans - // @Named(MetricsComponent.METRIC_REGISTRY_NAME) + // @Named(MicrometerComponent.METRIC_REGISTRY_NAME) MetricRegistry registry() { - MetricRegistry registry = new MetricRegistry(); + MeterRegistry registry = ...; // ... return registry; } } ---- -CAUTION: `MetricRegistry` uses internal thread(s) for reporting. There is no -public API in version DropWizard `3.0.1` for users to clean up on exit. Thus using -Camel Metrics Component leads to Java classloader leak and my cause -`OutOfMemoryErrors` in some cases. ### Usage Each metric has type and name. Supported types are -link:#MetricsComponent-counter[counter], -link:#MetricsComponent-histogram[histogram], link:#MetricsComponent-meter[meter], -link:#MetricsComponent-timer[timer] and link:#MetricsComponent-gauge[gauge]. -Metric name is simple string. If metric type is not provided then type meter is used by default. +link:#MicrometerComponent-counter[counter], +link:#MicrometerComponent-summary[histogram] and +link:#MetricsComponent-timer[timer]. +Metric name is simple string. If metric type is not provided then a counter is used by default. #### Headers -Metric name defined in URI can be overridden by using header with name +The Metric name defined in URI can be overridden by using header with name `CamelMetricsName`. +The Metric tags defined as URI parameters can be overridden by using header with name `CamelMetricsTags`. For example [source,java] ---- from("direct:in") - .setHeader(MetricsConstants.HEADER_METRIC_NAME, constant("new.name")) - .to("metrics:counter:name.not.used") + .setHeader(MicrometerConstants.HEADER_METRIC_NAME, constant("new.name")) + .setHeader(MicrometerConstants.HEADER_METRIC_TAGS, constant(Tags.of("otherKey", "otherValue"))) + .to("metrics:counter:name.not.used?tags=key=value") .to("direct:out"); ---- -will update counter with name `new.name` instead of `name.not.used`. +will update a counter with name `new.name` instead of `name.not.used` using the +tag `otherKey` with value `otherValue` instead of the tag `key` with value `value`. -All Metrics specific headers are removed from the message once Metrics +All Metrics specific headers are removed from the message once the Micrometer endpoint finishes processing of exchange. While processing exchange -Metrics endpoint will catch all exceptions and write log entry using +Micrometer endpoint will catch all exceptions and write log entry using level `warn`. -### [[MetricsComponent-counter]]Metrics type counter +### [[MicrometerComponent-counter]]Counter [source] ---- -metrics:counter:metricname[?options] +micrometer:counter:name[?options] ---- #### Options @@ -200,8 +197,8 @@ metrics:counter:metricname[?options] [width="100%",cols="10%,10%,80%",options="header",] |===================================================== |Name |Default |Description -|increment |- |Long value to add to the counter -|decrement |- |Long value to subtract from the counter +|increment |- |Double value to add to the counter +|decrement |- |Double value to subtract from the counter |===================================================== If neither `increment` or `decrement` is defined then counter value will @@ -212,7 +209,7 @@ only increment operation is called. ---- // update counter simple.counter by 7 from("direct:in") - .to("metric:counter:simple.counter?increment=7") + .to("micrometer:counter:simple.counter?increment=7") .to("direct:out"); ---- @@ -220,7 +217,7 @@ from("direct:in") ---- // increment counter simple.counter by 1 from("direct:in") - .to("metric:counter:simple.counter") + .to("micrometer:counter:simple.counter") .to("direct:out"); ---- @@ -228,7 +225,7 @@ from("direct:in") ---- // decrement counter simple.counter by 3 from("direct:in") - .to("metric:counter:simple.counter?decrement=3") + .to("micrometer:counter:simple.counter?decrement=3") .to("direct:out"); ---- @@ -240,16 +237,16 @@ values specified in Metrics component URI. [width="100%",cols="10%,80%,10%",options="header",] |==================================================================== |Name |Description |Expected type -|CamelMetricsCounterIncrement |Override increment value in URI |Long -|CamelMetricsCounterDecrement |Override decrement value in URI |Long +|CamelMetricsCounterIncrement |Override increment value in URI |Double +|CamelMetricsCounterDecrement |Override decrement value in URI |Double |==================================================================== [source,java] ---- // update counter simple.counter by 417 from("direct:in") - .setHeader(MetricsConstants.HEADER_COUNTER_INCREMENT, constant(417L)) - .to("metric:counter:simple.counter?increment=7") + .setHeader(MicrometerConstants.HEADER_COUNTER_INCREMENT, constant(417.0D)) + .to("micrometer:counter:simple.counter?increment=7") .to("direct:out"); ---- @@ -257,17 +254,17 @@ from("direct:in") ---- // updates counter using simple language to evaluate body.length from("direct:in") - .setHeader(MetricsConstants.HEADER_COUNTER_INCREMENT, simple("${body.length}")) - .to("metrics:counter:body.length") - .to("mock:out"); + .setHeader(MicrometerConstants.HEADER_COUNTER_INCREMENT, simple("${body.length}")) + .to("micrometer:counter:body.length") + .to("direct:out"); ---- -### [[MetricsComponent-histogram]]Metric type histogram +### [[MicrometerComponent-summary]]Histogram [source] ---- -metrics:histogram:metricname[?options] +micrometer:summary:metricname[?options] ---- #### Options @@ -285,7 +282,7 @@ logged. ---- // adds value 9923 to simple.histogram from("direct:in") - .to("metric:histogram:simple.histogram?value=9923") + .to("micrometer:summary:simple.histogram?value=9923") .to("direct:out"); ---- @@ -293,7 +290,7 @@ from("direct:in") ---- // nothing is added to simple.histogram; warning is logged from("direct:in") - .to("metric:histogram:simple.histogram") + .to("micrometer:summary:simple.histogram") .to("direct:out"); ---- @@ -313,70 +310,18 @@ component URI. ---- // adds value 992 to simple.histogram from("direct:in") - .setHeader(MetricsConstants.HEADER_HISTOGRAM_VALUE, constant(992L)) - .to("metric:histogram:simple.histogram?value=700") + .setHeader(MicrometerConstants.HEADER_HISTOGRAM_VALUE, constant(992L)) + .to("micrometer:summary:simple.histogram?value=700") .to("direct:out") ---- -### [[MetricsComponent-meter]]Metric type meter - -[source] ----- -metrics:meter:metricname[?options] ----- - -#### Options - -[width="100%",cols="10%,10%,80%",options="header",] -|=================================== -|Name |Default |Description -|mark |- |Long value to use as mark -|=================================== -If `mark` is not set then `meter.mark()` is called without argument. - -[source,java] ----- -// marks simple.meter without value -from("direct:in") - .to("metric:simple.meter") - .to("direct:out"); ----- - -[source,java] ----- -// marks simple.meter with value 81 -from("direct:in") - .to("metric:meter:simple.meter?mark=81") - .to("direct:out"); ----- - -#### Headers - -Message header can be used to override `mark` value specified in Metrics -component URI. - -[width="100%",cols="10%,80%,10%",options="header",] -|======================================================= -|Name |Description |Expected type -|CamelMetricsMeterMark |Override mark value in URI |Long -|======================================================= - -[source,java] ----- -// updates meter simple.meter with value 345 -from("direct:in") - .setHeader(MetricsConstants.HEADER_METER_MARK, constant(345L)) - .to("metric:meter:simple.meter?mark=123") - .to("direct:out"); ----- - -### [[MetricsComponent-timer]]Metrics type timer +### [[MicrometerComponent-timer]]Timer [source] ---- -metrics:timer:metricname[?options] +micrometer:timer:metricname[?options] ---- #### Options @@ -396,12 +341,12 @@ and warning is logged. ---- // measure time taken by route "calculate" from("direct:in") - .to("metrics:timer:simple.timer?action=start") + .to("micrometer:timer:simple.timer?action=start") .to("direct:calculate") - .to("metrics:timer:simple.timer?action=stop"); + .to("micrometer:timer:simple.timer?action=stop"); ---- -`TimerContext` objects are stored as Exchange properties between +`Timer.Sample` objects are stored as Exchange properties between different Metrics component calls. #### Headers @@ -413,80 +358,35 @@ component URI. |======================================================================= |Name |Description |Expected type |CamelMetricsTimerAction |Override timer action in URI -|`org.apache.camel.component.metrics.timer.TimerEndpoint.TimerAction` +|`org.apache.camel.component.micrometer.timer.TimerEndpoint.TimerAction` |======================================================================= [source,java] ---- // sets timer action using header from("direct:in") - .setHeader(MetricsConstants.HEADER_TIMER_ACTION, TimerAction.start) - .to("metric:timer:simple.timer") + .setHeader(MicrometerConstants.HEADER_TIMER_ACTION, TimerAction.start) + .to("micrometer:timer:simple.timer") .to("direct:out"); ---- -### [[MetricsComponent-gauge]]Metric type gauge -[source] ----- -metrics:gauge:metricname[?options] ----- - -#### Options - -[width="100%",cols="10%,10%,80%",options="header",] -|===================================================== -|Name |Default |Description -|subject |- |Any object to be observed by the gauge -|===================================================== - -If `subject` is not defined it's simply ignored, i.e. the gauge is not registered. - -[source,java] ----- -// update gauge "simple.gauge" by a bean "mySubjectBean" -from("direct:in") - .to("metric:gauge:simple.gauge?subject=#mySubjectBean") - .to("direct:out"); ----- - -#### Headers - -Message headers can be used to override `subject` values specified in Metrics component URI. -Note: if `CamelMetricsName` header is specified, then new gauge is registered in addition to -default one specified in a URI. - -[width="100%",cols="10%,80%,10%",options="header",] -|==================================================================== -|Name |Description |Expected type -|CamelMetricsGaugeSubject |Override subject value in URI |Object -|==================================================================== - -[source,java] ----- -// update gauge simple.gauge by a String literal "myUpdatedSubject" -from("direct:in") - .setHeader(MetricsConstants.HEADER_GAUGE_SUBJECT, constant("myUpdatedSubject")) - .to("metric:counter:simple.gauge?subject=#mySubjectBean") - .to("direct:out"); ----- - -### MetricsRoutePolicyFactory +### MicrometerRoutePolicyFactory This factory allows to add a RoutePolicy for each -route which exposes route utilization statistics using Dropwizard metrics. +route which 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 MetricsRoutePolicyFactory you can define a -MetricsRoutePolicy per route you want to instrument, in case you only +NOTE: Instead of using the MicrometerRoutePolicyFactory you can define a +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: [source,java] ---- -context.addRoutePolicyFactory(new MetricsRoutePolicyFactory()); +context.addRoutePolicyFactory(new MicrometerRoutePolicyFactory()); ---- And from XML DSL you define a <bean> as follows: @@ -494,64 +394,31 @@ And from XML DSL you define a <bean> as follows: [source,xml] ---- <!-- use camel-metrics route policy to gather metrics for all routes --> - <bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory"/> + <bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory"/> ---- -The `MetricsRoutePolicyFactory` and `MetricsRoutePolicy` supports the +The `MicrometerRoutePolicyFactory` and `MicrometerRoutePolicy` supports the following options: [width="100%",cols="10%,10%,80%",options="header",] |======================================================================= |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 -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 -want fine grained mbeans per statistics type. - -|jmxDomain |org.apache.camel.metrics |The JMX domain name - |prettyPrint |false |Whether to use pretty print when outputting statistics in json format - -|metricsRegistry | |Allow to use a shared -`com.codahale.metrics.MetricRegistry`. If none is provided then Camel +|meterRegistry | |Allow to use a shared `MeterRegistry`. If none is provided then Camel will create a shared instance used by the this CamelContext. - -|rateUnit |TimeUnit.SECONDS |The unit to use for rate in the metrics -reporter or when dumping the statistics as json. - -|durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration in -the metrics reporter or when dumping the statistics as json. - -|namePattern |`##name##.##routeId##.##type##` |*Camel 2.17:* The name +|durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration in when dumping the statistics as json. +|prefix|CamelMetrics|Common prefix for metric names +|namePattern |`##prefix##.##name##.##routeId##.##type##` |The name pattern to use. Uses dot as separators, but you can change that. The -values `##name##`, `##routeId##`, and `##type##` will be replaced with actual -value. Where `###name###` is the name of the CamelContext. `###routeId###` -is the name of the route. And `###type###` is the value of responses. +values `##prefix##`, `##name##`, `##routeId##`, and `##type##` will be replaced with actual +value, where `##prefix##` is a common metrics name prefix,`###name###` is the name of the +CamelContext. `###routeId###` is the name of the route and `###type###` is the value of responses. |======================================================================= - - -From Java code tou can get hold of -the `com.codahale.metrics.MetricRegistry` from the -`org.apache.camel.component.metrics.routepolicy.MetricsRegistryService` -as shown below: - -[source,java] ----- -MetricRegistryService registryService = context.hasService(MetricsRegistryService.class); -if (registryService != null) { - MetricsRegistry registry = registryService.getMetricsRegistry(); - ... -} ----- -### MetricsMessageHistoryFactory +### MicrometerMessageHistoryFactory -*Available as of Camel 2.17* This factory allows to use metrics to capture Message History performance @@ -563,7 +430,7 @@ From Java you just set the factory to the `CamelContext` as shown below: [source,java] ---- -context.setMessageHistoryFactory(new MetricsMessageHistoryFactory()); +context.setMessageHistoryFactory(new MicrometerMessageHistoryFactory()); ---- And from XML DSL you define a <bean> as follows: @@ -571,7 +438,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 --> - <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.metrics.messagehistory.MetricsMessageHistoryFactory"/> + <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory"/> ---- The following options is supported on the factory: @@ -579,35 +446,19 @@ The following options is supported on the factory: [width="100%",cols="10%,10%,80%",options="header",] |======================================================================= |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 -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 -want fine grained mbeans per statistics type. - -|jmxDomain |org.apache.camel.metrics |The JMX domain name - |prettyPrint |false |Whether to use pretty print when outputting statistics in json format - -|metricsRegistry | |Allow to use a shared -`com.codahale.metrics.MetricRegistry`. If none is provided then Camel +|meterRegistry | |Allow to use a shared +`MeterRegistry`. If none is provided then Camel will create a shared instance used by the this CamelContext. - -|rateUnit |TimeUnit.SECONDS |The unit to use for rate in the metrics -reporter or when dumping the statistics as json. - -|durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration in -the metrics reporter or when dumping the statistics as json. - -|namePattern |`##name##.##routeId##.###id###.##type##` |The name pattern +|durationUnit |TimeUnit.MILLISECONDS |The unit to use for duration when dumping the statistics as json. +|prefix|CamelMetrics|Common prefix for metric names +|namePattern |`##prefix##.##name##.##routeId##.##id##.##type##` |The name pattern to use. Uses dot as separators, but you can change that. The values `##name##`, `##routeId##`, `##type##`, and `###id###` will be replaced with -actual value. Where `###name###` is the name of the CamelContext. -`###routeId###` is the name of the route. The `###id###` pattern represents -the node id. And `###type###` is the value of history. +actual value, where `###name###` is the name of the CamelContext, +`###routeId###` is the name of the route, the `###id###` pattern represents +the node id and `###type###` is the value of history. |======================================================================= At runtime the metrics can be accessed from Java API or JMX which allows @@ -618,17 +469,15 @@ shown: [source,java] ---- -MetricsMessageHistoryService service = context.hasService(MetricsMessageHistoryService.class); +MicrometerMessageHistoryService service = context.hasService(MicrometerMessageHistoryService.class); String json = service.dumpStatisticsAsJson(); ---- And the JMX API the MBean is registered in the `type=services` tree -with `name=MetricsMessageHistoryService`. +with `name=MicrometerMessageHistoryService`. ### InstrumentedThreadPoolFactory -*Available as of Camel 2.18* - This factory allows you to gather performance information about Camel Thread Pools by injecting a InstrumentedThreadPoolFactory which collects information from inside of Camel. See more details at Advanced configuration of CamelContext using Spring 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 da55499..0d20077 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,10 +16,10 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Function; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.search.Search; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.impl.DefaultProducer; @@ -27,8 +27,6 @@ import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Optional; -import java.util.function.Function; public abstract class AbstractMicrometerProducer<T extends Meter> extends DefaultProducer { @@ -55,7 +53,7 @@ public abstract class AbstractMicrometerProducer<T extends Meter> extends Defaul } @Override - public void process(Exchange exchange) throws Exception { + public void process(Exchange exchange) { Message in = exchange.getIn(); String defaultMetricsName = getEndpoint().getMetricsName(); String finalMetricsName = getMetricsName(in, defaultMetricsName); @@ -112,7 +110,7 @@ public abstract class AbstractMicrometerProducer<T extends Meter> extends Defaul } public Iterable<Tag> getTagHeader(Message in, String header, Iterable<Tag> defaultTags) { - return in.getHeader(header, defaultTags, Iterable.class); + return (Iterable<Tag>)in.getHeader(header, defaultTags, Iterable.class); } protected boolean clearMetricsHeaders(Message in) { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/CounterProducer.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/CounterProducer.java index 127a283..b9ed3d2 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/CounterProducer.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/CounterProducer.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,14 +16,12 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Function; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import org.apache.camel.Exchange; import org.apache.camel.Message; - -import java.util.function.Function; - import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_DECREMENT; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_INCREMENT; 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 8f16c7e..63ac4dc 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 @@ -1,11 +1,26 @@ +/** + * 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.time.Duration; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import java.time.Duration; - /** * Filter for adding common distribution statistics for all Timers and Histograms. * Configure and add this to the {@link io.micrometer.core.instrument.MeterRegistry} @@ -19,7 +34,7 @@ public class DistributionStatisticConfigFilter implements MeterFilter { private Boolean enabled; private Integer bufferLength; private Duration expiry; - private double[] percentiles = new double[] { 0.5D, 0.75D, 0.9D, 0.99D, 0.999D }; + private double[] percentiles = new double[] {0.5D, 0.75D, 0.9D, 0.99D, 0.999D }; private long[] slas; @Override diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionSummaryProducer.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionSummaryProducer.java index 2b26d31..63e3754 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionSummaryProducer.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/DistributionSummaryProducer.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,15 +16,13 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Function; import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import org.apache.camel.Exchange; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.util.function.Function; - import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_HISTOGRAM_VALUE; public class DistributionSummaryProducer extends AbstractMicrometerProducer<DistributionSummary> { 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 5dcf6ae..5534493 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,8 +16,10 @@ */ package org.apache.camel.component.micrometer; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -30,21 +32,13 @@ import org.apache.camel.util.StringHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.BinaryOperator; -import java.util.stream.Collectors; -import java.util.stream.Stream; - /** * Represents the component that manages metrics endpoints. */ public class MicrometerComponent extends UriEndpointComponent { - public static final String METRICS_REGISTRY = "metricsRegistry"; - public static final MetricsType DEFAULT_METER_TYPE = MetricsType.TIMER; + public static final String METRICS_REGISTRY_NAME = "metricsRegistry"; + public static final MetricsType DEFAULT_METER_TYPE = MetricsType.COUNTER; private static final Logger LOG = LoggerFactory.getLogger(MicrometerComponent.class); @@ -62,7 +56,7 @@ public class MicrometerComponent extends UriEndpointComponent { protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { if (metricsRegistry == null) { Registry camelRegistry = getCamelContext().getRegistry(); - metricsRegistry = getOrCreateMeterRegistry(camelRegistry, METRICS_REGISTRY); + metricsRegistry = getOrCreateMeterRegistry(camelRegistry, METRICS_REGISTRY_NAME); } if (prefix == null) { prefix = MicrometerConstants.HEADER_PREFIX; 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 4e398cf..b1882c7 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -18,7 +18,11 @@ package org.apache.camel.component.micrometer; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; -import org.apache.camel.*; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.RuntimeCamelException; import org.apache.camel.impl.DefaultEndpoint; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; @@ -59,12 +63,12 @@ public class MicrometerEndpoint extends DefaultEndpoint { } @Override - public Consumer createConsumer(Processor processor) throws Exception { + public Consumer createConsumer(Processor processor) { throw new RuntimeCamelException("Cannot consume from " + getClass().getSimpleName() + ": " + getEndpointUri()); } @Override - public Producer createProducer() throws Exception { + public Producer createProducer() { if (metricsType == MetricsType.COUNTER) { return new CounterProducer(this); } else if (metricsType == MetricsType.DISTRIBUTION_SUMMARY) { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/TimerProducer.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/TimerProducer.java index 837b521..0c8e9fa 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/TimerProducer.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/TimerProducer.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Function; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Timer; @@ -23,9 +24,6 @@ import org.apache.camel.Exchange; import org.apache.camel.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.util.function.Function; - import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_TIMER_ACTION; public class TimerProducer extends AbstractMicrometerProducer<Timer> { diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/AbstractMicrometerService.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/AbstractMicrometerService.java index d88fdf9..67cac62 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/AbstractMicrometerService.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/AbstractMicrometerService.java @@ -1,5 +1,22 @@ +/** + * 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.json; +import java.util.concurrent.TimeUnit; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; @@ -11,18 +28,11 @@ import org.apache.camel.spi.Registry; import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ObjectHelper; -import java.time.temporal.ChronoUnit; -import java.util.concurrent.TimeUnit; - -/** - * @author Christian Ohr - */ public class AbstractMicrometerService extends ServiceSupport { private CamelContext camelContext; private MeterRegistry meterRegistry; private boolean prettyPrint = true; - private boolean supportAggregablePercentiles; private TimeUnit durationUnit = TimeUnit.MILLISECONDS; private transient ObjectMapper mapper; private transient ObjectMapper secondsMapper; @@ -59,14 +69,6 @@ public class AbstractMicrometerService extends ServiceSupport { this.durationUnit = durationUnit; } - public boolean isSupportAggregablePercentiles() { - return supportAggregablePercentiles; - } - - public void setSupportAggregablePercentiles(boolean supportAggregablePercentiles) { - this.supportAggregablePercentiles = supportAggregablePercentiles; - } - public String dumpStatisticsAsJson() { ObjectWriter writer = mapper.writer(); if (isPrettyPrint()) { @@ -92,10 +94,10 @@ public class AbstractMicrometerService extends ServiceSupport { } @Override - protected void doStart() throws Exception { + protected void doStart() { if (meterRegistry == null) { Registry camelRegistry = getCamelContext().getRegistry(); - meterRegistry = camelRegistry.lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY, MeterRegistry.class); + meterRegistry = camelRegistry.lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY_NAME, MeterRegistry.class); // create a new metricsRegistry by default if (meterRegistry == null) { meterRegistry = new SimpleMeterRegistry(); @@ -103,14 +105,14 @@ public class AbstractMicrometerService extends ServiceSupport { } // json mapper - this.mapper = new ObjectMapper().registerModule(new MicrometerModule(getDurationUnit(), supportAggregablePercentiles)); - this.secondsMapper = getDurationUnit() == TimeUnit.SECONDS ? - this.mapper : - new ObjectMapper().registerModule(new MicrometerModule(TimeUnit.SECONDS, supportAggregablePercentiles)); + this.mapper = new ObjectMapper().registerModule(new MicrometerModule(getDurationUnit())); + this.secondsMapper = getDurationUnit() == TimeUnit.SECONDS + ? this.mapper + : new ObjectMapper().registerModule(new MicrometerModule(TimeUnit.SECONDS)); } @Override - protected void doStop() throws Exception { + protected void doStop() { } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/MicrometerModule.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/MicrometerModule.java index 7487e8f..3068b6f 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/MicrometerModule.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/json/MicrometerModule.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,37 +16,46 @@ */ package org.apache.camel.component.micrometer.json; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.module.SimpleSerializers; import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import io.micrometer.core.instrument.*; +import io.micrometer.core.instrument.AbstractDistributionSummary; +import io.micrometer.core.instrument.AbstractTimer; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.DistributionSummary; +import io.micrometer.core.instrument.FunctionCounter; +import io.micrometer.core.instrument.FunctionTimer; +import io.micrometer.core.instrument.Gauge; +import io.micrometer.core.instrument.LongTaskTimer; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.composite.CompositeMeterRegistry; import io.micrometer.core.instrument.distribution.HistogramSnapshot; +import io.micrometer.core.instrument.distribution.ValueAtPercentile; import io.micrometer.core.instrument.search.Search; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * @author Christian Ohr - */ public class MicrometerModule extends Module { static final Version VERSION = new Version(1, 0, 2, "", "io.micrometer", "micrometer-core"); private final TimeUnit timeUnit; - private final boolean supportAggregablePercentiles; - public MicrometerModule(TimeUnit timeUnit, boolean supportAggregablePercentiles) { + public MicrometerModule(TimeUnit timeUnit) { this.timeUnit = timeUnit; - this.supportAggregablePercentiles = supportAggregablePercentiles; } @Override @@ -60,7 +69,7 @@ public class MicrometerModule extends Module { } - private static class IdSerializer extends StdSerializer<Meter.Id> { + private static final class IdSerializer extends StdSerializer<Meter.Id> { private IdSerializer() { super(Meter.Id.class); } @@ -74,7 +83,7 @@ public class MicrometerModule extends Module { } } - private static class TagSerializer extends StdSerializer<Tag> { + private static final class TagSerializer extends StdSerializer<Tag> { private TagSerializer() { super(Tag.class); } @@ -102,9 +111,20 @@ public class MicrometerModule extends Module { } protected abstract void serializeStatistics(T meter, JsonGenerator json, SerializerProvider provider) throws IOException; + + protected static void serializeSnapshot(JsonGenerator json, HistogramSnapshot snapshot, TimeUnit timeUnit) throws IOException { + json.writeNumberField("count", snapshot.count()); + json.writeNumberField("max", snapshot.max(timeUnit)); + json.writeNumberField("mean", snapshot.mean(timeUnit)); + json.writeNumberField("total", snapshot.total(timeUnit)); + ValueAtPercentile[] percentiles = snapshot.percentileValues(); + for (ValueAtPercentile percentile : percentiles) { + json.writeNumberField(String.format("p%0.3d", percentile.percentile()), percentile.value(timeUnit)); + } + } } - private static class GaugeSerializer extends MeterSerializer<Gauge> { + private static final class GaugeSerializer extends MeterSerializer<Gauge> { private GaugeSerializer() { super(Gauge.class); } @@ -115,7 +135,7 @@ public class MicrometerModule extends Module { } } - private static class CounterSerializer extends MeterSerializer<Counter> { + private static final class CounterSerializer extends MeterSerializer<Counter> { private CounterSerializer() { super(Counter.class); } @@ -126,7 +146,7 @@ public class MicrometerModule extends Module { } } - private static class FunctionCounterSerializer extends MeterSerializer<FunctionCounter> { + private static final class FunctionCounterSerializer extends MeterSerializer<FunctionCounter> { private FunctionCounterSerializer() { super(FunctionCounter.class); } @@ -137,32 +157,23 @@ public class MicrometerModule extends Module { } } - private static class TimerSerializer extends MeterSerializer<AbstractTimer> { + private static final class TimerSerializer extends MeterSerializer<AbstractTimer> { private final TimeUnit timeUnit; - private final boolean supportAggregablePercentiles; - private TimerSerializer(TimeUnit timeUnit, boolean supportAggregablePercentiles) { + private TimerSerializer(TimeUnit timeUnit) { super(AbstractTimer.class); this.timeUnit = timeUnit; - this.supportAggregablePercentiles = supportAggregablePercentiles; } @Override protected void serializeStatistics(AbstractTimer timer, JsonGenerator json, SerializerProvider provider) throws IOException { - HistogramSnapshot snapshot = timer.takeSnapshot(supportAggregablePercentiles); - json.writeNumberField("count", snapshot.count()); - json.writeNumberField("max", snapshot.max(timeUnit)); - json.writeNumberField("mean", snapshot.mean(timeUnit)); - json.writeNumberField("total", snapshot.total(timeUnit)); - double[] percentiles = timer.statsConfig().getPercentiles(); - for (int idx = 0; idx < percentiles.length; idx++) { - json.writeNumberField(String.format("p%0.3d", percentiles[idx]), snapshot.percentileValues()[idx].value(timeUnit)); - } + serializeSnapshot(json, timer.takeSnapshot(), timeUnit); } + } - private static class FunctionTimerSerializer extends MeterSerializer<FunctionTimer> { + private static final class FunctionTimerSerializer extends MeterSerializer<FunctionTimer> { private final TimeUnit timeUnit; @@ -179,7 +190,7 @@ public class MicrometerModule extends Module { } } - private static class LongTaskTimerSerializer extends MeterSerializer<LongTaskTimer> { + private static final class LongTaskTimerSerializer extends MeterSerializer<LongTaskTimer> { private final TimeUnit timeUnit; @@ -195,35 +206,25 @@ public class MicrometerModule extends Module { } } - private static class DistributionSummarySerializer extends MeterSerializer<AbstractDistributionSummary> { + private static final class DistributionSummarySerializer extends MeterSerializer<AbstractDistributionSummary> { private final TimeUnit timeUnit; - private final boolean supportAggregablePercentiles; - public DistributionSummarySerializer(TimeUnit timeUnit, boolean supportAggregablePercentiles) { + private DistributionSummarySerializer(TimeUnit timeUnit) { super(AbstractDistributionSummary.class); this.timeUnit = timeUnit; - this.supportAggregablePercentiles = supportAggregablePercentiles; } @Override protected void serializeStatistics(AbstractDistributionSummary distributionSummary, JsonGenerator json, SerializerProvider provider) throws IOException { - HistogramSnapshot snapshot = distributionSummary.takeSnapshot(supportAggregablePercentiles); - json.writeNumberField("count", snapshot.count()); - json.writeNumberField("max", snapshot.max(timeUnit)); - json.writeNumberField("mean", snapshot.mean(timeUnit)); - json.writeNumberField("total", snapshot.total(timeUnit)); - double[] percentiles = distributionSummary.statsConfig().getPercentiles(); - for (int idx = 0; idx < percentiles.length; idx++) { - json.writeNumberField(String.format("p%0.3d", percentiles[idx]), snapshot.percentileValues()[idx].value(timeUnit)); - } + serializeSnapshot(json, distributionSummary.takeSnapshot(), timeUnit); } } - private static class MeterRegistrySerializer extends StdSerializer<MeterRegistry> { + private static final class MeterRegistrySerializer extends StdSerializer<MeterRegistry> { private MeterRegistrySerializer() { super(MeterRegistry.class); @@ -251,17 +252,15 @@ public class MicrometerModule extends Module { if (meterRegistry instanceof CompositeMeterRegistry) { Map<String, List<Meter>> map = new TreeMap<>(); ((CompositeMeterRegistry) meterRegistry).getRegistries().forEach(reg -> - meters(meterRegistry, clazz).entrySet().forEach( - entry -> map.merge(entry.getKey(), entry.getValue(), (m1, m2) -> - Stream.concat(m1.stream(), m2.stream()).collect(Collectors.toList())) - )); + meters(meterRegistry, clazz).forEach((key, value) -> map.merge(key, value, (m1, m2) -> + Stream.concat(m1.stream(), m2.stream()).collect(Collectors.toList())))); return map; } return Search.in(meterRegistry).meters().stream() .filter(clazz::isInstance) .collect(Collectors.toMap( - meter -> meter.getId().getName(), - meter -> Collections.singletonList(meter))); + meter -> meter.getId().getName(), + Collections::singletonList)); } } @@ -274,10 +273,10 @@ public class MicrometerModule extends Module { new GaugeSerializer(), new CounterSerializer(), new FunctionCounterSerializer(), - new TimerSerializer(timeUnit, supportAggregablePercentiles), + new TimerSerializer(timeUnit), new FunctionTimerSerializer(timeUnit), new LongTaskTimerSerializer(timeUnit), - new DistributionSummarySerializer(timeUnit, supportAggregablePercentiles), + new DistributionSummarySerializer(timeUnit), new MeterRegistrySerializer() ))); } 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 266191a..a888dfc 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryFactory.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryFactory.java index 6c9661d4..886bf45 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryFactory.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryFactory.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,23 +16,26 @@ */ package org.apache.camel.component.micrometer.messagehistory; +import java.util.Date; +import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.MeterRegistry; -import org.apache.camel.*; +import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; +import org.apache.camel.MessageHistory; +import org.apache.camel.NamedNode; +import org.apache.camel.NonManagedService; +import org.apache.camel.StaticService; import org.apache.camel.component.micrometer.MicrometerConstants; import org.apache.camel.spi.MessageHistoryFactory; import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.ObjectHelper; -import java.util.Date; -import java.util.concurrent.TimeUnit; - /** * A factory to setup and use {@link MicrometerMessageHistory} as message history implementation. */ public class MicrometerMessageHistoryFactory extends ServiceSupport implements CamelContextAware, StaticService, NonManagedService, MessageHistoryFactory { private CamelContext camelContext; - private MicrometerMessageHistoryService messageHistoryService; private MeterRegistry meterRegistry; private boolean prettyPrint = true; private TimeUnit durationUnit = TimeUnit.MILLISECONDS; @@ -108,10 +111,9 @@ public class MicrometerMessageHistoryFactory extends ServiceSupport implements C @Override public MessageHistory newMessageHistory(String routeId, NamedNode namedNode, long timestamp) { - MicrometerMessageHistory messageHistory = new MicrometerMessageHistory(meterRegistry, routeId, namedNode, + return new MicrometerMessageHistory(meterRegistry, routeId, namedNode, createName("history", routeId, namedNode.getId()), timestamp); - return messageHistory; } private String createName(String type, String routeId, String id) { @@ -127,7 +129,8 @@ public class MicrometerMessageHistoryFactory extends ServiceSupport implements C } @Override - protected void doStart() throws Exception { + protected void doStart() { + MicrometerMessageHistoryService messageHistoryService; try { messageHistoryService = camelContext.hasService(MicrometerMessageHistoryService.class); if (messageHistoryService == null) { @@ -150,7 +153,7 @@ public class MicrometerMessageHistoryFactory extends ServiceSupport implements C } @Override - protected void doStop() throws Exception { + protected void doStop() { // noop } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryService.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryService.java index f0f84e3..aee4b61 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryService.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryService.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRegistryService.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRegistryService.java index c9d2385..8f5ac29 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRegistryService.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRegistryService.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. 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 6cb8bfb..66ec33d 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,8 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; import org.apache.camel.CamelContext; @@ -27,9 +29,6 @@ import org.apache.camel.support.RoutePolicySupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ServiceHelper; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; - /** * A {@link org.apache.camel.spi.RoutePolicy} which gathers statistics and reports them using {@link MeterRegistry}. * <p/> @@ -38,7 +37,6 @@ import java.util.regex.Matcher; public class MicrometerRoutePolicy extends RoutePolicySupport implements NonManagedService { private MeterRegistry meterRegistry; - private MicrometerRegistryService registryService; private boolean prettyPrint; private TimeUnit durationUnit = TimeUnit.MILLISECONDS; private MetricsStatistics statistics; @@ -48,6 +46,7 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana private static final class MetricsStatistics { + private static final String MICROMETER_ROUTE_POLICY = "MicrometerRoutePolicy-"; private final MeterRegistry meterRegistry; private final Route route; private final String name; @@ -60,16 +59,17 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana public void onExchangeBegin(Exchange exchange) { Timer.Sample sample = Timer.start(meterRegistry); - exchange.setProperty("MicrometerRoutePolicy-" + route.getId(), sample); + exchange.setProperty(MICROMETER_ROUTE_POLICY + route.getId(), sample); } public void onExchangeDone(Exchange exchange) { - Timer.Sample sample = (Timer.Sample) exchange.removeProperty("MicrometerRoutePolicy-" + route.getId()); + Timer.Sample sample = (Timer.Sample) exchange.removeProperty(MICROMETER_ROUTE_POLICY + route.getId()); if (sample != null) { Timer timer = Timer.builder(name) .description(route.getDescription()) .tag("camelService", "routePolicy") .tag("route", route.getId()) + .tag("failed", Boolean.toString(exchange.isFailed())) .register(meterRegistry); sample.stop(timer); } @@ -129,6 +129,7 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana super.onInit(route); this.route = route; + MicrometerRegistryService registryService; try { registryService = route.getRouteContext().getCamelContext().hasService(MicrometerRegistryService.class); if (registryService == null) { @@ -169,7 +170,6 @@ public class MicrometerRoutePolicy extends RoutePolicySupport implements NonMana @Override public void onExchangeBegin(Route route, Exchange exchange) { - if (statistics != null) { statistics.onExchangeBegin(exchange); } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyFactory.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyFactory.java index fbe485c..1ed4911 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyFactory.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyFactory.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.MeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.component.micrometer.MicrometerConstants; @@ -23,8 +24,6 @@ import org.apache.camel.model.RouteDefinition; import org.apache.camel.spi.RoutePolicy; import org.apache.camel.spi.RoutePolicyFactory; -import java.util.concurrent.TimeUnit; - /** * A {@link org.apache.camel.spi.RoutePolicyFactory} to plugin and use metrics for gathering route utilization statistics */ diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactory.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactory.java index f071e1b..7aa2e37 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactory.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactory.java @@ -16,6 +16,10 @@ */ package org.apache.camel.component.micrometer.spi; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicLong; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; @@ -24,18 +28,13 @@ import org.apache.camel.spi.ThreadPoolFactory; import org.apache.camel.spi.ThreadPoolProfile; import org.apache.camel.util.ObjectHelper; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicLong; - /** * This implements a {@link ThreadPoolFactory} and generates an Instrumented versions of ExecutorService used to * monitor performance of each thread using Metrics. */ public class InstrumentedThreadPoolFactory implements ThreadPoolFactory { - private static final AtomicLong counter = new AtomicLong(); + private static final AtomicLong COUNTER = new AtomicLong(); private MeterRegistry meterRegistry; private ThreadPoolFactory threadPoolFactory; private String prefix = "instrumented-delegate-"; @@ -75,11 +74,11 @@ public class InstrumentedThreadPoolFactory implements ThreadPoolFactory { } private String name(String prefix) { - return prefix + counter.incrementAndGet(); + return prefix + COUNTER.incrementAndGet(); } void reset() { - counter.set(0L); + COUNTER.set(0L); } } diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/TimedScheduledExecutorService.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/TimedScheduledExecutorService.java index 9f0b6ac..2db876c 100644 --- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/TimedScheduledExecutorService.java +++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/spi/TimedScheduledExecutorService.java @@ -1,19 +1,30 @@ +/** + * 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.spi; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.Timer; -import io.micrometer.core.instrument.internal.TimedExecutorService; - import java.util.concurrent.Callable; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; +import io.micrometer.core.instrument.Timer; +import io.micrometer.core.instrument.internal.TimedExecutorService; -/** - * @author Christian Ohr - */ public class TimedScheduledExecutorService extends TimedExecutorService implements ScheduledExecutorService { private final ScheduledExecutorService delegate; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/AbstractMicrometerProducerTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/AbstractMicrometerProducerTest.java index 149dbee..b7e2641 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/AbstractMicrometerProducerTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/AbstractMicrometerProducerTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import java.util.function.Function; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; @@ -30,9 +31,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.function.Function; - import static org.apache.camel.component.micrometer.AbstractMicrometerProducer.HEADER_PATTERN; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_HISTOGRAM_VALUE; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_METRIC_NAME; @@ -65,11 +63,11 @@ public class AbstractMicrometerProducerTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { okProducer = new AbstractMicrometerProducer<Meter>(endpoint) { @Override - protected Function registrar(String name, Iterable<Tag> list) { + protected Function<MeterRegistry, Meter> registrar(String name, Iterable<Tag> list) { return null; } @@ -80,7 +78,7 @@ public class AbstractMicrometerProducerTest { failProducer = new AbstractMicrometerProducer<Meter>(endpoint) { @Override - protected Function registrar(String name, Iterable<Tag> list) { + protected Function<MeterRegistry, Meter> registrar(String name, Iterable<Tag> list) { return null; } @@ -122,7 +120,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetMetricsName() throws Exception { + public void testGetMetricsName() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A"); assertThat(okProducer.getMetricsName(in, "value"), is("A")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -130,7 +128,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetMetricsNameNotSet() throws Exception { + public void testGetMetricsNameNotSet() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null); assertThat(okProducer.getMetricsName(in, "name"), is("name")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -138,7 +136,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetStringHeader() throws Exception { + public void testGetStringHeader() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn("A"); assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("A")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -146,7 +144,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetStringHeaderWithNullValue() throws Exception { + public void testGetStringHeaderWithNullValue() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(null); assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -154,7 +152,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetStringHeaderWithWhiteSpaces() throws Exception { + public void testGetStringHeaderWithWhiteSpaces() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(" "); assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -162,7 +160,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetStringHeaderWithEmptySrting() throws Exception { + public void testGetStringHeaderWithEmptyString() { when(in.getHeader(HEADER_METRIC_NAME, String.class)).thenReturn(""); assertThat(okProducer.getStringHeader(in, HEADER_METRIC_NAME, "value"), is("value")); inOrder.verify(in, times(1)).getHeader(HEADER_METRIC_NAME, String.class); @@ -170,7 +168,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testGetLongHeader() throws Exception { + public void testGetLongHeader() { when(in.getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class)).thenReturn(201L); assertThat(okProducer.getLongHeader(in, HEADER_HISTOGRAM_VALUE, 19L), is(201L)); inOrder.verify(in, times(1)).getHeader(HEADER_HISTOGRAM_VALUE, 19L, Long.class); @@ -178,7 +176,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testClearMetricsHeaders() throws Exception { + public void testClearMetricsHeaders() { when(in.removeHeaders(HEADER_PATTERN)).thenReturn(true); assertThat(okProducer.clearMetricsHeaders(in), is(true)); inOrder.verify(in, times(1)).removeHeaders(HEADER_PATTERN); @@ -186,7 +184,7 @@ public class AbstractMicrometerProducerTest { } @Test - public void testClearRealHeaders() throws Exception { + public void testClearRealHeaders() { Message msg = new DefaultMessage(new DefaultCamelContext()); Object val = new Object(); msg.setHeader(HEADER_HISTOGRAM_VALUE, 109L); 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 6817798..aa22cd1 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import java.util.Collections; import io.micrometer.core.instrument.MeterRegistry; import org.apache.camel.Producer; import org.junit.After; @@ -26,10 +27,10 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; @RunWith(MockitoJUnitRunner.class) @@ -46,7 +47,7 @@ public class CounterEndpointTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.COUNTER, METRICS_NAME, Collections.emptyList()); inOrder = Mockito.inOrder(registry); } @@ -57,7 +58,7 @@ public class CounterEndpointTest { } @Test - public void testCounterEndpoint() throws Exception { + public void testCounterEndpoint() { assertThat(endpoint.getRegistry(), is(registry)); assertThat(endpoint.getMetricsName(), is(METRICS_NAME)); assertThat(endpoint.getIncrement(), is(nullValue())); @@ -72,24 +73,24 @@ public class CounterEndpointTest { } @Test - public void testGetIncrement() throws Exception { + public void testGetIncrement() { assertThat(endpoint.getIncrement(), is(nullValue())); } @Test - public void testSetIncrement() throws Exception { + public void testSetIncrement() { assertThat(endpoint.getIncrement(), is(nullValue())); endpoint.setIncrement(VALUE); assertThat(endpoint.getIncrement(), is(VALUE)); } @Test - public void testGetDecrement() throws Exception { + public void testGetDecrement() { assertThat(endpoint.getDecrement(), is(nullValue())); } @Test - public void testSetDecrement() throws Exception { + public void testSetDecrement() { assertThat(endpoint.getDecrement(), is(nullValue())); endpoint.setDecrement(VALUE); assertThat(endpoint.getDecrement(), is(VALUE)); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterProducerTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterProducerTest.java index 431984b..1fb69a2 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterProducerTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterProducerTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -28,13 +28,14 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - import static org.apache.camel.component.micrometer.AbstractMicrometerProducer.HEADER_PATTERN; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_DECREMENT; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_INCREMENT; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class CounterProducerTest { @@ -63,7 +64,7 @@ public class CounterProducerTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { endpoint = mock(MicrometerEndpoint.class); producer = new CounterProducer(endpoint); inOrder = Mockito.inOrder(endpoint, exchange, registry, counter, in); @@ -73,12 +74,12 @@ public class CounterProducerTest { } @Test - public void testCounterProducer() throws Exception { + public void testCounterProducer() { assertThat(producer.getEndpoint().equals(endpoint), is(true)); } @Test - public void testProcessWithIncrementOnly() throws Exception { + public void testProcessWithIncrementOnly() { Object action = null; when(endpoint.getIncrement()).thenReturn(INCREMENT); when(endpoint.getDecrement()).thenReturn(null); @@ -98,7 +99,7 @@ public class CounterProducerTest { } @Test - public void testProcessWithDecrementOnly() throws Exception { + public void testProcessWithDecrementOnly() { Object action = null; when(endpoint.getIncrement()).thenReturn(null); when(endpoint.getDecrement()).thenReturn(DECREMENT); @@ -118,7 +119,7 @@ public class CounterProducerTest { } @Test - public void testDoProcessWithIncrementAndDecrement() throws Exception { + public void testDoProcessWithIncrementAndDecrement() { when(endpoint.getIncrement()).thenReturn(INCREMENT); when(endpoint.getDecrement()).thenReturn(DECREMENT); when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Double.class)).thenReturn(INCREMENT); @@ -139,7 +140,7 @@ public class CounterProducerTest { } @Test - public void testProcessWithOutIncrementAndDecrement() throws Exception { + public void testProcessWithOutIncrementAndDecrement() { Object action = null; when(endpoint.getIncrement()).thenReturn(null); when(endpoint.getDecrement()).thenReturn(null); @@ -158,7 +159,7 @@ public class CounterProducerTest { } @Test - public void testProcessOverridingIncrement() throws Exception { + public void testProcessOverridingIncrement() { when(endpoint.getIncrement()).thenReturn(INCREMENT); when(endpoint.getDecrement()).thenReturn(DECREMENT); when(in.getHeader(HEADER_COUNTER_INCREMENT, INCREMENT, Double.class)).thenReturn(INCREMENT + 1); @@ -178,7 +179,7 @@ public class CounterProducerTest { } @Test - public void testProcessOverridingDecrement() throws Exception { + public void testProcessOverridingDecrement() { Object action = null; when(endpoint.getIncrement()).thenReturn(null); when(endpoint.getDecrement()).thenReturn(DECREMENT); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterRouteTest.java index dc4b5c0..f91d6df 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/CounterRouteTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -35,9 +35,10 @@ import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; - -import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY; -import static org.apache.camel.component.micrometer.MicrometerConstants.*; +import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY_NAME; +import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_DECREMENT; +import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_COUNTER_INCREMENT; +import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_METRIC_NAME; import static org.junit.Assert.assertEquals; @RunWith(CamelSpringRunner.class) @@ -74,7 +75,7 @@ public class CounterRouteTest { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:in-1") .to("micrometer:counter:A?increment=5") .to("mock:out"); @@ -96,7 +97,7 @@ public class CounterRouteTest { }; } - @Bean(name = METRICS_REGISTRY) + @Bean(name = METRICS_REGISTRY_NAME) public MeterRegistry getMetricRegistry() { return new SimpleMeterRegistry(); } @@ -104,7 +105,7 @@ public class CounterRouteTest { @Before public void setup() { - registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY, MeterRegistry.class); + registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY_NAME, MeterRegistry.class); } @After 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 2ed4e92..b237c51 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 java.util.Collections; import io.micrometer.core.instrument.MeterRegistry; import org.apache.camel.Producer; import org.junit.After; @@ -26,10 +27,10 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; @RunWith(MockitoJUnitRunner.class) @@ -46,18 +47,18 @@ public class DistributionSummaryEndpointTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.DISTRIBUTION_SUMMARY, METRICS_NAME, Collections.emptyList()); inOrder = Mockito.inOrder(registry); } @After - public void tearDown() throws Exception { + public void tearDown() { inOrder.verifyNoMoreInteractions(); } @Test - public void testHistogramEndpoint() throws Exception { + public void testHistogramEndpoint() { assertThat(endpoint, is(notNullValue())); assertThat(endpoint.getRegistry(), is(registry)); assertThat(endpoint.getMetricsName(), is(METRICS_NAME)); @@ -71,12 +72,12 @@ public class DistributionSummaryEndpointTest { } @Test - public void testGetValue() throws Exception { + public void testGetValue() { assertThat(endpoint.getValue(), is(nullValue())); } @Test - public void testSetValue() throws Exception { + public void testSetValue() { assertThat(endpoint.getValue(), is(nullValue())); endpoint.setValue(VALUE); assertThat(endpoint.getValue(), is(VALUE)); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryProducerTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryProducerTest.java index d2669fd..39a465d 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryProducerTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryProducerTest.java @@ -19,7 +19,6 @@ package org.apache.camel.component.micrometer; import io.micrometer.core.instrument.DistributionSummary; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.search.Search; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.junit.Before; @@ -29,9 +28,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - import static org.apache.camel.component.micrometer.AbstractMicrometerProducer.HEADER_PATTERN; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_HISTOGRAM_VALUE; import static org.hamcrest.Matchers.is; @@ -66,7 +62,7 @@ public class DistributionSummaryProducerTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { endpoint = mock(MicrometerEndpoint.class); producer = new DistributionSummaryProducer(endpoint); inOrder = Mockito.inOrder(endpoint, registry, histogram, exchange, in); @@ -76,12 +72,12 @@ public class DistributionSummaryProducerTest { } @Test - public void testHistogramProducer() throws Exception { + public void testHistogramProducer() { assertThat(producer.getEndpoint().equals(endpoint), is(true)); } @Test - public void testProcessValueSet() throws Exception { + public void testProcessValueSet() { when(endpoint.getValue()).thenReturn(VALUE); when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Double.class)).thenReturn(VALUE); producer.doProcess(exchange, METRICS_NAME, Tags.empty()); @@ -96,7 +92,7 @@ public class DistributionSummaryProducerTest { } @Test - public void testProcessValueNotSet() throws Exception { + public void testProcessValueNotSet() { Object action = null; when(endpoint.getValue()).thenReturn(null); producer.doProcess(exchange, METRICS_NAME, Tags.empty()); @@ -110,7 +106,7 @@ public class DistributionSummaryProducerTest { } @Test - public void testProcessOverrideValue() throws Exception { + public void testProcessOverrideValue() { when(endpoint.getValue()).thenReturn(VALUE); when(in.getHeader(HEADER_HISTOGRAM_VALUE, VALUE, Double.class)).thenReturn(VALUE + 3.0d); producer.doProcess(exchange, METRICS_NAME, Tags.empty()); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryRouteTest.java index ba6b995..128da0d 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/DistributionSummaryRouteTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -36,8 +36,7 @@ import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; - -import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY; +import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY_NAME; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_HISTOGRAM_VALUE; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_METRIC_NAME; import static org.junit.Assert.assertEquals; @@ -66,7 +65,7 @@ public class DistributionSummaryRouteTest { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:in") .to("micrometer:summary:A?value=332491") .to("mock:out"); @@ -74,7 +73,7 @@ public class DistributionSummaryRouteTest { }; } - @Bean(name = METRICS_REGISTRY) + @Bean(name = METRICS_REGISTRY_NAME) public MeterRegistry getMetricRegistry() { return new SimpleMeterRegistry(); } @@ -82,7 +81,7 @@ public class DistributionSummaryRouteTest { @Before public void setup() { - registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY, MeterRegistry.class); + registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY_NAME, MeterRegistry.class); } @After diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricComponentSpringTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricComponentSpringTest.java index 4f70933..5e3140d 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricComponentSpringTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MetricComponentSpringTest.java @@ -19,7 +19,6 @@ package org.apache.camel.component.micrometer; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.search.Search; import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; @@ -36,7 +35,6 @@ import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; - import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; @@ -62,7 +60,7 @@ public class MetricComponentSpringTest { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:in") .to("micrometer:counter:A?increment=512") .to("mock:out"); @@ -70,7 +68,7 @@ public class MetricComponentSpringTest { }; } - @Bean(name = MicrometerComponent.METRICS_REGISTRY) + @Bean(name = MicrometerComponent.METRICS_REGISTRY_NAME) public MeterRegistry getMetricRegistry() { return Mockito.mock(MeterRegistry.class); } @@ -78,7 +76,7 @@ public class MetricComponentSpringTest { @Test public void testMetricsRegistryFromCamelRegistry() throws Exception { - MeterRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY, MeterRegistry.class); + MeterRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY_NAME, MeterRegistry.class); Counter mockCounter = Mockito.mock(Counter.class); InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter); when(mockRegistry.counter(MicrometerConstants.HEADER_PREFIX + "." + "A", Tags.empty())).thenReturn(mockCounter); 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 index a670559..f9df5fb 100644 --- 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 @@ -17,16 +17,14 @@ 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() throws Exception { + 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/MicrometerComponentRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentRouteTest.java index 718ecdf..b3b95dc 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/MicrometerComponentRouteTest.java @@ -19,7 +19,6 @@ package org.apache.camel.component.micrometer; import java.util.Date; import java.util.HashMap; import java.util.Map; - import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; @@ -27,10 +26,6 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; -import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_HISTOGRAM_VALUE; -import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_METRIC_NAME; -import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_PREFIX; - public class MicrometerComponentRouteTest extends CamelTestSupport { @Produce(uri = "direct:start-1") @@ -63,7 +58,7 @@ public class MicrometerComponentRouteTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override public void configure() { 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 0b826f0..d25e18e 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,7 +20,6 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; - import io.micrometer.core.instrument.MeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; @@ -34,7 +33,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -74,7 +72,7 @@ public class MicrometerComponentTest { when(camelContext.getRegistry()).thenReturn(camelRegistry); when(camelContext.getTypeConverter()).thenReturn(typeConverter); when(typeConverter.convertTo(String.class, "key=value")).thenReturn("key=value"); - when(camelRegistry.lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY, MeterRegistry.class)).thenReturn(metricRegistry); + when(camelRegistry.lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY_NAME, MeterRegistry.class)).thenReturn(metricRegistry); Map<String, Object> params = new HashMap<>(); params.put("tags", "key=value"); @@ -85,7 +83,7 @@ public class MicrometerComponentTest { assertThat(me.getMetricsName(), is(MicrometerConstants.HEADER_PREFIX + "." + "counter")); assertThat(me.getRegistry(), is(metricRegistry)); inOrder.verify(camelContext, times(1)).getRegistry(); - inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY, MeterRegistry.class); + inOrder.verify(camelRegistry, times(1)).lookupByNameAndType(MicrometerComponent.METRICS_REGISTRY_NAME, MeterRegistry.class); inOrder.verify(camelContext, times(1)).getTypeConverter(); inOrder.verify(typeConverter, times(1)).convertTo(String.class, "key=value"); inOrder.verify(camelContext, times(1)).getTypeConverter(); @@ -160,7 +158,7 @@ public class MicrometerComponentTest { @Test public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() { when(camelRegistry.lookupByNameAndType("name", MeterRegistry.class)).thenReturn(null); - when(camelRegistry.findByType(MeterRegistry.class)).thenReturn(Collections.<MeterRegistry>emptySet()); + when(camelRegistry.findByType(MeterRegistry.class)).thenReturn(Collections.emptySet()); MeterRegistry result = component.getOrCreateMeterRegistry(camelRegistry, "name"); assertThat(result, is(notNullValue())); assertThat(result, is(not(metricRegistry))); 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 6a27ea3..2588a66 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,8 +16,13 @@ */ package org.apache.camel.component.micrometer; +import java.util.Collections; import io.micrometer.core.instrument.MeterRegistry; -import org.apache.camel.*; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.RuntimeCamelException; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -26,9 +31,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -54,10 +56,10 @@ public class MicrometerEndpointTest { private InOrder inOrder; @Before - public void setUp() throws Exception { + public void setUp() { endpoint = new MicrometerEndpoint(null, null, registry, MetricsType.COUNTER, METRICS_NAME, Collections.emptyList()) { @Override - public Producer createProducer() throws Exception { + public Producer createProducer() { return null; } @@ -70,12 +72,12 @@ public class MicrometerEndpointTest { } @After - public void tearDown() throws Exception { + public void tearDown() { inOrder.verifyNoMoreInteractions(); } @Test - public void testAbstractMetricsEndpoint() throws Exception { + public void testAbstractMetricsEndpoint() { assertThat(endpoint.getMetricsName(), is(METRICS_NAME)); assertThat(endpoint.getRegistry(), is(registry)); } @@ -86,17 +88,17 @@ public class MicrometerEndpointTest { } @Test - public void testIsSingleton() throws Exception { + public void testIsSingleton() { assertThat(endpoint.isSingleton(), is(true)); } @Test - public void testGetRegistry() throws Exception { + public void testGetRegistry() { assertThat(endpoint.getRegistry(), is(registry)); } @Test - public void testGetMetricsName() throws Exception { + public void testGetMetricsName() { assertThat(endpoint.getMetricsName(), is(METRICS_NAME)); } } 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 b043877..bdd811d 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 java.util.Collections; import io.micrometer.core.instrument.MeterRegistry; import org.apache.camel.Producer; import org.junit.After; @@ -26,9 +27,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerProducerTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerProducerTest.java index 97856b7..70960fb 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerProducerTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerProducerTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,7 +16,12 @@ */ package org.apache.camel.component.micrometer; -import io.micrometer.core.instrument.*; +import java.util.Collections; +import io.micrometer.core.instrument.Clock; +import io.micrometer.core.instrument.Meter; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.instrument.Timer; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.junit.Before; @@ -24,11 +29,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Collections; - import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_TIMER_ACTION; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; @@ -65,20 +69,20 @@ public class TimerProducerTest { private TimerProducer producer; @Before - public void setUp() throws Exception { + public void setUp() { producer = new TimerProducer(endpoint); when(endpoint.getRegistry()).thenReturn(registry); when(exchange.getIn()).thenReturn(in); } @Test - public void testTimerProducer() throws Exception { + public void testTimerProducer() { assertThat(producer, is(notNullValue())); assertThat(producer.getEndpoint().equals(endpoint), is(true)); } @Test - public void testProcessStart() throws Exception { + public void testProcessStart() { when(endpoint.getAction()).thenReturn(MicrometerTimerAction.start); when(in.getHeader(HEADER_TIMER_ACTION, MicrometerTimerAction.start, MicrometerTimerAction.class)).thenReturn(MicrometerTimerAction.start); when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(null); @@ -88,7 +92,7 @@ public class TimerProducerTest { } @Test - public void testProcessStopWithOverride() throws Exception { + public void testProcessStopWithOverride() { when(endpoint.getAction()).thenReturn(MicrometerTimerAction.stop); when(in.getHeader(HEADER_TIMER_ACTION, MicrometerTimerAction.stop, MicrometerTimerAction.class)).thenReturn(MicrometerTimerAction.start); when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(null); @@ -99,7 +103,7 @@ public class TimerProducerTest { @Test - public void testProcessNoActionOverride() throws Exception { + public void testProcessNoActionOverride() { Object action = null; when(endpoint.getAction()).thenReturn(null); when(in.getHeader(HEADER_TIMER_ACTION, action, MicrometerTimerAction.class)).thenReturn(MicrometerTimerAction.start); @@ -110,7 +114,7 @@ public class TimerProducerTest { } @Test - public void testProcessStartWithOverride() throws Exception { + public void testProcessStartWithOverride() { when(endpoint.getAction()).thenReturn(MicrometerTimerAction.start); when(in.getHeader(HEADER_TIMER_ACTION, MicrometerTimerAction.start, MicrometerTimerAction.class)).thenReturn(MicrometerTimerAction.stop); when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(sample); @@ -124,7 +128,7 @@ public class TimerProducerTest { } @Test - public void testProcessStop() throws Exception { + public void testProcessStop() { when(endpoint.getAction()).thenReturn(MicrometerTimerAction.stop); when(in.getHeader(HEADER_TIMER_ACTION, MicrometerTimerAction.stop, MicrometerTimerAction.class)).thenReturn(MicrometerTimerAction.stop); when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(sample); @@ -138,25 +142,25 @@ public class TimerProducerTest { } @Test - public void testProcessNoAction() throws Exception { + public void testProcessNoAction() { when(endpoint.getAction()).thenReturn(null); producer.doProcess(exchange, METRICS_NAME, Tags.empty()); } @Test - public void testGetPropertyName() throws Exception { + public void testGetPropertyName() { assertThat(producer.getPropertyName(METRICS_NAME), is("timer" + ":" + METRICS_NAME)); } @Test - public void testGetTimerContextFromExchange() throws Exception { + public void testGetTimerContextFromExchange() { when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(sample); assertThat(producer.getTimerSampleFromExchange(exchange, PROPERTY_NAME), is(sample)); } @Test - public void testGetTimerContextFromExchangeNotFound() throws Exception { + public void testGetTimerContextFromExchangeNotFound() { when(exchange.getProperty(PROPERTY_NAME, Timer.Sample.class)).thenReturn(null); assertThat(producer.getTimerSampleFromExchange(exchange, PROPERTY_NAME), is(nullValue())); } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerRouteTest.java index d04a7c1..0a465b4 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/TimerRouteTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,7 @@ */ package org.apache.camel.component.micrometer; +import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; @@ -35,10 +36,7 @@ import org.junit.runner.RunWith; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; - -import java.util.concurrent.TimeUnit; - -import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY; +import static org.apache.camel.component.micrometer.MicrometerComponent.METRICS_REGISTRY_NAME; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_METRIC_NAME; import static org.apache.camel.component.micrometer.MicrometerConstants.HEADER_TIMER_ACTION; import static org.junit.Assert.assertEquals; @@ -74,7 +72,7 @@ public class TimerRouteTest { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:in-1") .setHeader(HEADER_METRIC_NAME, constant("B")) .to("micrometer:timer:A?action=start") @@ -100,7 +98,7 @@ public class TimerRouteTest { }; } - @Bean(name = METRICS_REGISTRY) + @Bean(name = METRICS_REGISTRY_NAME) public MeterRegistry getMetricRegistry() { return new SimpleMeterRegistry(); } @@ -108,7 +106,7 @@ public class TimerRouteTest { @Before public void setup() { - registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY, MeterRegistry.class); + registry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(METRICS_REGISTRY_NAME, MeterRegistry.class); } @After 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 0675e27..3480c1b 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 @@ -17,7 +17,6 @@ package org.apache.camel.component.micrometer.messagehistory; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; @@ -74,10 +73,10 @@ public class ExceptionRouteMicrometerMessageHistoryTest extends CamelTestSupport } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { onException(Exception.class) .routeId("ExceptionRoute") .log("Exception received.") @@ -88,11 +87,8 @@ public class ExceptionRouteMicrometerMessageHistoryTest extends CamelTestSupport from("seda:bar") .to("mock:bar").id("bar") - .process(new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - throw new Exception("Metrics Exception"); - } + .process(exchange -> { + throw new Exception("Metrics Exception"); }) .to("mock:baz").id("baz"); } diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ManagedMessageHistoryTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ManagedMessageHistoryTest.java index 5883d1e..8dd8ce3 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ManagedMessageHistoryTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/ManagedMessageHistoryTest.java @@ -19,9 +19,7 @@ package org.apache.camel.component.micrometer.messagehistory; import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; - import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; @@ -49,7 +47,7 @@ public class ManagedMessageHistoryTest extends CamelTestSupport { @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); - registry.bind(MicrometerComponent.METRICS_REGISTRY, registry); + registry.bind(MicrometerComponent.METRICS_REGISTRY_NAME, registry); return registry; } @@ -119,10 +117,10 @@ public class ManagedMessageHistoryTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("seda:foo") .to("mock:foo").id("foo"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryTest.java index 93b9d18..7f28464 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/messagehistory/MicrometerMessageHistoryTest.java @@ -17,7 +17,6 @@ package org.apache.camel.component.micrometer.messagehistory; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; @@ -72,10 +71,10 @@ public class MicrometerMessageHistoryTest extends CamelTestSupport { } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("seda:foo") .to("mock:foo").id("foo"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/AbstractMicrometerRoutePolicyTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/AbstractMicrometerRoutePolicyTest.java index f545c10..446606f 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/AbstractMicrometerRoutePolicyTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/AbstractMicrometerRoutePolicyTest.java @@ -1,16 +1,28 @@ +/** + * 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.routepolicy; import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.apache.camel.CamelContext; import org.apache.camel.component.micrometer.MicrometerComponent; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.junit4.CamelTestSupport; -/** - * @author Christian Ohr - */ public class AbstractMicrometerRoutePolicyTest extends CamelTestSupport { protected MeterRegistry registry = new SimpleMeterRegistry(); @@ -23,7 +35,7 @@ public class AbstractMicrometerRoutePolicyTest extends CamelTestSupport { @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); - registry.bind(MicrometerComponent.METRICS_REGISTRY, this.registry); + registry.bind(MicrometerComponent.METRICS_REGISTRY_NAME, this.registry); return registry; } 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 8b97a76..b202e18 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 @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,16 +16,15 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.List; +import java.util.Set; +import javax.management.MBeanServer; +import javax.management.ObjectName; import io.micrometer.core.instrument.Meter; import org.apache.camel.builder.RouteBuilder; import org.junit.Ignore; import org.junit.Test; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import java.util.List; -import java.util.Set; - @Ignore public class ManagedMicrometerRoutePolicyTest extends AbstractMicrometerRoutePolicyTest { @@ -68,10 +67,10 @@ public class ManagedMicrometerRoutePolicyTest extends AbstractMicrometerRoutePol } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("seda:foo").routeId("foo") .to("micrometer:counter:test") .to("mock:result"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyMulticastSubRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyMulticastSubRouteTest.java index 970afdd..0dffcc4 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyMulticastSubRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyMulticastSubRouteTest.java @@ -16,13 +16,12 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.List; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Timer; import org.apache.camel.builder.RouteBuilder; import org.junit.Test; -import java.util.List; - /** * CAMEL-9226 - check metrics are counted correctly in multicast sub-routes */ @@ -50,10 +49,10 @@ public class MicrometerRoutePolicyMulticastSubRouteTest extends AbstractMicromet } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:foo").routeId("foo").to("mock:foo"); from("direct:bar").routeId("bar").multicast().to("mock:bar1", "mock:bar2"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicySubRouteTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicySubRouteTest.java index 6e2c45e..cc18dc8 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicySubRouteTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicySubRouteTest.java @@ -16,14 +16,12 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.List; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Timer; import org.apache.camel.builder.RouteBuilder; import org.junit.Test; -import java.util.List; -import java.util.concurrent.TimeUnit; - public class MicrometerRoutePolicySubRouteTest extends AbstractMicrometerRoutePolicyTest { @Test @@ -42,10 +40,10 @@ public class MicrometerRoutePolicySubRouteTest extends AbstractMicrometerRoutePo } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("direct:foo").routeId("foo") .to("direct:bar") .to("mock:foo"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyTest.java index e88abcd..7aefbbc 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/routepolicy/MicrometerRoutePolicyTest.java @@ -16,13 +16,12 @@ */ package org.apache.camel.component.micrometer.routepolicy; +import java.util.List; import io.micrometer.core.instrument.Meter; import io.micrometer.core.instrument.Timer; import org.apache.camel.builder.RouteBuilder; import org.junit.Test; -import java.util.List; - public class MicrometerRoutePolicyTest extends AbstractMicrometerRoutePolicyTest { @Test @@ -46,10 +45,10 @@ public class MicrometerRoutePolicyTest extends AbstractMicrometerRoutePolicyTest } @Override - protected RouteBuilder createRouteBuilder() throws Exception { + protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @Override - public void configure() throws Exception { + public void configure() { from("seda:foo").routeId("foo") .to("mock:result"); diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactoryTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactoryTest.java index ab0e770..9094244 100644 --- a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactoryTest.java +++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/spi/InstrumentedThreadPoolFactoryTest.java @@ -5,9 +5,9 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * 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. @@ -16,6 +16,10 @@ */ package org.apache.camel.component.micrometer.spi; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.internal.TimedExecutorService; @@ -30,16 +34,10 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; @RunWith(MockitoJUnitRunner.class) @@ -84,7 +82,7 @@ public class InstrumentedThreadPoolFactoryTest { } @Test - public void testNewCachedThreadPool() throws Exception { + public void testNewCachedThreadPool() { final ExecutorService executorService = instrumentedThreadPoolFactory.newCachedThreadPool(threadFactory); assertThat(executorService, is(notNullValue())); assertThat(executorService, is(instanceOf(TimedExecutorService.class))); @@ -95,7 +93,7 @@ public class InstrumentedThreadPoolFactoryTest { } @Test - public void testNewThreadPool() throws Exception { + public void testNewThreadPool() { final ExecutorService executorService = instrumentedThreadPoolFactory.newThreadPool(profile, threadFactory); assertThat(executorService, is(notNullValue())); assertThat(executorService, is(instanceOf(TimedExecutorService.class))); @@ -105,7 +103,7 @@ public class InstrumentedThreadPoolFactoryTest { } @Test - public void testNewScheduledThreadPool() throws Exception { + public void testNewScheduledThreadPool() { final ScheduledExecutorService scheduledExecutorService = instrumentedThreadPoolFactory.newScheduledThreadPool(profile, threadFactory); assertThat(scheduledExecutorService, is(notNullValue())); diff --git a/parent/pom.xml b/parent/pom.xml index b940e4e..1b8c208 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -494,7 +494,7 @@ <maven-war-plugin-version>3.0.0</maven-war-plugin-version> <mchange-commons-java-version>0.2.11</mchange-commons-java-version> <metrics-version>3.2.6</metrics-version> - <micrometer-version>1.0.2</micrometer-version> + <micrometer-version>1.0.3</micrometer-version> <milo-version>0.2.1</milo-version> <mina-bundle-version>1.1.7_6</mina-bundle-version> <mina-version>1.1.7</mina-version> -- To stop receiving notification emails like this one, please contact acosent...@apache.org.