From 6f6ef4cde62e69625905b3590887cd64c46525d0 Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Thu, 2 Mar 2023 14:06:44 +0100 Subject: [PATCH] Allow FaultToleranceExtension to switch metrics integration provider. --- .../FaultToleranceExtension.java | 26 +++++++++++++++++-- .../metrics/MetricsIntegration.java | 17 ++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/metrics/MetricsIntegration.java diff --git a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java index d5e747e9..4c380986 100644 --- a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java +++ b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java @@ -68,7 +68,10 @@ import io.smallrye.faulttolerance.config.FaultToleranceMethods; import io.smallrye.faulttolerance.config.FaultToleranceOperation; import io.smallrye.faulttolerance.internal.StrategyCache; +import io.smallrye.faulttolerance.metrics.MetricsIntegration; import io.smallrye.faulttolerance.metrics.MicroProfileMetricsProvider; +import io.smallrye.faulttolerance.metrics.MicrometerProvider; +import io.smallrye.faulttolerance.metrics.NoopProvider; public class FaultToleranceExtension implements Extension { @@ -83,6 +86,15 @@ public class FaultToleranceExtension implements Extension { private final ConcurrentMap faultToleranceOperations = new ConcurrentHashMap<>(); private final ConcurrentMap> existingCircuitBreakerNames = new ConcurrentHashMap<>(); + private final MetricsIntegration metricsIntegration; + + public FaultToleranceExtension() { + this(MetricsIntegration.MICROPROFILE_METRICS); + } + + public FaultToleranceExtension(MetricsIntegration metricsIntegration) { + this.metricsIntegration = metricsIntegration; + } void registerInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager bm) { LOG.activated(getImplementationVersion().orElse("unknown")); @@ -112,8 +124,18 @@ void registerInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager DefaultFaultToleranceOperationProvider.class.getName()); bbd.addAnnotatedType(bm.createAnnotatedType(DefaultExistingCircuitBreakerNames.class), DefaultExistingCircuitBreakerNames.class.getName()); - bbd.addAnnotatedType(bm.createAnnotatedType(MicroProfileMetricsProvider.class), - MicroProfileMetricsProvider.class.getName()); + switch (metricsIntegration) { + case MICROPROFILE_METRICS: + bbd.addAnnotatedType(bm.createAnnotatedType(MicroProfileMetricsProvider.class), + MicroProfileMetricsProvider.class.getName()); + break; + case MICROMETER: + bbd.addAnnotatedType(bm.createAnnotatedType(MicrometerProvider.class), MicrometerProvider.class.getName()); + break; + case NOOP: + bbd.addAnnotatedType(bm.createAnnotatedType(NoopProvider.class), NoopProvider.class.getName()); + break; + } bbd.addAnnotatedType(bm.createAnnotatedType(StrategyCache.class), StrategyCache.class.getName()); bbd.addAnnotatedType(bm.createAnnotatedType(CircuitBreakerMaintenanceImpl.class), CircuitBreakerMaintenanceImpl.class.getName()); diff --git a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/metrics/MetricsIntegration.java b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/metrics/MetricsIntegration.java new file mode 100644 index 00000000..1ac490c9 --- /dev/null +++ b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/metrics/MetricsIntegration.java @@ -0,0 +1,17 @@ +package io.smallrye.faulttolerance.metrics; + +public enum MetricsIntegration { + + /** + * Metrics integration using {@link MicroProfileMetricsProvider}. + */ + MICROPROFILE_METRICS, + /** + * Metrics integration using {@link MicrometerProvider}. + */ + MICROMETER, + /** + * Metrics will be disabled using {@link NoopProvider}. + */ + NOOP, +}