Search in sources :

Example 11 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project spring-boot by spring-projects.

the class MetricsAutoConfigurationTests method configuresMeterRegistries.

@SuppressWarnings("unchecked")
@Test
void configuresMeterRegistries() {
    this.contextRunner.withUserConfiguration(MeterRegistryConfiguration.class).run((context) -> {
        MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
        MeterFilter[] filters = (MeterFilter[]) ReflectionTestUtils.getField(meterRegistry, "filters");
        assertThat(filters).hasSize(3);
        assertThat(filters[0].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.DENY);
        assertThat(filters[1]).isInstanceOf(PropertiesMeterFilter.class);
        assertThat(filters[2].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.ACCEPT);
        then((MeterBinder) context.getBean("meterBinder")).should().bindTo(meterRegistry);
        then(context.getBean(MeterRegistryCustomizer.class)).should().customize(meterRegistry);
    });
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 12 with MeterFilter

use of io.micrometer.core.instrument.config.MeterFilter in project spring-boot by spring-projects.

the class WebFluxMetricsAutoConfiguration method metricsHttpServerUriTagFilter.

@Bean
@Order(0)
public MeterFilter metricsHttpServerUriTagFilter() {
    String metricName = this.properties.getWeb().getServer().getRequest().getMetricName();
    MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(() -> String.format("Reached the maximum number of URI tags for '%s'.", metricName));
    return MeterFilter.maximumAllowableTags(metricName, "uri", this.properties.getWeb().getServer().getMaxUriTags(), filter);
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) OnlyOnceLoggingDenyMeterFilter(org.springframework.boot.actuate.autoconfigure.metrics.OnlyOnceLoggingDenyMeterFilter) OnlyOnceLoggingDenyMeterFilter(org.springframework.boot.actuate.autoconfigure.metrics.OnlyOnceLoggingDenyMeterFilter) Order(org.springframework.core.annotation.Order) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 13 with MeterFilter

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

the class MeterFilterTest method renameTags.

@Test
@Issue("#329")
void renameTags() {
    MeterFilter filter = MeterFilter.renameTag("hystrix", "group", "hystrixgroup");
    Meter.Id id = new Meter.Id("hystrix.something", Tags.of("k", "v", "group", "mygroup"), null, null, Meter.Type.GAUGE);
    assertThat(filter.map(id)).has(tag("hystrixgroup", "mygroup"));
    Meter.Id id2 = new Meter.Id("something.else", Tags.of("group", "mygroup"), null, null, Meter.Type.GAUGE);
    assertThat(filter.map(id2)).has(tag("group", "mygroup"));
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Issue(io.micrometer.core.Issue) Test(org.junit.jupiter.api.Test)

Example 14 with MeterFilter

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

the class MeterFilterTest method replaceTagValues.

@Test
void replaceTagValues() {
    MeterFilter filter = MeterFilter.replaceTagValues("status", s -> s.charAt(0) + "xx", "200");
    Meter.Id id = new Meter.Id("name", Tags.of("status", "400"), null, null, Meter.Type.COUNTER);
    Meter.Id filteredId = filter.map(id);
    assertThat(filteredId).has(tag("status", "4xx"));
    id = new Meter.Id("name", Tags.of("status", "200"), null, null, Meter.Type.COUNTER);
    filteredId = filter.map(id);
    assertThat(filteredId).has(tag("status", "200"));
}
Also used : MeterFilter(io.micrometer.core.instrument.config.MeterFilter) Test(org.junit.jupiter.api.Test)

Example 15 with MeterFilter

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

the class MeterFilterTest method minExpectedOnTimer.

@Test
void minExpectedOnTimer() {
    MeterFilter filter = MeterFilter.minExpected("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.getMinimumExpectedValue()).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