You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm interested into improving the prometheus metrics system of litestar and work on a PR.
Let me explain the problem I'm trying to solve.
So I want to use the /metrics endpoint, but the issue I have is that it's registering every requests even the one I don't need to have, it clutter my time series
For exemple, when quering a route with random or bad params in the URL with 404 responses, it register the calls which is useless and clutter the monitoring data.
It can be a problem because it increase the active time series number in my prometheus server and create high cardinality labels.
So we need to implement some way to control the potential cardinality explosion.
Currently there is a exclude_unhandled_paths setting in litestar.contrib.prometheus.PrometheusConfig which should not register metrics when a the server respond a 404.
But, apparently it does nothing currently, it's unimplemented.
So my proposal is to work on these issues:
Have a way to ignore 404 calls,
For that we can implement the exclude_unhandled_paths setting, to not register metrics when a call return 404. All others status code can be interesting.
May be we can replace this setting by exclude_status_code so it can be more configurable and we allow the user to exclude others status codes like 400 for example.
Have a way to specify which params in a URL are worth registering
We can implement a route_keep_params setting for each route, there is 2 way that I see to do that:
Add a MetricParameter in Annotated with a include option. We can make the default value configurable.
So what are your thoughts on this? Feedback and critics appreciated.
Basic Example
Example of endpoint config, adding a meta data in the Annotated type to tell the metrics handler to include or ignore a param:
So if I'm making a request GET /thing/bike/1
then a request GET /thing/bike/2, then a request GET /thing/house/1
before this feature I'm getting in the /metrics:
Summary
Hello,
I'm interested into improving the prometheus metrics system of litestar and work on a PR.
Let me explain the problem I'm trying to solve.
So I want to use the
/metrics
endpoint, but the issue I have is that it's registering every requests even the one I don't need to have, it clutter my time seriesFor exemple, when quering a route with random or bad params in the URL with 404 responses, it register the calls which is useless and clutter the monitoring data.
It can be a problem because it increase the active time series number in my prometheus server and create high cardinality labels.
So we need to implement some way to control the potential cardinality explosion.
Currently there is a
exclude_unhandled_paths
setting inlitestar.contrib.prometheus.PrometheusConfig
which should not register metrics when a the server respond a 404.But, apparently it does nothing currently, it's unimplemented.
So my proposal is to work on these issues:
Have a way to ignore 404 calls,
For that we can implement the
exclude_unhandled_paths
setting, to not register metrics when a call return 404. All others status code can be interesting.May be we can replace this setting by
exclude_status_code
so it can be more configurable and we allow the user to exclude others status codes like 400 for example.Have a way to specify which params in a URL are worth registering
We can implement a
route_keep_params
setting for each route, there is 2 way that I see to do that:Add a
MetricParameter
inAnnotated
with ainclude
option. We can make the default value configurable.So what are your thoughts on this? Feedback and critics appreciated.
Basic Example
Example of endpoint config, adding a meta data in the Annotated type to tell the metrics handler to include or ignore a param:
So if I'm making a request
GET /thing/bike/1
then a request
GET /thing/bike/2
, then a requestGET /thing/house/1
before this feature I'm getting in the
/metrics
:With this feature instead I would get:
Drawbacks and Impact
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: