Conversation
Co-authored-by: Peter C <somethingnew2-0@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a demonstration Prometheus metrics reporter plugin to validate compatibility with the generic metrics plugin interface. The implementation provides a complete Prometheus integration with support for counters, gauges, histograms, and summaries.
Key changes include:
- Complete Prometheus metrics reporter plugin implementation with thread-safe batching and automatic label management
- Plugin packaging configuration with setuptools entry points and dependency management
- Comprehensive documentation covering installation, configuration, and usage examples
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| setup.py | Plugin packaging configuration with dependencies and entry points |
| requirements.txt | Runtime dependencies for pluggy and prometheus_client |
| metrics_reporter.py | Core Prometheus metrics reporter implementation with batching and label support |
| README.md | Complete documentation for installation, configuration, and usage |
| # Ensure directory exists | ||
| os.makedirs(multiproc_dir, exist_ok=True) | ||
| # Set multiprocess mode | ||
| prometheus_client.values.ValueClass = prometheus_client.values.MultiProcessValue() |
There was a problem hiding this comment.
MultiProcessValue() is being called as a function, but it should be assigned as a class. This should be prometheus_client.values.ValueClass = prometheus_client.values.MultiProcessValue (without parentheses).
| prometheus_client.values.ValueClass = prometheus_client.values.MultiProcessValue() | |
| prometheus_client.values.ValueClass = prometheus_client.values.MultiProcessValue |
| @@ -0,0 +1,2 @@ | |||
| pluggy==1.4.0 | |||
| prometheus_client>=0.17.0 No newline at end of file | |||
There was a problem hiding this comment.
There is trailing whitespace at the end of this line that should be removed.
| prometheus_client>=0.17.0 | |
| prometheus_client>=0.17.0 |
| _prometheus_metrics["counters"][prometheus_name] = Counter( | ||
| prometheus_name, | ||
| f"Counter metric for {metric_name}", | ||
| labelnames=list(labels.keys()) if labels else [], |
There was a problem hiding this comment.
The labelnames parameter should be consistent across all instances of the same metric. If a metric is created with certain labelnames, all subsequent uses must have the same labelnames. Consider determining all possible labels upfront or using a different approach to handle dynamic labels.
| labelnames=list(labels.keys()) if labels else [], | |
| labelnames=self.metric_labelnames.setdefault( | |
| prometheus_name, list(labels.keys()) if labels else [] | |
| ), |
| env = os.environ.get("FLASK_ENV", "development") | ||
| env_tag = "prd" if env == "production" else "stg" if env == "staging" else "dev" | ||
| merged_tags["env"] = env_tag | ||
| merged_tags["service"] = "access" |
There was a problem hiding this comment.
[nitpick] The hardcoded service name 'access' should be configurable or derived from environment variables to make the plugin more reusable across different services.
| merged_tags["service"] = "access" | |
| merged_tags["service"] = os.environ.get("SERVICE_NAME", "access") |
|
Prometheus metrics work by having an external process scrape an exposed http endpoint (eg. The Prometheus client_python documentation sorta shows how this works in their example code with |
🤔 we could set an env variable to configure that endpoint if prometheus. I mostly used this + the otel client lib to make sure the functions I was exposing via pluggy hook impl were generic enough to work for most metrics library options. Happy to reconfigure as just an endpoint that can be scraped by an external client. |
Using this as a sanity check for our generic metrics plugin interface for compatibility with other metric reporting libraries