Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prometheus middleware generates new metrics for every 404 #86

Closed
brietaylor opened this issue Jan 27, 2023 · 3 comments
Closed

Prometheus middleware generates new metrics for every 404 #86

brietaylor opened this issue Jan 27, 2023 · 3 comments

Comments

@brietaylor
Copy link

brietaylor commented Jan 27, 2023

Every time a user requests a unique URL that returns 404, the Prometheus middleware generates new metrics. This can easily generate millions of timeseries, overloading a Prometheus server or triggering other limits.

Minimal reproducer: https://gist.github.com/brietaylor/c5aa76df6a2f3fa3a8e14e4f8250cab1

Debugging:

I was able to trace this back through the code somewhat. The code that generates these URLs ultimately traces back to router.go:Find() in Echo. That code initially sets Context.path to the request path, but on all success paths, it overrides Context.path to the route path. I couldn't find any way for middlewares to detect which was done, though, so this might need to be an upstream fix.

https://github.com/labstack/echo/blob/master/router.go#L527

@lammel
Copy link
Contributor

lammel commented Feb 20, 2023

We have been using our own metrics with a helper to discover the actual used route (the one configured in echo, not the actual path, so the list is not unbound) for a few years now.

Your proposed changes have been merged already with labstack/echo#2385
So this will be resolved with the next minor release.

@aldas
Copy link
Contributor

aldas commented Mar 3, 2023

Should be fixed. Please update Echo to latest version and this library to latest.

@therealak12
Copy link
Contributor

therealak12 commented Feb 29, 2024

Hi.

Can you confirm the issue is resolved? @brietaylor

I'm using echo v4.14.4 and echo-contrib v0.15.0. I still see new metrics for each new path with a 404 status code.
The solution is to make this assignment conditional.

I propose #111 as a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants