Change unknownPath to unmapped
This commit is contained in:
parent
733b22f46a
commit
1259057acb
|
|
@ -57,7 +57,7 @@ import org.springframework.web.util.UrlPathHelper;
|
||||||
public class MetricFilterAutoConfiguration {
|
public class MetricFilterAutoConfiguration {
|
||||||
|
|
||||||
private static final int UNDEFINED_HTTP_STATUS = 999;
|
private static final int UNDEFINED_HTTP_STATUS = 999;
|
||||||
private static final String UNKNOWN_PATH_SUFFIX = "/unknownPath";
|
private static final String UNKNOWN_PATH_SUFFIX = "/unmapped";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CounterService counterService;
|
private CounterService counterService;
|
||||||
|
|
@ -89,18 +89,19 @@ public class MetricFilterAutoConfiguration {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
if(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE) != null)
|
int status = getStatus(response);
|
||||||
{
|
if (request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE) != null) {
|
||||||
suffix = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE).toString().replaceAll("[{}]", "-");
|
suffix = request
|
||||||
|
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)
|
||||||
|
.toString().replaceAll("[{}]", "-");
|
||||||
}
|
}
|
||||||
else if(getStatus(response) == HttpStatus.NOT_FOUND.value())
|
else if (HttpStatus.valueOf(status).is4xxClientError()) {
|
||||||
{
|
suffix = UNKNOWN_PATH_SUFFIX;
|
||||||
suffix=UNKNOWN_PATH_SUFFIX;
|
|
||||||
}
|
}
|
||||||
String gaugeKey = getKey("response" + suffix);
|
String gaugeKey = getKey("response" + suffix);
|
||||||
MetricFilterAutoConfiguration.this.gaugeService.submit(gaugeKey,
|
MetricFilterAutoConfiguration.this.gaugeService.submit(gaugeKey,
|
||||||
stopWatch.getTotalTimeMillis());
|
stopWatch.getTotalTimeMillis());
|
||||||
String counterKey = getKey("status." + getStatus(response) + suffix);
|
String counterKey = getKey("status." + status + suffix);
|
||||||
MetricFilterAutoConfiguration.this.counterService.increment(counterKey);
|
MetricFilterAutoConfiguration.this.counterService.increment(counterKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure;
|
package org.springframework.boot.actuate.autoconfigure;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.BDDMockito.willAnswer;
|
|
||||||
import static org.mockito.Matchers.anyDouble;
|
|
||||||
import static org.mockito.Matchers.eq;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
|
|
||||||
|
|
@ -49,6 +38,17 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.BDDMockito.willAnswer;
|
||||||
|
import static org.mockito.Matchers.anyDouble;
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link MetricFilterAutoConfiguration}.
|
* Tests for {@link MetricFilterAutoConfiguration}.
|
||||||
*
|
*
|
||||||
|
|
@ -56,7 +56,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
*/
|
*/
|
||||||
public class MetricFilterAutoConfigurationTests {
|
public class MetricFilterAutoConfigurationTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void recordsHttpInteractions() throws Exception {
|
public void recordsHttpInteractions() throws Exception {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
|
@ -85,28 +84,31 @@ public class MetricFilterAutoConfigurationTests {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
Config.class, MetricFilterAutoConfiguration.class);
|
Config.class, MetricFilterAutoConfiguration.class);
|
||||||
Filter filter = context.getBean(Filter.class);
|
Filter filter = context.getBean(Filter.class);
|
||||||
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
|
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
|
||||||
mvc.perform(get("/templateVarTest/foo"))
|
.addFilter(filter).build();
|
||||||
.andExpect(status().isOk());
|
mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
|
||||||
|
|
||||||
verify(context.getBean(CounterService.class)).increment("status.200.templateVarTest.-someVariable-");
|
verify(context.getBean(CounterService.class)).increment(
|
||||||
verify(context.getBean(GaugeService.class)).submit(eq("response.templateVarTest.-someVariable-"),
|
"status.200.templateVarTest.-someVariable-");
|
||||||
anyDouble());
|
verify(context.getBean(GaugeService.class)).submit(
|
||||||
|
eq("response.templateVarTest.-someVariable-"), anyDouble());
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable() throws Exception {
|
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable()
|
||||||
|
throws Exception {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
Config.class, MetricFilterAutoConfiguration.class);
|
Config.class, MetricFilterAutoConfiguration.class);
|
||||||
Filter filter = context.getBean(Filter.class);
|
Filter filter = context.getBean(Filter.class);
|
||||||
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
|
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
|
||||||
mvc.perform(get("/knownPath/foo"))
|
.addFilter(filter).build();
|
||||||
.andExpect(status().isNotFound());
|
mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());
|
||||||
|
|
||||||
verify(context.getBean(CounterService.class)).increment("status.404.knownPath.-someVariable-");
|
verify(context.getBean(CounterService.class)).increment(
|
||||||
verify(context.getBean(GaugeService.class)).submit(eq("response.knownPath.-someVariable-"),
|
"status.404.knownPath.-someVariable-");
|
||||||
anyDouble());
|
verify(context.getBean(GaugeService.class)).submit(
|
||||||
|
eq("response.knownPath.-someVariable-"), anyDouble());
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,16 +117,16 @@ public class MetricFilterAutoConfigurationTests {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
Config.class, MetricFilterAutoConfiguration.class);
|
Config.class, MetricFilterAutoConfiguration.class);
|
||||||
Filter filter = context.getBean(Filter.class);
|
Filter filter = context.getBean(Filter.class);
|
||||||
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
|
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController())
|
||||||
mvc.perform(get("/unknownPath/1"))
|
.addFilter(filter).build();
|
||||||
.andExpect(status().isNotFound());
|
mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());
|
||||||
|
|
||||||
mvc.perform(get("/unknownPath/2"))
|
mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());
|
||||||
.andExpect(status().isNotFound());
|
|
||||||
|
|
||||||
verify(context.getBean(CounterService.class), times(2)).increment("status.404.unknownPath");
|
verify(context.getBean(CounterService.class), times(2)).increment(
|
||||||
verify(context.getBean(GaugeService.class), times(2)).submit(eq("response.unknownPath"),
|
"status.404.unmapped");
|
||||||
anyDouble());
|
verify(context.getBean(GaugeService.class), times(2)).submit(
|
||||||
|
eq("response.unmapped"), anyDouble());
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,22 +155,18 @@ public class MetricFilterAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class MetricFilterTestController
|
class MetricFilterTestController {
|
||||||
{
|
|
||||||
|
|
||||||
@RequestMapping("templateVarTest/{someVariable}")
|
@RequestMapping("templateVarTest/{someVariable}")
|
||||||
public String testTemplateVariableResolution(@PathVariable String someVariable)
|
public String testTemplateVariableResolution(@PathVariable String someVariable) {
|
||||||
{
|
|
||||||
return someVariable;
|
return someVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("knownPath/{someVariable}")
|
@RequestMapping("knownPath/{someVariable}")
|
||||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String testKnownPathWith404Response(@PathVariable String someVariable)
|
public String testKnownPathWith404Response(@PathVariable String someVariable) {
|
||||||
{
|
|
||||||
return someVariable;
|
return someVariable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue