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 e64f5cf2b5af0f29e71c8d7da09d667bd2c54985 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Mon Nov 25 14:22:39 2019 +0100 Remove MicroProfile Metrics extension workarounds #319 --- .../runtime/CamelMicroProfileMetricsRecorder.java | 22 ++-- .../patch/CamelQuarkusAtomicIntegerGauge.java | 45 ------- ...usMicroProfileMetricsExchangeEventNotifier.java | 74 ----------- ...arkusMicroProfileMetricsRouteEventNotifier.java | 105 --------------- ...CamelQuarkusMicroProfileMetricsRoutePolicy.java | 142 --------------------- ...arkusMicroProfileMetricsRoutePolicyFactory.java | 39 ------ ...QurakusMicroProfileMetricsExchangeRecorder.java | 71 ----------- 7 files changed, 11 insertions(+), 487 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 6d19cf0..6120855 100644 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java +++ b/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/CamelMicroProfileMetricsRecorder.java @@ -16,20 +16,20 @@ */ package org.apache.camel.quarkus.component.microprofile.metrics.runtime; -import io.quarkus.arc.runtime.BeanContainer; -import io.quarkus.runtime.RuntimeValue; -import io.quarkus.runtime.annotations.Recorder; -import io.smallrye.metrics.MetricRegistries; - import org.apache.camel.CamelContext; import org.apache.camel.component.microprofile.metrics.event.notifier.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.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.component.microprofile.metrics.route.policy.MicroProfileMetricsRoutePolicyFactory; import org.apache.camel.spi.ManagementStrategy; import org.eclipse.microprofile.metrics.MetricRegistry; +import io.quarkus.arc.runtime.BeanContainer; +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import io.smallrye.metrics.MetricRegistries; + @Recorder public class CamelMicroProfileMetricsRecorder { @@ -42,7 +42,7 @@ public class CamelMicroProfileMetricsRecorder { ManagementStrategy managementStrategy = camelContext.getManagementStrategy(); if (config.enableRoutePolicy) { - camelContext.addRoutePolicyFactory(new CamelQuarkusMicroProfileMetricsRoutePolicyFactory()); + camelContext.addRoutePolicyFactory(new MicroProfileMetricsRoutePolicyFactory()); } if (config.enableMessageHistory) { @@ -51,11 +51,11 @@ public class CamelMicroProfileMetricsRecorder { } if (config.enableExchangeEventNotifier) { - managementStrategy.addEventNotifier(new CamelQuarkusMicroProfileMetricsExchangeEventNotifier()); + managementStrategy.addEventNotifier(new MicroProfileMetricsExchangeEventNotifier()); } if (config.enableRouteEventNotifier) { - managementStrategy.addEventNotifier(new CamelQuarkusMicroProfileMetricsRouteEventNotifier()); + managementStrategy.addEventNotifier(new MicroProfileMetricsRouteEventNotifier()); } 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 deleted file mode 100644 index 6c584e9..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusAtomicIntegerGauge.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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 deleted file mode 100644 index 6c47568..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsExchangeEventNotifier.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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 deleted file mode 100644 index 73bf4c1..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRouteEventNotifier.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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 deleted file mode 100644 index fbfbc25..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicy.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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 deleted file mode 100644 index 7a4773d..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQuarkusMicroProfileMetricsRoutePolicyFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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 deleted file mode 100644 index 085f771..0000000 --- a/extensions/microprofile-metrics/runtime/src/main/java/org/apache/camel/quarkus/component/microprofile/metrics/runtime/patch/CamelQurakusMicroProfileMetricsExchangeRecorder.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.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(); - } -}