jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

Normalizing URL path: Replace #val with custom values/attributes #96

Open girish7999 opened 2 years ago

girish7999 commented 2 years ago

Current values using the 'express-prom-bundle' module:

attribute: path Value: "/api/v1/engagements/#val/features" "/api/v1/engagements/#val" "/api/v1/engagements/#val/data/workspace/assets/#val/unzip"

But we are expecting the metrics report to come up with the below values:

attribute: path Value: "/api/v1/engagements/{engagementId}/features" "/api/v1/engagements/{engagementId" "/api/v1/engagements/{engagementId}/data/workspace/assets/{assetId}/unzip"

I already tried the below normalizePath expressions:

normalizePath: [ ['^/api/v1/engagements/./features', '/api/v1/engagements/{engagementId}/features'], ['^/api/v1/engagements/.', '/api/v1/engagements/{engagementId}'], ]

disjunction commented 2 years ago

Formally right solution: normalizePath also takes the function and let's you do any custom replacement you like.

It will not work with the array of regex, because those replacements are matched against individual chunks. In your example if the path is: /api/v1/engagements/345472387234/features, then the path is split into chunks and then analyzsed?

Actually right solution: don't customize anything. You're missing the point of this library. It's meant to work with an unknown paths and provide good results. So that when you add a new API tomorrow /api/v2/raccons/{racoonId}/furr-color it would still replace racoon IDs with #val without you need to touch anything. Look at your API. After /engagements there can be nothing else than engementId so replacing with {engementId}, #val or foobar will work just the same - provide one path for all possible ids.