3

Is there a way to configure distribution statistic expiry and buffer length for http.server.requests metrics?

I need to increase the expiry and couldn't find the proper way of doing this with spring boot actuator. Is it possible to configure these settings?

Ivan Nakov
  • 414
  • 6
  • 9
  • Please add more details and share what you have tried if any – Romil Patel Mar 27 '19 at 08:37
  • The micrometer timers have the ability to increase `distributionStatisticExpiry` and `distributionStatisticBufferLength` but I can't find a way to set these settings for my percentiles in spring-boot's `http.server.requests`. I want to increase the window in witch percentiles are calculated for `http.server.requests` and can't find a proper way of doing this. – Ivan Nakov Mar 27 '19 at 08:59

1 Answers1

1

You should look at DistributionStatisticConfig. The creation of DEFAULT instance shows how to set expiry and bufferLength.

All you have to do in Spring Boot is register a bean MeterRegistryCustomizer in your @SpringBootApplication or @Configuration class.

import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;

@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
    return registry -> registry.config()
        .commonTags("myTag", myTagValue)
        .meterFilter(new MeterFilter() {

            @Override
            public DistributionStatisticConfig configure(Meter.Id id,
                                                         DistributionStatisticConfig config) {
                if (id.getName().startsWith("http.server.requests")) {
                    return config.merge(DistributionStatisticConfig.builder()
                        .percentilesHistogram(true)
                        .percentiles(0.5, 0.9, 0.99)
                        .percentilePrecision(1)
                        .minimumExpectedValue(1L)
                        .maximumExpectedValue(Long.MAX_VALUE)
                        .expiry(Duration.ofMinutes(1))
                        .bufferLength(2)
                        .build());
                }
                return config;
            }
        });
}

You can also ask on Micrometer's Slack channel.

lu_ko
  • 4,055
  • 2
  • 26
  • 31