Skip to content

Add new default metric: inflight gauge #481

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

john-wd
Copy link

@john-wd john-wd commented Aug 11, 2025

From my experience working with web applications, we usually want to track an additional quantity. Why?

The reason is simple:

  • Total inflight requests is a gauge that tracks how active the application is at any given time, useful if you are working on highly constrained machines with many replicas. It can also be a key metric to track slowdowns if you have many concurrent requests at a given time.

This PR adds this metric to the default After middleware, so if will be available for everyone for free.

I haven't added tests yet, first I want to run by the maintainers to see if it looks good enough to proceed, then I can add tests accordingly.

@@ -261,6 +275,8 @@ def process_response(self, request, response):
method = self._method(request)
name = self._get_view_name(request)
status = str(response.status_code)
self.label_metric(self.metrics.inflight_requests, request).dec()
self.label_metric(self.metrics.requests_total_by_view, request, view=name).inc()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this additional metric. As it can be easily constructed from the responses_by_status_view_method metric by sum(...) by (view). Is there a reason this doesn't work for your use case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you are right, this should suffice for this usecase. Thanks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this dupe from my latest commit, kept the inflights one.

@john-wd john-wd changed the title Add two more default metrics: inflight gauge and total requests by view Add new default metric: inflight gauge Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants