[ 
https://issues.apache.org/jira/browse/CXF-8424?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17287023#comment-17287023
 ] 

Henrik Wingerei edited comment on CXF-8424 at 2/19/21, 11:58 AM:
-----------------------------------------------------------------

Thanks [~reta] 
 I found this old discussion where a suggested solution is to use the 
OperationResourceInfo class located on the Exchange object on the request. 
[http://cxf.547215.n5.nabble.com/JAXRS-Best-way-to-retrieve-path-parameters-in-request-handler-td567237.html]
 

I tested it briefly and to me it looks like you could something like this to 
get the complete templated path, using the value which is set in the @Path 
annotation on the resource class (both from any class @Path annotations and 
method @Path annotations):
{code:java}
private String getPathTemplate(Message request) {
    OperationResourceInfo operationResourceInfo = 
request.getExchange().get(OperationResourceInfo.class);
    String methodPathTemplate = 
operationResourceInfo.getURITemplate().getValue();
    String classPathTemplate = 
operationResourceInfo.getClassResourceInfo().getURITemplate().getValue();

    return classPathTemplate + methodPathTemplate;
}{code}
 


was (Author: henriwi):
Thanks [~reta] 
I found this old discussion where a suggested solution is to use 
OperationResourceInfo class located on the Exchange object on the request. 
[http://cxf.547215.n5.nabble.com/JAXRS-Best-way-to-retrieve-path-parameters-in-request-handler-td567237.html]
 

I tested it briefly and to me it looks like you could something like this to 
get the complete templated path, using the value which is set in the @Path 
annotation on the resource class (both from any class @Path annotations and 
method @Path annotations):
{code:java}
private String getPathTemplate(Message request) {
    OperationResourceInfo operationResourceInfo = 
request.getExchange().get(OperationResourceInfo.class);
    String methodPathTemplate = 
operationResourceInfo.getURITemplate().getValue();
    String classPathTemplate = 
operationResourceInfo.getClassResourceInfo().getURITemplate().getValue();

    return classPathTemplate + methodPathTemplate;
}{code}
 

> Use template URL instead of actual path values for JAX-RS micrometer metrics
> ----------------------------------------------------------------------------
>
>                 Key: CXF-8424
>                 URL: https://issues.apache.org/jira/browse/CXF-8424
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>    Affects Versions: 3.4.1, 3.3.9
>            Reporter: Henrik Wingerei
>            Assignee: Andriy Redko
>            Priority: Minor
>
> The JAX-RS micrometer metrics implemented in the PRs listed below generates 
> one unique metric per combination of path parameteres in the URL. For 
> instance if you have the following path annotation on an API:
> {code:java}
> @Path("/user/{userId}" {code}
> A request to the URL _/user/1234_ will result in the following metric:
> {code:java}
> cxf_server_requests_seconds_count{exception="None",method="GET",operation="getUser",outcome="SUCCESS",status="200",uri="/user/1234",}
>  1.0 {code}
> Since the uri-tag in the metric uses the actual path value this could lead to 
> a huge number of metrics since it will create one metric per user. It will 
> also be more difficult to aggregate the metrics for one operation in tools 
> like Prometheus/Grafana.
> A suggestion is to instead generate the metric with the uri-tag as a 
> templated url. I think this is how the metrics generated by Spring MVC is 
> constructed. This would result in the following metric instead:
> {code:java}
> cxf_server_requests_seconds_count{exception="None",method="GET",operation="getUser",outcome="SUCCESS",status="200",uri="/user/{userId}",}
>  1.0  {code}
> Not sure if this is possible and what the best solution is, but it might be 
> possible to use the UriInfo class 
> ([https://javaee.github.io/javaee-spec/javadocs/javax/ws/rs/core/UriInfo.html)]
>   to get the URI without the values, or use that class to replace the actual 
> values with a placeholder/variable text.
> Relevant PRs:
> [https://github.com/apache/cxf/pull/716]
> [https://github.com/apache/cxf/pull/642] 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to