Repository navigation
Conversation
…-Agent#3201) Signed-off-by: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com>
Co-authored-by: Utsab <utsab@pr-agent.dev>
Co-authored-by: Utsab <utsab@pr-agent.dev>
Co-authored-by: Aurora <aurora9c69543e@atomicmail.ai>
…-Agent#3163) Co-authored-by: Alex Tumanov <6143578+oleksii-tumanov@users.noreply.github.com>
…e-PR-Agent#3204) Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
…Agent#3213) Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
…ent#3219) Co-authored-by: Aurora <aurora9c69543e@atomicmail.ai>
Signed-off-by: hwan <3373484735@qq.com>
Signed-off-by: hwan <3373484735@qq.com>
Adds an opt-in 'prometheus' OTEL.EXPORTER_TYPE that renders the command counter as a native GET /metrics endpoint on the gunicorn-served webhook apps (github_app, gitlab_webhook, azuredevops_server_webhook, gitea_app). The exporter is meters-only and bridges the SDK's DELTA counter aggregates into prometheus_client metrics on the worker side. gunicorn provisions a shared PROMETHEUS_MULTIPROC_DIR before forking workers and deregisters them on child_exit, so a MultiProcessCollector merges every worker's values at scrape time. The endpoint is only mounted when this exporter is selected, so nothing is exposed by default. Dependency: adds prometheus-client==0.21.1. opentelemetry-exporter-prometheus was explicitly avoided because its PrometheusMetricReader documents no multiprocessing support and it only ships as a 0.x pre-release. Refs: The-PR-Agent#3191
Comment on lines
+65
to
+66
| "counter = provider.get_meter('mp-test').create_counter(" | ||
| "'pr_agent.commands', unit='{command}', description='PR-Agent commands executed')", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements The-PR-Agent#3191: an opt-in native Prometheus scrape endpoint for the OpenTelemetry command telemetry.
Telemetry stays disabled by default and the exporter is only active when
OTEL.EXPORTER_TYPE = "prometheus"— nothing is exposed or changed out of the box. In that mode thepr_agent.commandscounter (and any future gauge instruments) is rendered asGET /metricson the gunicorn-served webhook apps:github_app,gitlab_webhook,azuredevops_server_webhook, andgitea_app.Gunicorn runs with
preload_app = True, so counters must aggregate correctly across workers. The exporter translates each worker's DELTA aggregates intoprometheus_clientmetrics on the worker side, writes them to per-pid state files under a sharedPROMETHEUS_MULTIPROC_DIR, and/metricsmerges every worker's file with aMultiProcessCollectorat scrape time. gunicorn provisions the state directory inwhen_ready(before the first fork) and deregisters workers inchild_exit, so counters stay accurate through worker churn.prometheus-client==0.21.1to the base dependency set and no other runtime dependency.opentelemetry-exporter-prometheus? The maintainer's suggested approach named that package, but itsPrometheusMetricReaderdocuments no multiprocessing support, and the only published versions are 0.x pre-releases. Since multiprocess aggregation under gunicorn is the core requirement of the issue, expecting aMetricExporterto plug into the existingPeriodicExportingMetricReader(my earlier suggestion in the issue comments was based on an inaccurate assumption about that package), I implemented a small in-house bridge onprometheus_clientdirectly. It is ~120 lines, metric-naming and label rules match the OpenMetrics format, and it reuses the existingPeriodicExportingMetricReader+ push-on-release flow. Happy to revisit if maintainers prefer a different dependency strategy.uvicorn, no gunicorn) works without the state directory and serves its own in-process registry.Configuration
The directory can be mounted as a volume for durability;
when_readycreates it when missing. Example scrape config:How this was verified
MeterProvider+PeriodicExportingMetricReaderpath, including name sanitization (pr_agent.commands→pr_agent_commands_total) and label-key sanitization (provider.name→provider_name)./metricsmerges both workers' state files.prometheus_client(gunicorn master safety underpreload_app).ruffand pre-commit hooks clean.closes The-PR-Agent#3191