feat: cumulative workflow job completion counters#721
Open
DenisBY wants to merge 2 commits into
Open
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.
Comment on lines
+113
to
+117
| Started: prometheus.NewDesc( | ||
| "workflow_job_started_timestamp_seconds", | ||
| "Started time of the workflow job", | ||
| nil, nil, | ||
| ), |
Comment on lines
+118
to
+122
| CompletedTotal: prometheus.NewDesc( | ||
| "workflow_job_completed_total", | ||
| "Total number of completed workflow jobs", | ||
| nil, nil, | ||
| ), |
Comment on lines
+123
to
+127
| DurationSecondsTotal: prometheus.NewDesc( | ||
| "workflow_job_duration_seconds_total", | ||
| "Total duration of completed workflow jobs in seconds", | ||
| nil, nil, | ||
| ), |
Comment on lines
+363
to
+371
| 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
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.
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