All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.faulttolerance.standalone.MicrometerAdapter Maven / Gradle / Ivy

There is a newer version: 6.4.1
Show newest version
package io.smallrye.faulttolerance.standalone;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.micrometer.core.instrument.MeterRegistry;
import io.smallrye.faulttolerance.core.metrics.MeteredOperation;
import io.smallrye.faulttolerance.core.metrics.MetricsConstants;
import io.smallrye.faulttolerance.core.metrics.MetricsProvider;
import io.smallrye.faulttolerance.core.metrics.MetricsRecorder;
import io.smallrye.faulttolerance.core.metrics.MicrometerRecorder;
import io.smallrye.faulttolerance.core.timer.Timer;

public final class MicrometerAdapter implements MetricsAdapter {
    private final MeterRegistry registry;

    public MicrometerAdapter(MeterRegistry registry) {
        this.registry = registry;
    }

    MetricsProvider createMetricsProvider(Timer timer) {
        registry.gauge(MetricsConstants.TIMER_SCHEDULED, timer, Timer::countScheduledTasks);

        return new MetricsProvider() {
            private final Map cache = new ConcurrentHashMap<>();

            @Override
            public boolean isEnabled() {
                return true;
            }

            @Override
            public MetricsRecorder create(MeteredOperation operation) {
                return cache.computeIfAbsent(operation.cacheKey(),
                        ignored -> new MicrometerRecorder(registry, operation));
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy