Search in sources :

Example 1 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.

the class MeterRegistryTest method histogramConfigTransformingMeterFilter.

@Test
void histogramConfigTransformingMeterFilter() {
    MeterRegistry registry = new SimpleMeterRegistry() {

        @Override
        protected Timer newTimer(@Nonnull Meter.Id id, DistributionStatisticConfig histogramConfig, PauseDetector pauseDetector) {
            assertThat(histogramConfig.isPublishingHistogram()).isTrue();
            return super.newTimer(id, histogramConfig, pauseDetector);
        }
    };
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public DistributionStatisticConfig configure(Meter.Id mappedId, DistributionStatisticConfig config) {
            return DistributionStatisticConfig.builder().percentiles(0.95).percentilesHistogram(true).build().merge(config);
        }
    });
    registry.timer("my.timer");
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Nonnull(javax.annotation.Nonnull) PauseDetector(io.micrometer.core.instrument.distribution.pause.PauseDetector) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.

the class MeterRegistryTest method acceptMeterFilter.

@Test
void acceptMeterFilter() {
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public MeterFilterReply accept(Meter.Id id) {
            return id.getName().contains("jvm") ? MeterFilterReply.DENY : MeterFilterReply.NEUTRAL;
        }
    });
    assertThat(registry.counter("jvm.my.counter")).isInstanceOf(NoopCounter.class);
    assertThat(registry.counter("my.counter")).isNotInstanceOf(NoopCounter.class);
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) MeterFilterReply(io.micrometer.core.instrument.config.MeterFilterReply) Test(org.junit.jupiter.api.Test)

Example 3 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.

the class TimedAspectTest method serviceIsTimedWithHistogram.

@Test
public void serviceIsTimedWithHistogram() {
    // given...
    // ... we are waiting for a metric to be created with a histogram
    AtomicReference<DistributionStatisticConfig> myConfig = new AtomicReference<>();
    registry.config().meterFilter(new MeterFilter() {

        @Override
        public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
            if (id.getName().equals("something")) {
                myConfig.set(config);
            }
            return config;
        }
    });
    // when...
    // ... the service is being called
    service.timeWithHistogram();
    // then...
    assertThat(myConfig.get()).as("the metric has been created").isNotNull();
    assertThat(myConfig.get().isPublishingHistogram()).as("the metric has a histogram").isTrue();
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Meter(io.micrometer.core.instrument.Meter) AtomicReference(java.util.concurrent.atomic.AtomicReference) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig) Test(org.junit.Test)

Example 4 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.

the class MeterRegistry method registerMeterIfNecessary.

private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.Id id, @Nullable DistributionStatisticConfig config, BiFunction<Meter.Id, DistributionStatisticConfig, Meter> builder, Function<Meter.Id, M> noopBuilder) {
    Meter.Id mappedId = id;
    for (MeterFilter filter : filters) {
        mappedId = filter.map(mappedId);
    }
    if (!accept(id)) {
        // noinspection unchecked
        return noopBuilder.apply(id);
    }
    if (config != null) {
        for (MeterFilter filter : filters) {
            DistributionStatisticConfig filteredConfig = filter.configure(mappedId, config);
            if (filteredConfig != null) {
                config = filteredConfig;
            }
        }
    }
    Meter m = getOrCreateMeter(config, builder, mappedId, noopBuilder);
    if (!meterClass.isInstance(m)) {
        throw new IllegalArgumentException("There is already a registered meter of a different type with the same name");
    }
    // noinspection unchecked
    return (M) m;
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Id(io.micrometer.core.instrument.Meter.Id) DistributionStatisticConfig(io.micrometer.core.instrument.distribution.DistributionStatisticConfig)

Example 5 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project micrometer by micrometer-metrics.

the class MeterFilterTest method maxExpectedOnTimer.

@Test
void maxExpectedOnTimer() {
    MeterFilter filter = MeterFilter.maxExpected("name", Duration.ofNanos(100));
    Meter.Id timer = new Meter.Id("name", emptyList(), null, null, Meter.Type.TIMER);
    assertThat(filter.configure(timer, DistributionStatisticConfig.DEFAULT)).satisfies(conf -> assertThat(conf.getMaximumExpectedValue()).isEqualTo(100));
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Test(org.junit.jupiter.api.Test)

Aggregations

MeterFilter (io.micrometer.core.instrument.config.MeterFilter)20 Test (org.junit.jupiter.api.Test)14 Bean (org.springframework.context.annotation.Bean)4 DistributionStatisticConfig (io.micrometer.core.instrument.distribution.DistributionStatisticConfig)3 OnlyOnceLoggingDenyMeterFilter (org.springframework.boot.actuate.autoconfigure.metrics.OnlyOnceLoggingDenyMeterFilter)3 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)3 Order (org.springframework.core.annotation.Order)3 Meter (io.micrometer.core.instrument.Meter)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 MeterFilterReply (io.micrometer.core.instrument.config.MeterFilterReply)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpStatus (com.linecorp.armeria.common.HttpStatus)1 MediaType (com.linecorp.armeria.common.MediaType)1 ServerCacheControl (com.linecorp.armeria.common.ServerCacheControl)1 HttpService (com.linecorp.armeria.server.HttpService)1 RedirectService (com.linecorp.armeria.server.RedirectService)1 FileService (com.linecorp.armeria.server.file.FileService)1