Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FaultToleranceExtension to switch metrics integration provider. #789

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}