Honour management.metrics.web.server.auto-time-requests with WebFlux
Closes gh-13895
This commit is contained in:
parent
1f34da9025
commit
d3b3c8c64e
|
@ -66,7 +66,8 @@ public class WebFluxMetricsAutoConfiguration {
|
|||
public MetricsWebFilter webfluxMetrics(MeterRegistry registry,
|
||||
WebFluxTagsProvider tagConfigurer) {
|
||||
return new MetricsWebFilter(registry, tagConfigurer,
|
||||
this.properties.getWeb().getServer().getRequestsMetricName());
|
||||
this.properties.getWeb().getServer().getRequestsMetricName(),
|
||||
this.properties.getWeb().getServer().isAutoTimeRequests());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -98,6 +98,19 @@ public class WebFluxMetricsAutoConfigurationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metricsAreNotRecordedIfAutoTimeRequestsIsDisabled() {
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
|
||||
.withUserConfiguration(TestController.class)
|
||||
.withPropertyValues(
|
||||
"management.metrics.web.server.auto-time-requests=false")
|
||||
.run((context) -> {
|
||||
MeterRegistry registry = getInitializedMeterRegistry(context);
|
||||
assertThat(registry.find("http.server.requests").meter()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
private MeterRegistry getInitializedMeterRegistry(
|
||||
AssertableReactiveWebApplicationContext context) {
|
||||
WebTestClient webTestClient = WebTestClient.bindToApplicationContext(context)
|
||||
|
|
|
@ -46,16 +46,36 @@ public class MetricsWebFilter implements WebFilter {
|
|||
|
||||
private final String metricName;
|
||||
|
||||
private final boolean autoTimeRequests;
|
||||
|
||||
/**
|
||||
* Create a new {@code MetricsWebFilter}.
|
||||
* @param registry the registry to which metrics are recorded
|
||||
* @param tagsProvider provider for metrics tags
|
||||
* @param metricName name of the metric to record
|
||||
* @deprecated since 2.0.6 in favour of
|
||||
* {@link #MetricsWebFilter(MeterRegistry, WebFluxTagsProvider, String, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
|
||||
String metricName) {
|
||||
this(registry, tagsProvider, metricName, true);
|
||||
}
|
||||
|
||||
public MetricsWebFilter(MeterRegistry registry, WebFluxTagsProvider tagsProvider,
|
||||
String metricName, boolean autoTimeRequests) {
|
||||
this.registry = registry;
|
||||
this.tagsProvider = tagsProvider;
|
||||
this.metricName = metricName;
|
||||
this.autoTimeRequests = autoTimeRequests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return chain.filter(exchange).compose((call) -> filter(exchange, call));
|
||||
if (this.autoTimeRequests) {
|
||||
return chain.filter(exchange).compose((call) -> filter(exchange, call));
|
||||
}
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
private Publisher<Void> filter(ServerWebExchange exchange, Mono<Void> call) {
|
||||
|
|
Loading…
Reference in New Issue