spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.82k stars 40.6k forks source link

Provide a URI tag for HTTP requests handled by MessageDispatcherServlet #15390

Open SorokinStanislav opened 5 years ago

SorokinStanislav commented 5 years ago

Trying to use http_server_requests actuator metrics (Spring Boot 2.1.1) for web-method annotated by

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getName")
@ResponsePayload
@Timed

in @Endpoint class.

Do request like this:

POST /soap/getPerson HTTP/1.1
Host: localhost:1882
Content-Type: text/xml
Cache-Control: no-cache

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://example.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:personRequest>
         <id>18</id>
      </ser:personRequest>
   </soapenv:Body>
</soapenv:Envelope>

And in prometheus I see:

http_server_requests_seconds_count{exception="None",method="POST",outcome="SUCCESS",status="200",uri="UNKNOWN",} 1.0
http_server_requests_seconds_sum{exception="None",method="POST",outcome="SUCCESS",status="200",uri="UNKNOWN",} 0.290792324
http_server_requests_seconds_max{exception="None",method="POST",outcome="SUCCESS",status="200",uri="UNKNOWN",} 0.290792324

This issue like a micrometer issue #431, but there were URI cutting and not UNKNOWN. This is because of update WebMvcTags solving #12447.

So as I can see, new uri method doesn't support MessageDispatcherServlet which request does not contain BEST_MATCHING_PATTERN_ATTRIBUTE attribute.

You can reproduce this and look at whole code at my repo.

wilkinsona commented 5 years ago

Thanks for the suggestion, but I'm not sure that the URI is of much value when using SOAP as it won't tell you that much. It'll only provide details of the service that's being called and won't provide any information about the specific request which is in the body. Perhaps I have misunderstood? What did you expect to appear in the URI tag?

Overall, this feels to me like this may be better handled in Spring Web Services as part of SWS-1024. /cc @gregturn

SorokinStanislav commented 5 years ago

@wilkinsona, Thank you for your answer! I've updated my example by adding the second web-method with following request:

POST /soap/getOrigin HTTP/1.1
Host: localhost:1882
Content-Type: text/xml
Cache-Control: no-cache

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://example.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:originRequest>
         <id>18</id>
      </ser:originRequest>
   </soapenv:Body>
</soapenv:Envelope>

So, I agree that specific request info is containing in body: originRequest and personRequest. But if I have these two methods in my application (@PayloadRoot(namespace = NAMESPACE_URI, localPart = "originRequest") and @PayloadRoot(namespace = NAMESPACE_URI, localPart = "personRequest"), I have incorrect metrics in Prometheus after two requests: both of them are handled by one metric:

http_server_requests_seconds_count{exception="None",method="POST",outcome="SUCCESS",status="200",uri="UNKNOWN",} 2.0

And I wanna have something like this:

http_server_requests_seconds_count{exception="None",method="POST",outcome="SUCCESS",status="200",uri="soap/getPerson",} 1.0
http_server_requests_seconds_count{exception="None",method="POST",outcome="SUCCESS",status="200",uri="soap/getOrigin",} 1.0

Therefore my point is that I want to have different metrics for my different SOAP-methods, like @RestController allows to do for different URLs.

Bun in fact, our clients request service by one URL, even service has a lot of methods. So the URI in prometheus will be the same in this case anyway:)

wilkinsona commented 5 years ago

Thanks for the additional information. To implement that we'd need something (perhaps a request attribute) that provides a URI known to have low cardinality so it's suitable for use as a tag's value. AFAIK, Spring Web Services doesn't provide anything like that at the moment. Let's see what @gregturn says.

shark300 commented 5 years ago

@wilkinsona what's the plan?

wilkinsona commented 5 years ago

@shark300 There isn't much of a plan at the moment as we're blocked until we get some input from @gregturn, unfortunately.

gregturn commented 5 years ago

@wilkinsona is correct. Spring WS does not (yet) have support for Micrometer.

I haven't had time to pursue that feature addition, but can try to move it up in priority.

shark300 commented 5 years ago

Thank you everyone, we will keep in touch regarding to this issue :)

r00ta commented 4 years ago

Hi, Any update on this? Is there any workaround to add the URI to the labels atm? Btw It would be nice to have the possibility to specify some arguments in the @Timed annotation, isnt't?

wilkinsona commented 4 years ago

@r00ta As indicated by the issue's labels, I'm afraid this issue is still blocked from Spring Boot's perspective. @gregturn may have an update from the Spring WS side of things.

shark300 commented 4 years ago

As a workaround you can use CXF as a SOAP handler because I've opened a PR for CXF starter yet: https://github.com/apache/cxf/pull/642