VEuPathDB / lib-jaxrs-container-core

Core library for VEuPathDB JaxRS container services
Apache License 2.0
0 stars 0 forks source link

Replace path params in duration label #24

Closed dmgaldi closed 1 year ago

dmgaldi commented 1 year ago

Overview

Apply path param transformation to prometheus duration label.

dmgaldi commented 1 year ago

@dmgaldi In WDK we add paths like this to prometheus but as a post-matching filter; then we get the matched URL pattern from Jersey and use that. It means we're not adding metrics for 404s, and it's a nice way to ask the services which portions of the path are variable. Not exactly sure what this code is doing; like what is getPathParameters() if we haven't matched to a service yet? The WDK version (which, granted, seems to do a lot of work) is here: https://github.com/VEuPathDB/WDK/blob/master/Service/src/main/java/org/gusdb/wdk/service/filter/PrometheusFilter.java

EDIT: Actually, this needs some work to match how we do the logging. This filter only records duration from beginning-of-request to beginning-of-response. But for streaming responses, we probably want to know how long until all the data is out the door. That is a little more complex, but we already figured out how to do it here: https://github.com/VEuPathDB/WDK/blob/master/Service/src/main/java/org/gusdb/wdk/service/filter/RequestLoggingFilter.java

The trick is: if a response has a non-empty body, you need to "complete" the request in the WriterInterceptor, because the ContainerResponseFilter is too soon. But if it's an empty body, you have to use the ContainerResponseFilter, because no WriterIntercepter is applied in that case.

I finally updated this PR addressing these comments :)