Skip to content

Commit

Permalink
Merge pull request #789 from rhusar/metrics
Browse files Browse the repository at this point in the history
Allow FaultToleranceExtension to switch metrics integration provider.
  • Loading branch information
Ladicek authored Mar 2, 2023
2 parents b86ad41 + 6f6ef4c commit ff86e60
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -83,6 +86,15 @@ public class FaultToleranceExtension implements Extension {
private final ConcurrentMap<String, FaultToleranceOperation> faultToleranceOperations = new ConcurrentHashMap<>();

private final ConcurrentMap<String, Set<String>> 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"));
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit ff86e60

Please sign in to comment.