You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/11/22 10:39:52 UTC

[GitHub] [pulsar] yaalsn commented on issue #18560: [DISCUSS] PIP-223: Add metrics for all Rest Endpoints

yaalsn commented on issue #18560:
URL: https://github.com/apache/pulsar/issues/18560#issuecomment-1323465891

   It would be better to avoid use reflection because it cost much. We can get the path in this way:
   
   ```java
       @Override
       public void filter(ContainerRequestContext req, ContainerResponseContext resp) throws IOException {
           StringBuilder fullPath = new StringBuilder();
           Stack<String> pathStack = new Stack<>();
           Resource matchedResourceMethodParent =
                   ((UriRoutingContext) req.getUriInfo()).getMatchedResourceMethod().getParent();
   
           while (true) {
               String path = matchedResourceMethodParent.getPath();
               matchedResourceMethodParent = matchedResourceMethodParent.getParent();
               if (matchedResourceMethodParent == null) {
                   // To prevent path from beginning without "/"
                   if (!pathStack.peek().startsWith("/")) {
                       pathStack.push("/");
                   }
                   pathStack.push(path);
                   break;
               }
               pathStack.push(path);
   
           }
           while (!pathStack.isEmpty()) {
               fullPath.append(pathStack.pop());
           }
       }
       // Use fullPath ....
   ```
   
   Furthermore, we can cache the result to reduce the stack allocation and method invocations.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org