oathkeeper icon indicating copy to clipboard operation
oathkeeper copied to clipboard

More Customizable collapse_request_path Setting

Open WillyRL opened this issue 11 months ago • 3 comments

Preflight checklist

Ory Network Project

No response

Describe your problem

In reference to issue #446, the collapse_request_path configuration could be significantly more useful if it were more flexible.

Use Case I have an /api prefix for my service, followed by a unique UUID in the URL path, for example:

/api/conversations/{uuid-v4-conversation-id}/messages

When collapse_request_path is set to false, my metrics become unmanageable because each unique UUID generates a separate metric entry. However, setting it to true collapses everything under the /api prefix, losing valuable details for different endpoints.

Describe your ideal solution

Enable a more advanced configuration for collapse_request_path that allows specifying patterns, placeholders, or partial collapsing so that important segments (like /conversations) are preserved while unique identifiers (UUIDs) are collapsed.

Example Configuration

  collapse_request_paths:
    enabled: true
    rules:
      - pattern: "^/api/conversations/[0-9a-fA-F-]{36}/messages"
        replacement: "/api/conversations/:conversationId/messages"
      - pattern: "^/api/other-service/[0-9a-fA-F-]{36}"
        replacement: "/api/other-service/:resourceId"

Workarounds or alternatives

If the pattern based is too complicated, for the use case that using /api prefix, provide the collapse_level.

  collapse_request_paths:
    enabled: true
    # Define how many path segments to skip from the start
    collapse_level: 1

Version

0.40.6

Additional Context

No response

WillyRL avatar Dec 30 '24 07:12 WillyRL

Let me loop in @nipsufn to take a look at this idea as he is working on this issue in our system as well right now.

aeneasr avatar Jan 02 '25 09:01 aeneasr

I think you should be able to do that with Prometheus relabelings.

PR is welcome with changes on code level. There's a similar solution already used in Kratos with ory/x/prometheusx, maybe it can be reused or at least serve as a starting point.

nipsufn avatar Jan 07 '25 13:01 nipsufn

I think you should be able to do that with Prometheus relabelings.

yes, I think so. But I also think it's a bad Idea to let all the request path exposed on /metrics, it will introduce performance issues when the requests path are keep growing, at least the performance when the prometheus try to fetching the metrics.

WillyRL avatar Jan 10 '25 08:01 WillyRL