Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds cumulative Prometheus counters for completed GitHub Actions workflow jobs by persisting terminal job events in a new append-only store table and exposing aggregated totals during metric collection.
Changes:
- Introduces an append-only
workflow_job_completionstable (per supported DB backend) keyed by(owner, repo, identifier, run_attempt)to make completion inserts idempotent. - Records terminal job completions on webhook ingestion and exports new counter metrics:
github_workflow_job_completed_total{owner,repo,workflow_name,name,conclusion}github_workflow_job_duration_seconds_total{owner,repo,workflow_name,name,conclusion}
- Updates docs and tests for the new counters.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/store/types.go | Adds completion record and aggregate types for storing and emitting counter aggregates. |
| pkg/store/store.go | Extends the Store interface with a completion-aggregate read API. |
| pkg/store/sqlite.go | Adds SQLite migration for workflow_job_completions and store method wiring. |
| pkg/store/postgres.go | Adds Postgres migration for workflow_job_completions and store method wiring. |
| pkg/store/mysql.go | Adds MySQL migrations for workflow_job_completions table + aggregate index and store method wiring. |
| pkg/store/chai.go | Adds Chai migration for workflow_job_completions and store method wiring. |
| pkg/store/generic_workflow_job.go | Records terminal completions idempotently and adds aggregation query used by exporter. |
| pkg/exporter/workflow_job.go | Exposes the two new counter metrics with fixed low-cardinality labels and emits them from DB aggregates. |
| pkg/exporter/workflow_job_test.go | Adds a new counter-focused test and updates the store mock for the new interface method. |
| go.mod | Promotes github.com/prometheus/client_model to a direct dependency (used by tests). |
| docs/partials/metrics.md | Documents the two new counter metrics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Started: prometheus.NewDesc( | ||
| "workflow_job_started_timestamp_seconds", | ||
| "Started time of the workflow job", | ||
| nil, nil, | ||
| ), |
| CompletedTotal: prometheus.NewDesc( | ||
| "workflow_job_completed_total", | ||
| "Total number of completed workflow jobs", | ||
| nil, nil, | ||
| ), |
| DurationSecondsTotal: prometheus.NewDesc( | ||
| "workflow_job_duration_seconds_total", | ||
| "Total duration of completed workflow jobs in seconds", | ||
| nil, nil, | ||
| ), |
| var selectWorkflowJobCompletionsQuery = ` | ||
| SELECT | ||
| owner, | ||
| repo, | ||
| workflow_name, | ||
| name, | ||
| conclusion, | ||
| COUNT(*) AS count, | ||
| COALESCE(SUM(duration_seconds), 0.0) AS duration_seconds_total |
Adds prometheus counters github_workflow_job_completed_total and github_workflow_job_duration_seconds_total with a fixed low-cardinality label set (owner, repo, workflow_name, name, conclusion). Introduces an append-only workflow_job_completions table keyed by (owner, repo, identifier, run_attempt) so that the first terminal payload wins and redeliveries are silently ignored, keeping counters monotonic. The existing gauge metrics are left untouched for compatibility. Closes promhippie#712
dbf75d7 to
260d0fa
Compare
tboerger
left a comment
There was a problem hiding this comment.
Sorry for the late response, I have totally forgot this contribution with holidays and conferences and all that stuff. Just 2 tiny changes, than I guess we should be able to finally merge it.
| recorded_at BIGINT, | ||
| PRIMARY KEY(owner, repo, identifier, run_attempt) | ||
| ); | ||
| CREATE INDEX idx_workflow_job_completions_aggregate |
There was a problem hiding this comment.
Handle it like the MySQL implementation, use a separate migration for the index.
| recorded_at BIGINT, | ||
| PRIMARY KEY(owner, repo, identifier, run_attempt) | ||
| ); | ||
| CREATE INDEX idx_workflow_job_completions_aggregate |
There was a problem hiding this comment.
Handle it like the MySQL implementation, use a separate migration for the index.
Adds
github_workflow_job_completed_totalandgithub_workflow_job_duration_seconds_totalcounters for completed workflow jobs, with a fixed low-cardinality label set (owner, repo, workflow_name, name, conclusion).To keep the counters monotonic an append-only
workflow_job_completionstable is introduced, keyed by (owner, repo, identifier, run_attempt). The first terminal payload wins; later redeliveries with the same key are silently ignored via driver-specific idempotent inserts. Existing gauge metrics remain unchanged.Closes #712