|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.web.servlet;
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.metrics.web.servlet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
|
|
|
@ -24,6 +25,7 @@ import javax.servlet.Filter;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.Meter;
|
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.MeterRegistry;
|
|
|
|
import io.micrometer.core.instrument.Tag;
|
|
|
|
import io.micrometer.core.instrument.Tag;
|
|
|
|
import io.micrometer.core.instrument.Timer;
|
|
|
|
import io.micrometer.core.instrument.Timer;
|
|
|
@ -64,12 +66,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|
|
|
* @author Dmytro Nosan
|
|
|
|
* @author Dmytro Nosan
|
|
|
|
* @author Tadaya Tsuyukubo
|
|
|
|
* @author Tadaya Tsuyukubo
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @author Madhura Bhave
|
|
|
|
|
|
|
|
* @author Chanhyeong LEE
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ExtendWith(OutputCaptureExtension.class)
|
|
|
|
@ExtendWith(OutputCaptureExtension.class)
|
|
|
|
class WebMvcMetricsAutoConfigurationTests {
|
|
|
|
class WebMvcMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().with(MetricsRun.simple())
|
|
|
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
|
|
|
.withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
|
|
|
|
.with(MetricsRun.simple()).withConfiguration(AutoConfigurations.of(WebMvcMetricsAutoConfiguration.class));
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void backsOffWhenMeterRegistryIsMissing() {
|
|
|
|
void backsOffWhenMeterRegistryIsMissing() {
|
|
|
@ -157,6 +160,19 @@ class WebMvcMetricsAutoConfigurationTests {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void timerWorksWithTimedAnnotationsWhenAutoTimeRequestsIsFalse() {
|
|
|
|
|
|
|
|
this.contextRunner.withUserConfiguration(TestController.class)
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(MetricsAutoConfiguration.class, WebMvcAutoConfiguration.class))
|
|
|
|
|
|
|
|
.withPropertyValues("management.metrics.web.server.request.autotime.enabled=false").run((context) -> {
|
|
|
|
|
|
|
|
MeterRegistry registry = getInitializedMeterRegistry(context, "/test3");
|
|
|
|
|
|
|
|
Collection<Meter> meters = registry.get("http.server.requests").meters();
|
|
|
|
|
|
|
|
assertThat(meters).hasSize(1);
|
|
|
|
|
|
|
|
Meter meter = meters.iterator().next();
|
|
|
|
|
|
|
|
assertThat(meter.getId().getTag("uri")).isEqualTo("/test3");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
void longTaskTimingInterceptorIsRegistered() {
|
|
|
|
void longTaskTimingInterceptorIsRegistered() {
|
|
|
@ -168,12 +184,17 @@ class WebMvcMetricsAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
|
|
|
|
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context) throws Exception {
|
|
|
|
|
|
|
|
return getInitializedMeterRegistry(context, "/test0", "/test1", "/test2");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MeterRegistry getInitializedMeterRegistry(AssertableWebApplicationContext context, String... urls)
|
|
|
|
|
|
|
|
throws Exception {
|
|
|
|
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
|
|
|
|
assertThat(context).hasSingleBean(FilterRegistrationBean.class);
|
|
|
|
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
|
|
|
|
Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
|
|
|
|
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);
|
|
|
|
assertThat(filter).isInstanceOf(WebMvcMetricsFilter.class);
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilters(filter).build();
|
|
|
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).addFilters(filter).build();
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (String url : urls) {
|
|
|
|
mockMvc.perform(MockMvcRequestBuilders.get("/test" + i)).andExpect(status().isOk());
|
|
|
|
mockMvc.perform(MockMvcRequestBuilders.get(url)).andExpect(status().isOk());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return context.getBean(MeterRegistry.class);
|
|
|
|
return context.getBean(MeterRegistry.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|