Polish "Allow configuration of auto-timed metrics"

Closes gh-15988
This commit is contained in:
Stephane Nicoll
2019-05-01 08:16:54 +02:00
parent 4df6f5dee0
commit 8045bf1f50
26 changed files with 305 additions and 224 deletions

View File

@@ -0,0 +1,89 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics;
import java.util.List;
/**
* Settings for requests that are automatically timed.
*
* @author Tadaya Tsuyukubo
* @author Stephane Nicoll
* @since 2.2.0
*/
public final class Autotime {
private boolean enabled = true;
private boolean percentilesHistogram;
private double[] percentiles;
/**
* Create an instance that automatically time requests with no percentiles.
*/
public Autotime() {
}
/**
* Create an instance with the specified settings.
* @param enabled whether requests should be automatically timed
* @param percentilesHistogram whether percentile histograms should be published
* @param percentiles computed non-aggregable percentiles to publish (can be
* {@code null})
*/
public Autotime(boolean enabled, boolean percentilesHistogram,
List<Double> percentiles) {
this.enabled = enabled;
this.percentilesHistogram = percentilesHistogram;
this.percentiles = (percentiles != null)
? percentiles.stream().mapToDouble(Double::doubleValue).toArray() : null;
}
/**
* Create an instance that disable auto-timed requests.
* @return an instance that disable auto-timed requests
*/
public static Autotime disabled() {
return new Autotime(false, false, null);
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isPercentilesHistogram() {
return this.percentilesHistogram;
}
public void setPercentilesHistogram(boolean percentilesHistogram) {
this.percentilesHistogram = percentilesHistogram;
}
public double[] getPercentiles() {
return this.percentiles;
}
public void setPercentiles(double[] percentiles) {
this.percentiles = percentiles;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,13 +18,13 @@ package org.springframework.boot.actuate.metrics.web.client;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.core.NamedThreadLocal;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
@@ -51,11 +51,7 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
private final String metricName;
private final boolean autoTimeRequests;
private final double[] percentiles;
private final boolean histogram;
private final Autotime autotime;
/**
* Create a new {@code MetricsClientHttpRequestInterceptor}.
@@ -63,11 +59,11 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
* @param tagProvider provider for metrics tags
* @param metricName name of the metric to record
* @deprecated since 2.2.0 in favor of
* {@link #MetricsClientHttpRequestInterceptor(MeterRegistry, RestTemplateExchangeTagsProvider, String, boolean, List, boolean)}
* {@link #MetricsClientHttpRequestInterceptor(MeterRegistry, RestTemplateExchangeTagsProvider, String, Autotime)}
*/
MetricsClientHttpRequestInterceptor(MeterRegistry meterRegistry,
RestTemplateExchangeTagsProvider tagProvider, String metricName) {
this(meterRegistry, tagProvider, metricName, true, null, false);
this(meterRegistry, tagProvider, metricName, new Autotime());
}
/**
@@ -75,25 +71,16 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
* @param meterRegistry the registry to which metrics are recorded
* @param tagProvider provider for metrics tags
* @param metricName name of the metric to record
* @param autoTimeRequests if requests should be automatically timed
* @param percentileList percentiles for auto time requests
* @param histogram histogram or not for auto time requests
* @param autotime auto timed request settings
* @since 2.2.0
*/
MetricsClientHttpRequestInterceptor(MeterRegistry meterRegistry,
RestTemplateExchangeTagsProvider tagProvider, String metricName,
boolean autoTimeRequests, List<Double> percentileList, boolean histogram) {
double[] percentiles = (percentileList != null)
? percentileList.stream().mapToDouble(Double::doubleValue).toArray()
: null;
Autotime autotime) {
this.tagProvider = tagProvider;
this.meterRegistry = meterRegistry;
this.metricName = metricName;
this.autoTimeRequests = autoTimeRequests;
this.percentiles = percentiles;
this.histogram = histogram;
this.autotime = (autotime != null) ? autotime : Autotime.disabled();
}
@Override
@@ -106,7 +93,7 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
return response;
}
finally {
if (this.autoTimeRequests) {
if (this.autotime.isEnabled()) {
getTimeBuilder(request, response).register(this.meterRegistry)
.record(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
}
@@ -134,8 +121,9 @@ class MetricsClientHttpRequestInterceptor implements ClientHttpRequestIntercepto
private Timer.Builder getTimeBuilder(HttpRequest request,
ClientHttpResponse response) {
return Timer.builder(this.metricName).publishPercentiles(this.percentiles)
.publishPercentileHistogram(this.histogram)
return Timer.builder(this.metricName)
.publishPercentiles(this.autotime.getPercentiles())
.publishPercentileHistogram(this.autotime.isPercentilesHistogram())
.tags(this.tagProvider.getTags(urlTemplate.get(), request, response))
.description("Timer of RestTemplate operation");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.util.List;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
@@ -46,32 +47,29 @@ public class MetricsRestTemplateCustomizer implements RestTemplateCustomizer {
* @param tagProvider the tag provider
* @param metricName the name of the recorded metric
* @deprecated since 2.2.0 in favor of
* {@link #MetricsRestTemplateCustomizer(MeterRegistry, RestTemplateExchangeTagsProvider, String, boolean, List, boolean)}
* {@link #MetricsRestTemplateCustomizer(MeterRegistry, RestTemplateExchangeTagsProvider, String, Autotime)}
*/
public MetricsRestTemplateCustomizer(MeterRegistry meterRegistry,
RestTemplateExchangeTagsProvider tagProvider, String metricName) {
this.interceptor = new MetricsClientHttpRequestInterceptor(meterRegistry,
tagProvider, metricName);
this(meterRegistry, tagProvider, metricName, new Autotime());
}
/**
* Creates a new {@code MetricsRestTemplateInterceptor}. When {@code autoTimeRequests}
* is set to {@code true}, the interceptor records metrics using the given
* {@code meterRegistry} with tags provided by the given {@code tagProvider} and with
* {@code percentileList} and {@code histogram} configurations.
* {@link Autotime auto-timed request configuration}.
* @param meterRegistry the meter registry
* @param tagProvider the tag provider
* @param metricName the name of the recorded metric
* @param autoTimeRequests if requests should be automatically timed
* @param percentileList percentiles for auto time requests
* @param histogram histogram or not for auto time requests
* @param autotime auto-timed request settings
* @since 2.2.0
*/
public MetricsRestTemplateCustomizer(MeterRegistry meterRegistry,
RestTemplateExchangeTagsProvider tagProvider, String metricName,
boolean autoTimeRequests, List<Double> percentileList, boolean histogram) {
Autotime autotime) {
this.interceptor = new MetricsClientHttpRequestInterceptor(meterRegistry,
tagProvider, metricName, autoTimeRequests, percentileList, histogram);
tagProvider, metricName, autotime);
}
@Override

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.actuate.metrics.web.reactive.client;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer;
import org.springframework.web.reactive.function.client.WebClient;
@@ -39,11 +40,30 @@ public class MetricsWebClientCustomizer implements WebClientCustomizer {
* @param meterRegistry the meter registry
* @param tagProvider the tag provider
* @param metricName the name of the recorded metric
* @deprecated since 2.2.0 in favor of
* {@link #MetricsWebClientCustomizer(MeterRegistry, WebClientExchangeTagsProvider, String, Autotime)}
*/
@Deprecated
public MetricsWebClientCustomizer(MeterRegistry meterRegistry,
WebClientExchangeTagsProvider tagProvider, String metricName) {
this(meterRegistry, tagProvider, metricName, new Autotime());
}
/**
* Create a new {@code MetricsWebClientFilterFunction} that will record metrics using
* the given {@code meterRegistry} with tags provided by the given
* {@code tagProvider}.
* @param meterRegistry the meter registry
* @param tagProvider the tag provider
* @param metricName the name of the recorded metric
* @param autotime auto-timed request settings
* @since 2.2.0
*/
public MetricsWebClientCustomizer(MeterRegistry meterRegistry,
WebClientExchangeTagsProvider tagProvider, String metricName,
Autotime autotime) {
this.filterFunction = new MetricsWebClientFilterFunction(meterRegistry,
tagProvider, metricName);
tagProvider, metricName, autotime);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.boot.actuate.metrics.web.reactive.client;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.MeterRegistry;
@@ -24,6 +23,7 @@ import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Timer;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
@@ -48,11 +48,7 @@ public class MetricsWebClientFilterFunction implements ExchangeFilterFunction {
private final String metricName;
private final boolean autoTimeRequests;
private final double[] percentiles;
private final boolean histogram;
private final Autotime autotime;
/**
* Create a new {@code MetricsWebClientFilterFunction}.
@@ -60,11 +56,12 @@ public class MetricsWebClientFilterFunction implements ExchangeFilterFunction {
* @param tagProvider provider for metrics tags
* @param metricName name of the metric to record
* @deprecated since 2.2.0 in favor of
* {@link #MetricsWebClientFilterFunction(MeterRegistry, WebClientExchangeTagsProvider, String, boolean, List, boolean)}
* {@link #MetricsWebClientFilterFunction(MeterRegistry, WebClientExchangeTagsProvider, String, Autotime)}
*/
@Deprecated
public MetricsWebClientFilterFunction(MeterRegistry meterRegistry,
WebClientExchangeTagsProvider tagProvider, String metricName) {
this(meterRegistry, tagProvider, metricName, true, null, false);
this(meterRegistry, tagProvider, metricName, new Autotime());
}
/**
@@ -72,40 +69,33 @@ public class MetricsWebClientFilterFunction implements ExchangeFilterFunction {
* @param meterRegistry the registry to which metrics are recorded
* @param tagProvider provider for metrics tags
* @param metricName name of the metric to record
* @param autoTimeRequests if requests should be automatically timed
* @param percentileList percentiles for auto time requests
* @param histogram histogram or not for auto time requests
* @param autotime auto-timed request settings
* @since 2.2.0
*/
public MetricsWebClientFilterFunction(MeterRegistry meterRegistry,
WebClientExchangeTagsProvider tagProvider, String metricName,
boolean autoTimeRequests, List<Double> percentileList, boolean histogram) {
double[] percentiles = (percentileList != null)
? percentileList.stream().mapToDouble(Double::doubleValue).toArray()
: null;
Autotime autotime) {
this.meterRegistry = meterRegistry;
this.tagProvider = tagProvider;
this.metricName = metricName;
this.autoTimeRequests = autoTimeRequests;
this.percentiles = percentiles;
this.histogram = histogram;
this.autotime = (autotime != null) ? autotime : Autotime.disabled();
}
@Override
public Mono<ClientResponse> filter(ClientRequest clientRequest,
ExchangeFunction exchangeFunction) {
return exchangeFunction.exchange(clientRequest).doOnEach((signal) -> {
if (!signal.isOnComplete() && this.autoTimeRequests) {
if (!signal.isOnComplete() && this.autotime.isEnabled()) {
Long startTime = signal.getContext().get(METRICS_WEBCLIENT_START_TIME);
ClientResponse clientResponse = signal.get();
Throwable throwable = signal.getThrowable();
Iterable<Tag> tags = this.tagProvider.tags(clientRequest, clientResponse,
throwable);
Timer.builder(this.metricName).publishPercentiles(this.percentiles)
.publishPercentileHistogram(this.histogram).tags(tags)
.description("Timer of WebClient operation")
Timer.builder(this.metricName)
.publishPercentiles(this.autotime.getPercentiles())
.publishPercentileHistogram(
this.autotime.isPercentilesHistogram())
.tags(tags).description("Timer of WebClient operation")
.register(this.meterRegistry)
.record(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
}

View File

@@ -16,7 +16,6 @@
package org.springframework.boot.actuate.metrics.web.reactive.server;
import java.util.List;
import java.util.concurrent.TimeUnit;
import io.micrometer.core.instrument.MeterRegistry;
@@ -25,6 +24,7 @@ import io.micrometer.core.instrument.Timer;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.server.reactive.ServerHttpResponse;
@@ -48,11 +48,7 @@ public class MetricsWebFilter implements WebFilter {
private final String metricName;
private final boolean autoTimeRequests;
private final double[] percentiles;
private final boolean histogram;
private final Autotime autotime;
/**
* Create a new {@code MetricsWebFilter}.
@@ -61,12 +57,13 @@ public class MetricsWebFilter implements WebFilter {
* @param metricName name of the metric to record
* @param autoTimeRequests if requests should be automatically timed
* @deprecated since 2.2.0 in favor of
* {@link #MetricsWebFilter(MeterRegistry, WebFluxTagsProvider, String, boolean, List, boolean)}
* {@link #MetricsWebFilter(MeterRegistry, WebFluxTagsProvider, String, Autotime)}
*/
@Deprecated
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
String metricName, boolean autoTimeRequests) {
this(registry, tagsProvider, metricName, autoTimeRequests, null, false);
this(registry, tagsProvider, metricName,
new Autotime(autoTimeRequests, false, null));
}
/**
@@ -74,30 +71,20 @@ public class MetricsWebFilter implements WebFilter {
* @param registry the registry to which metrics are recorded
* @param tagsProvider provider for metrics tags
* @param metricName name of the metric to record
* @param autoTimeRequests if requests should be automatically timed
* @param percentileList percentiles for auto time requests
* @param histogram histogram or not for auto time requests
* @param autotime auto timed request settings
* @since 2.2.0
*/
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
String metricName, boolean autoTimeRequests, List<Double> percentileList,
boolean histogram) {
double[] percentiles = (percentileList != null)
? percentileList.stream().mapToDouble(Double::doubleValue).toArray()
: null;
String metricName, Autotime autotime) {
this.registry = registry;
this.tagsProvider = tagsProvider;
this.metricName = metricName;
this.autoTimeRequests = autoTimeRequests;
this.percentiles = percentiles;
this.histogram = histogram;
this.autotime = (autotime != null) ? autotime : Autotime.disabled();
}
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
if (this.autoTimeRequests) {
if (this.autotime.isEnabled()) {
return chain.filter(exchange).compose((call) -> filter(exchange, call));
}
return chain.filter(exchange);
@@ -122,8 +109,10 @@ public class MetricsWebFilter implements WebFilter {
private void record(ServerWebExchange exchange, long start, Throwable cause) {
Iterable<Tag> tags = this.tagsProvider.httpRequestTags(exchange, cause);
Timer.builder(this.metricName).tags(tags).publishPercentiles(this.percentiles)
.publishPercentileHistogram(this.histogram).register(this.registry)
Timer.builder(this.metricName).tags(tags)
.publishPercentiles(this.autotime.getPercentiles())
.publishPercentileHistogram(this.autotime.isPercentilesHistogram())
.register(this.registry)
.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
}

View File

@@ -19,7 +19,6 @@ package org.springframework.boot.actuate.metrics.web.servlet;
import java.io.IOException;
import java.lang.reflect.AnnotatedElement;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
@@ -35,6 +34,7 @@ import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.Timer.Builder;
import io.micrometer.core.instrument.Timer.Sample;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.core.annotation.MergedAnnotationCollectors;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.http.HttpStatus;
@@ -60,11 +60,7 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
private final String metricName;
private final boolean autoTimeRequests;
private final double[] autoTimeRequestsPercentiles;
private final boolean autoTimeRequestsHistogram;
private final Autotime autotime;
/**
* Create a new {@link WebMvcMetricsFilter} instance.
@@ -73,13 +69,14 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
* @param metricName the metric name
* @param autoTimeRequests if requests should be automatically timed
* @since 2.0.7
* @deprecated since 2.1.4 in favor of
* {@link #WebMvcMetricsFilter(MeterRegistry, WebMvcTagsProvider, String, boolean, List, boolean)}
* @deprecated since 2.2.0 in favor of
* {@link #WebMvcMetricsFilter(MeterRegistry, WebMvcTagsProvider, String, Autotime)}
*/
@Deprecated
public WebMvcMetricsFilter(MeterRegistry registry, WebMvcTagsProvider tagsProvider,
String metricName, boolean autoTimeRequests) {
this(registry, tagsProvider, metricName, autoTimeRequests, null, false);
this(registry, tagsProvider, metricName,
new Autotime(autoTimeRequests, false, null));
}
/**
@@ -87,26 +84,15 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
* @param registry the meter registry
* @param tagsProvider the tags provider
* @param metricName the metric name
* @param autoTimeRequests if requests should be automatically timed
* @param autoTimeRequestsPercentiles default percentiles if requests are auto timed
* @param autoTimeRequestsHistogram default histogram flag if requests are auto timed
* @param autotime auto timed request settings
* @since 2.2.0
*/
public WebMvcMetricsFilter(MeterRegistry registry, WebMvcTagsProvider tagsProvider,
String metricName, boolean autoTimeRequests,
List<Double> autoTimeRequestsPercentiles, boolean autoTimeRequestsHistogram) {
double[] percentiles = (autoTimeRequestsPercentiles != null)
? autoTimeRequestsPercentiles.stream().mapToDouble(Double::doubleValue)
.toArray()
: null;
String metricName, Autotime autotime) {
this.registry = registry;
this.tagsProvider = tagsProvider;
this.metricName = metricName;
this.autoTimeRequests = autoTimeRequests;
this.autoTimeRequestsPercentiles = percentiles;
this.autoTimeRequestsHistogram = autoTimeRequestsHistogram;
this.autotime = autotime;
}
@Override
@@ -187,10 +173,12 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
Supplier<Iterable<Tag>> tags = () -> this.tagsProvider.getTags(request, response,
handlerObject, exception);
if (annotations.isEmpty()) {
if (this.autoTimeRequests) {
stop(timerSample, tags, Timer.builder(this.metricName)
.publishPercentiles(this.autoTimeRequestsPercentiles)
.publishPercentileHistogram(this.autoTimeRequestsHistogram));
if (this.autotime.isEnabled()) {
stop(timerSample, tags,
Timer.builder(this.metricName)
.publishPercentiles(this.autotime.getPercentiles())
.publishPercentileHistogram(
this.autotime.isPercentilesHistogram()));
}
}
else {

View File

@@ -27,6 +27,7 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.test.web.client.MockRestServiceServer;
@@ -59,7 +60,7 @@ public class MetricsRestTemplateCustomizerTests {
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
this.customizer = new MetricsRestTemplateCustomizer(this.registry,
new DefaultRestTemplateExchangeTagsProvider(), "http.client.requests",
true, null, false);
new Autotime());
this.customizer.customize(this.restTemplate);
}

View File

@@ -40,7 +40,7 @@ public class MetricsWebClientCustomizerTests {
@Before
public void setup() {
this.customizer = new MetricsWebClientCustomizer(mock(MeterRegistry.class),
mock(WebClientExchangeTagsProvider.class), "test");
mock(WebClientExchangeTagsProvider.class), "test", null);
this.clientBuilder = WebClient.builder();
}

View File

@@ -30,6 +30,7 @@ import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.ClientRequest;
@@ -63,7 +64,8 @@ public class MetricsWebClientFilterFunctionTests {
public void setup() {
this.registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
this.filterFunction = new MetricsWebClientFilterFunction(this.registry,
new DefaultWebClientExchangeTagsProvider(), "http.client.requests");
new DefaultWebClientExchangeTagsProvider(), "http.client.requests",
new Autotime());
this.response = mock(ClientResponse.class);
this.exchange = (r) -> Mono.just(this.response);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
import org.springframework.mock.web.server.MockServerWebExchange;
import org.springframework.web.reactive.HandlerMapping;
@@ -50,8 +51,7 @@ public class MetricsWebFilterTests {
MockClock clock = new MockClock();
this.registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock);
this.webFilter = new MetricsWebFilter(this.registry,
new DefaultWebFluxTagsProvider(), REQUEST_METRICS_NAME, true, null,
false);
new DefaultWebFluxTagsProvider(), REQUEST_METRICS_NAME, new Autotime());
}
@Test

View File

@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -106,7 +107,8 @@ public class WebMvcMetricsFilterAutoTimedTests {
public WebMvcMetricsFilter webMetricsFilter(WebApplicationContext context,
MeterRegistry registry) {
return new WebMvcMetricsFilter(registry, new DefaultWebMvcTagsProvider(),
"http.server.requests", true, Arrays.asList(0.5, 0.95), true);
"http.server.requests",
new Autotime(true, true, Arrays.asList(0.5, 0.95)));
}
}

View File

@@ -56,6 +56,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -372,7 +373,7 @@ public class WebMvcMetricsFilterTests {
WebMvcMetricsFilter webMetricsFilter(MeterRegistry registry,
WebApplicationContext ctx) {
return new WebMvcMetricsFilter(registry, new DefaultWebMvcTagsProvider(),
"http.server.requests", true, null, false);
"http.server.requests", new Autotime());
}
}

View File

@@ -27,6 +27,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.Autotime;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
@@ -111,7 +112,7 @@ public class WebMvcMetricsIntegrationTests {
public WebMvcMetricsFilter webMetricsFilter(MeterRegistry registry,
WebApplicationContext ctx) {
return new WebMvcMetricsFilter(registry, new DefaultWebMvcTagsProvider(),
"http.server.requests", true, null, false);
"http.server.requests", new Autotime());
}
@Configuration(proxyBeanMethods = false)