This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 04d4487e5483c51c6321ebebef92066f3cb4518c Author: James Netherton <[email protected]> AuthorDate: Tue Oct 22 13:39:52 2019 +0100 Upgrade to quarkus 0.26.0 fixes #315 --- .../runtime/CamelMicroProfileMetricsRecorder.java | 12 +- .../patch/CamelQuarkusAtomicIntegerGauge.java | 45 +++++++ ...usMicroProfileMetricsExchangeEventNotifier.java | 74 +++++++++++ ...arkusMicroProfileMetricsRouteEventNotifier.java | 105 ++++++++++++++++ ...CamelQuarkusMicroProfileMetricsRoutePolicy.java | 139 +++++++++++++++++++++ ...arkusMicroProfileMetricsRoutePolicyFactory.java | 39 ++++++ ...QurakusMicroProfileMetricsExchangeRecorder.java | 71 +++++++++++ pom.xml | 2 +- 8 files changed, 480 insertions(+), 7 deletions(-) diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java index 9150cdc..314d5f3 100644 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java @@ -23,10 +23,10 @@ import io.smallrye.metrics.MetricRegistries; import org.apache.camel.CamelContext; import org.apache.camel.component.microprofile.metrics.event.notifier.context.MicroProfileMetricsCamelContextEventNotifier; -import org.apache.camel.component.microprofile.metrics.event.notifier.exchange.MicroProfileMetricsExchangeEventNotifier; -import org.apache.camel.component.microprofile.metrics.event.notifier.route.MicroProfileMetricsRouteEventNotifier; import org.apache.camel.component.microprofile.metrics.message.history.MicroProfileMetricsMessageHistoryFactory; -import org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyFactory; +import org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch.CamelQuarkusMicroProfileMetricsExchangeEventNotifier; +import org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch.CamelQuarkusMicroProfileMetricsRouteEventNotifier; +import org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch.CamelQuarkusMicroProfileMetricsRoutePolicyFactory; import org.apache.camel.spi.ManagementStrategy; import org.eclipse.microprofile.metrics.MetricRegistry; @@ -42,7 +42,7 @@ public class CamelMicroProfileMetricsRecorder { ManagementStrategy managementStrategy = camelContext.getManagementStrategy(); if (config.enableRoutePolicy) { - camelContext.addRoutePolicyFactory(new MicroProfileMetricsRoutePolicyFactory()); + camelContext.addRoutePolicyFactory(new CamelQuarkusMicroProfileMetricsRoutePolicyFactory()); } if (config.enableMessageHistory) { @@ -51,11 +51,11 @@ public class CamelMicroProfileMetricsRecorder { } if (config.enableExchangeEventNotifier) { - managementStrategy.addEventNotifier(new MicroProfileMetricsExchangeEventNotifier()); + managementStrategy.addEventNotifier(new CamelQuarkusMicroProfileMetricsExchangeEventNotifier()); } if (config.enableRouteEventNotifier) { - managementStrategy.addEventNotifier(new MicroProfileMetricsRouteEventNotifier()); + managementStrategy.addEventNotifier(new CamelQuarkusMicroProfileMetricsRouteEventNotifier()); } if (config.enableCamelContextEventNotifier) { diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusAtomicIntegerGauge.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusAtomicIntegerGauge.java new file mode 100644 index 0000000..6c584e9 --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusAtomicIntegerGauge.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.eclipse.microprofile.metrics.Gauge; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQuarkusAtomicIntegerGauge implements Gauge<Integer> { + + private final AtomicInteger gaugeValue = new AtomicInteger(); + + @Override + public Integer getValue() { + return gaugeValue.get(); + } + + public void increment() { + gaugeValue.incrementAndGet(); + } + + public void decrement() { + gaugeValue.decrementAndGet(); + } +} diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsExchangeEventNotifier.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsExchangeEventNotifier.java new file mode 100644 index 0000000..a495656 --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsExchangeEventNotifier.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsExchangeRecorder; +import org.apache.camel.component.microprofile.metrics.event.notifier.exchange.MicroProfileMetricsExchangeEventNotifier; +import org.apache.camel.spi.CamelEvent; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.Tag; +import org.eclipse.microprofile.metrics.Timer; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.CAMEL_CONTEXT_METRIC_NAME; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.CAMEL_CONTEXT_TAG; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQuarkusMicroProfileMetricsExchangeEventNotifier extends MicroProfileMetricsExchangeEventNotifier { + + private MicroProfileMetricsExchangeRecorder exchangeRecorder; + + @Override + protected void doStart() throws Exception { + super.doStart(); + CamelContext camelContext = getCamelContext(); + MetricRegistry metricRegistry = getMetricRegistry(); + Tag tag = new Tag(CAMEL_CONTEXT_TAG, camelContext.getName()); + + metricRegistry.removeMatching((metricID, metric) -> metricID.getName().startsWith(CAMEL_CONTEXT_METRIC_NAME)); + + exchangeRecorder = new CamelQurakusMicroProfileMetricsExchangeRecorder(metricRegistry, CAMEL_CONTEXT_METRIC_NAME, tag); + } + + @Override + protected void handleCreatedEvent(CamelEvent.ExchangeCreatedEvent createdEvent) { + String name = getNamingStrategy().getName(createdEvent.getExchange(), createdEvent.getExchange().getFromEndpoint()); + Tag[] tags = getNamingStrategy().getTags(createdEvent, createdEvent.getExchange().getFromEndpoint()); + Timer timer = getMetricRegistry().timer(name + ".processing", tags); + createdEvent.getExchange().setProperty("eventTimer:" + name, timer); + createdEvent.getExchange().setProperty("eventTimerContext:" + name, timer.time()); + this.exchangeRecorder.recordExchangeBegin(); + } + + @Override + protected void handleDoneEvent(CamelEvent.ExchangeEvent doneEvent) { + Exchange exchange = doneEvent.getExchange(); + String name = getNamingStrategy().getName(exchange, exchange.getFromEndpoint()); + exchange.removeProperty("eventTimer:" + name); + Timer.Context context = (Timer.Context)exchange.removeProperty("eventTimerContext:" + name); + if (context != null) { + context.stop(); + } + + this.exchangeRecorder.recordExchangeComplete(exchange); + } +} diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRouteEventNotifier.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRouteEventNotifier.java new file mode 100644 index 0000000..4d06c9b --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRouteEventNotifier.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.microprofile.metrics.event.notifier.route.MicroProfileMetricsRouteEventNotifier; +import org.apache.camel.component.microprofile.metrics.event.notifier.route.MicroProfileMetricsRouteEventNotifierNamingStrategy; +import org.apache.camel.spi.CamelEvent; +import org.eclipse.microprofile.metrics.Metadata; +import org.eclipse.microprofile.metrics.MetadataBuilder; +import org.eclipse.microprofile.metrics.Metric; +import org.eclipse.microprofile.metrics.MetricFilter; +import org.eclipse.microprofile.metrics.MetricID; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.MetricType; +import org.eclipse.microprofile.metrics.Tag; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.ROUTES_ADDED_DESCRIPTION; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.ROUTES_ADDED_DISPLAY_NAME; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.ROUTES_RUNNING_DESCRIPTION; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.ROUTES_RUNNING_DISPLAY_NAME; +import static org.apache.camel.spi.CamelEvent.Type.RouteAdded; +import static org.apache.camel.spi.CamelEvent.Type.RouteRemoved; +import static org.apache.camel.spi.CamelEvent.Type.RouteStarted; +import static org.apache.camel.spi.CamelEvent.Type.RouteStopped; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQuarkusMicroProfileMetricsRouteEventNotifier extends MicroProfileMetricsRouteEventNotifier { + + private CamelQuarkusAtomicIntegerGauge routesAdded = new CamelQuarkusAtomicIntegerGauge(); + private CamelQuarkusAtomicIntegerGauge routesRunning = new CamelQuarkusAtomicIntegerGauge(); + + @Override + protected void doStart() throws Exception { + super.doStart(); + + CamelContext camelContext = getCamelContext(); + MicroProfileMetricsRouteEventNotifierNamingStrategy namingStrategy = getNamingStrategy(); + + MetricRegistry metricRegistry = getMetricRegistry(); + Tag[] tags = namingStrategy.getTags(camelContext); + + String routeAddedName = namingStrategy.getRouteAddedName(); + String routeRunningName = namingStrategy.getRouteRunningName(); + + metricRegistry.removeMatching(new MetricFilter() { + @Override + public boolean matches(MetricID metricID, Metric metric) { + return metricID.getName().equals(routeAddedName) || metricID.getName().equals(routeRunningName); + } + }); + + Metadata routesAddedMetadata = new MetadataBuilder() + .withName(routeAddedName) + .withDisplayName(ROUTES_ADDED_DISPLAY_NAME) + .withDescription(ROUTES_ADDED_DESCRIPTION) + .withType(MetricType.GAUGE) + .build(); + + metricRegistry.register(routesAddedMetadata, routesAdded, tags); + + Metadata routesRunningMetadata = new MetadataBuilder() + .withName(routeRunningName) + .withDisplayName(ROUTES_RUNNING_DISPLAY_NAME) + .withDescription(ROUTES_RUNNING_DESCRIPTION) + .withType(MetricType.GAUGE) + .build(); + metricRegistry.register(routesRunningMetadata, routesRunning, tags); + } + + @Override + public void notify(CamelEvent event) throws Exception { + if (routesAdded == null || routesRunning == null) { + return; + } + + if (event.getType().equals(RouteAdded)) { + routesAdded.increment(); + } else if (event.getType().equals(RouteRemoved)) { + routesAdded.decrement(); + } else if (event.getType().equals(RouteStarted)) { + routesRunning.increment(); + } else if (event.getType().equals(RouteStopped)) { + routesRunning.decrement(); + } + } +} diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicy.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicy.java new file mode 100644 index 0000000..f3577cd --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicy.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import org.apache.camel.Exchange; +import org.apache.camel.NonManagedService; +import org.apache.camel.Route; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsExchangeRecorder; +import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsHelper; +import org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyNamingStrategy; +import org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyService; +import org.apache.camel.support.RoutePolicySupport; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.camel.util.ObjectHelper; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.Timer; +import org.eclipse.microprofile.metrics.Timer.Context; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.DEFAULT_CAMEL_ROUTE_POLICY_METRIC_NAME; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.PROCESSING_METRICS_SUFFIX; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQuarkusMicroProfileMetricsRoutePolicy extends RoutePolicySupport implements NonManagedService { + + private MetricRegistry metricRegistry; + private MetricsStatistics statistics; + private MicroProfileMetricsRoutePolicyNamingStrategy namingStrategy = MicroProfileMetricsRoutePolicyNamingStrategy.DEFAULT; + private MicroProfileMetricsExchangeRecorder exchangeRecorder; + + private static final class MetricsStatistics { + private final MetricRegistry metricRegistry; + private final Route route; + private final MicroProfileMetricsRoutePolicyNamingStrategy namingStrategy; + + private MetricsStatistics(MetricRegistry metricRegistry, Route route, MicroProfileMetricsRoutePolicyNamingStrategy namingStrategy) { + this.metricRegistry = ObjectHelper.notNull(metricRegistry, "metricRegistry", this); + this.namingStrategy = ObjectHelper.notNull(namingStrategy, "MicroProfileMetricsRoutePolicyNamingStrategy", this); + this.route = route; + } + + public void onExchangeBegin(Exchange exchange) { + String name = namingStrategy.getName(route); + Timer timer = metricRegistry.timer(name + PROCESSING_METRICS_SUFFIX, namingStrategy.getTags(route)); + exchange.setProperty(propertyName(exchange), timer.time()); + } + + public void onExchangeDone(Exchange exchange) { + Context context = (Context) exchange.removeProperty(propertyName(exchange)); + if (context != null) { + context.stop(); + } + } + + private String propertyName(Exchange exchange) { + return String.format("%s.%s.%s", DEFAULT_CAMEL_ROUTE_POLICY_METRIC_NAME, route.getId(), exchange.getExchangeId()); + } + } + + public MetricRegistry getMetricRegistry() { + return metricRegistry; + } + + public void setMetricRegistry(MetricRegistry metricRegistry) { + this.metricRegistry = metricRegistry; + } + + public MicroProfileMetricsRoutePolicyNamingStrategy getNamingStrategy() { + return namingStrategy; + } + + public void setNamingStrategy(MicroProfileMetricsRoutePolicyNamingStrategy namingStrategy) { + this.namingStrategy = namingStrategy; + } + + @Override + public void onInit(Route route) { + super.onInit(route); + MetricRegistry metricRegistry = getMetricRegistry(); + if (metricRegistry == null) { + metricRegistry = MicroProfileMetricsHelper.getMetricRegistry(route.getCamelContext()); + } + + exchangeRecorder = new CamelQurakusMicroProfileMetricsExchangeRecorder(metricRegistry, namingStrategy.getName(route), namingStrategy.getTags(route)); + + try { + MicroProfileMetricsRoutePolicyService registryService = route.getCamelContext().hasService(MicroProfileMetricsRoutePolicyService.class); + if (registryService == null) { + registryService = new MicroProfileMetricsRoutePolicyService(); + registryService.setMetricRegistry(metricRegistry); + route.getCamelContext().addService(registryService); + ServiceHelper.startService(registryService); + } + } catch (Exception e) { + throw RuntimeCamelException.wrapRuntimeCamelException(e); + } + statistics = new MetricsStatistics(metricRegistry, route, getNamingStrategy()); + } + + @Override + public void onExchangeBegin(Route route, Exchange exchange) { + if (statistics != null) { + statistics.onExchangeBegin(exchange); + } + + if (exchangeRecorder != null) { + exchangeRecorder.recordExchangeBegin(); + } + } + + @Override + public void onExchangeDone(Route route, Exchange exchange) { + if (statistics != null) { + statistics.onExchangeDone(exchange); + } + + if (exchangeRecorder != null) { + exchangeRecorder.recordExchangeComplete(exchange); + } + } +} diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicyFactory.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicyFactory.java new file mode 100644 index 0000000..7a4773d --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicyFactory.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import org.apache.camel.CamelContext; +import org.apache.camel.NamedNode; +import org.apache.camel.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyFactory; +import org.apache.camel.spi.RoutePolicy; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQuarkusMicroProfileMetricsRoutePolicyFactory extends MicroProfileMetricsRoutePolicyFactory { + + @Override + public RoutePolicy createRoutePolicy(CamelContext camelContext, String routeId, NamedNode routeDefinition) { + CamelQuarkusMicroProfileMetricsRoutePolicy answer = new CamelQuarkusMicroProfileMetricsRoutePolicy(); + answer.setMetricRegistry(getMetricRegistry()); + answer.setNamingStrategy(getNamingStrategy()); + return answer; + } +} diff --git a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQurakusMicroProfileMetricsExchangeRecorder.java b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQurakusMicroProfileMetricsExchangeRecorder.java new file mode 100644 index 0000000..2c7d8f8 --- /dev/null +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQurakusMicroProfileMetricsExchangeRecorder.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.component.microprofile.metrics.runtime.patch; + +import org.apache.camel.Exchange; +import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsExchangeRecorder; +import org.eclipse.microprofile.metrics.Metadata; +import org.eclipse.microprofile.metrics.MetadataBuilder; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.MetricType; +import org.eclipse.microprofile.metrics.Tag; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.EXCHANGES_INFLIGHT_DESCRIPTION; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.EXCHANGES_INFLIGHT_DISPLAY_NAME; +import static org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants.EXCHANGES_INFLIGHT_METRIC_NAME; + +/** + * Handle MicroProfile metrics API incompatibility between versions used + * by Camel <= 3.0.0 RC3 and Quarkus >= 0.26 + * + * TODO: Remove this when upgrading to Camel > 3.0.0 RC3 + */ +public class CamelQurakusMicroProfileMetricsExchangeRecorder extends MicroProfileMetricsExchangeRecorder { + + private CamelQuarkusAtomicIntegerGauge exchangesInflight = new CamelQuarkusAtomicIntegerGauge(); + + public CamelQurakusMicroProfileMetricsExchangeRecorder(MetricRegistry metricRegistry, String metricName, Tag... tags) { + super(metricRegistry, metricName, tags); + } + + @Override + protected void configureMetrics(MetricRegistry metricRegistry, String metricName, Tag... tags) { + super.configureMetrics(metricRegistry, metricName, tags); + + Metadata exchangesInflightMetadata = new MetadataBuilder() + .withName(metricName + EXCHANGES_INFLIGHT_METRIC_NAME) + .withDisplayName(EXCHANGES_INFLIGHT_DISPLAY_NAME) + .withDescription(EXCHANGES_INFLIGHT_DESCRIPTION) + .withType(MetricType.GAUGE) + .build(); + + metricRegistry.remove(exchangesInflightMetadata.getName()); + + this.exchangesInflight = metricRegistry.register(exchangesInflightMetadata, new CamelQuarkusAtomicIntegerGauge(), tags); + } + + @Override + public void recordExchangeBegin() { + super.recordExchangeBegin(); + exchangesInflight.increment(); + } + + @Override + public void recordExchangeComplete(Exchange exchange) { + super.recordExchangeComplete(exchange); + exchangesInflight.decrement(); + } +} diff --git a/pom.xml b/pom.xml index e8a1673..f652622 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <camel.version>3.0.0-SNAPSHOT</camel.version> - <quarkus.version>0.25.0</quarkus.version> + <quarkus.version>0.26.0</quarkus.version> <jetty.version>9.4.18.v20190429</jetty.version> <xstream.version>1.4.11</xstream.version>
