-
Notifications
You must be signed in to change notification settings - Fork 129
Add API calling metrics. #844
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Prometheus metrics to track API call counts and response times for the HTTP server. The implementation introduces two new middleware components: one for access logging and another for recording request metrics with labels for method, path, and status code.
Key Changes:
- Created a new middleware module with
AccessLogMiddlewareandRequestMetricsMiddlewareclasses - Refactored
MetricsFactoryIdMixinto extract a runtimeWithMetricsFactorymixin - Moved inline access logging middleware from
app.pyto the new middleware module
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/memmachine/server/middleware.py |
Implements new middleware classes for access logging and metrics collection |
src/memmachine/server/app.py |
Removes inline middleware and registers the new middleware classes |
src/memmachine/common/configuration/mixin_confs.py |
Extracts WithMetricsFactory runtime mixin from MetricsFactoryIdMixin |
tests/memmachine/server/test_middleware.py |
Adds comprehensive tests for both middleware classes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
13d48bb to
7291cf1
Compare
| """Initialize the middleware and metrics.""" | ||
| self.metrics_factory_id: str | None = None | ||
| super().__init__(app) | ||
| metrics_factory = self.get_metrics_factory() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the metrics factory id should from the same configuration as the memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, because we only support one kind of the metric factory, we don't have a configuration. Maybe in the future we can add that if we support multiple metric factory?
Add prometheus metrics to track the API count and response time.
7291cf1 to
1ff5c24
Compare
Purpose of the change
Add prometheus metrics to track the API count and response time.
Description
Add a middleware to track the API call count the response time. Use labels to track the number of different
API calls.
Move all the app middleware to a middleware module.
Type of change
How Has This Been Tested?
Checklist
Maintainer Checklist
Screenshots/Gifs
the metrics page after the change: