-
Notifications
You must be signed in to change notification settings - Fork 69
Demo: Prometheus plugin example #315
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
Co-authored-by: Peter C <[email protected]>
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot uses AI. Check for mistakes.
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is trailing whitespace at the end of this line that should be removed.
prometheus_client>=0.17.0 | |
prometheus_client>=0.17.0 |
Copilot uses AI. Check for mistakes.
_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 [] | |
), |
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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") |
Copilot uses AI. Check for mistakes.
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