Skip to content

Commit

Permalink
Polish "Stop time web metrics when autotime is disabled"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Feb 4, 2020
1 parent e323e05 commit 10643b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
Expand Down Expand Up @@ -49,7 +49,7 @@ public String test2() {
@Timed
@GetMapping("test3")
public String test3() {
return "test2";
return "test3";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
@ExtendWith(OutputCaptureExtension.class)
class WebMvcMetricsAutoConfigurationTests {

private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple())
.withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));

@Test
void backsOffWhenMeterRegistryIsMissing() {
Expand Down Expand Up @@ -183,11 +183,12 @@ void longTaskTimingInterceptorIsRegistered() {
.contains(LongTaskTimingHandlerInterceptor.class));
}

private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2");
}

private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls)
throws Exception {
if (urls.length == 0) {
urls = new String[] { "/test0", "/test1", "/test2" };
}
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
Expand Down Expand Up @@ -144,11 +144,11 @@ private void record(TimingContext timingContext, HttpServletRequest request, Htt
Builder builder = this.autoTimer.builder(this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
}
return;
}
for (Timed annotation : annotations) {
Builder builder = Timer.builder(annotation, this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
} else {
for (Timed annotation : annotations) {
Builder builder = Timer.builder(annotation, this.metricName);
timerSample.stop(getTimer(builder, handler, request, response, exception));
}
}
}

Expand Down

0 comments on commit 10643b7

Please sign in to comment.