【发布时间】:2020-12-06 14:17:43
【问题描述】:
通过微服务架构,我编写了一个通用的 POST 请求处理程序,它被所有微服务使用。 spring的post映射是这样的:
@RestController
@RequestMapping(value = "/v1/", consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE})
public class V1Controller {
@PostMapping(path = "/**")
public @ResponseBody Json post () {}
}
现在,当我使用千分尺使用此端点的指标时,我只会将 /v1/ 作为指标中的端点,而我正在发送像 /v1/demo 这样的完整 URL /foo 来自调用服务。我尝试了很多组合,但它不起作用。我还添加了我列出的 WebMvcTagsProvider 以请求和解决 POST api 调用。
@Bean
@SuppressWarnings("unchecked")
public WebMvcTagsProvider webMvcTagsProvider(ObjectMapper objectMapper) {
return new DefaultWebMvcTagsProvider() {
public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable exception) {
if ("POST".equals(request.getMethod())) {
Tag uriTag = Tag.of("uri", String.valueOf(request.getRequestURI()));
return Tags.of(WebMvcTags.method(request), uriTag, WebMvcTags.exception(exception), WebMvcTags.status(response));
}
return Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, response), WebMvcTags.exception(exception), WebMvcTags.status(response));
}
};
}
仍然解析为指标中的 /v1/ URL。我尝试了很多谷歌搜索,但没有找到任何解决方案。提前致谢。
【问题讨论】:
标签: spring spring-boot prometheus micrometer spring-micrometer