Skip to content

feat: cumulative workflow job completion counters#721

Open
DenisBY wants to merge 2 commits into
promhippie:masterfrom
DenisBY:feat/workflow-job-counters
Open

feat: cumulative workflow job completion counters#721
DenisBY wants to merge 2 commits into
promhippie:masterfrom
DenisBY:feat/workflow-job-counters

Conversation

@DenisBY

@DenisBY DenisBY commented Jul 7, 2026

Copy link
Copy Markdown

Adds github_workflow_job_completed_total and github_workflow_job_duration_seconds_total counters 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_completions table 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

Copilot AI review requested due to automatic review settings July 7, 2026 08:15

Copilot AI left a comment

Copy link
Copy Markdown

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 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_completions table (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
DenisMkS added 2 commits July 8, 2026 19:19
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
@tboerger tboerger force-pushed the feat/workflow-job-counters branch from dbf75d7 to 260d0fa Compare July 8, 2026 17:19
@tboerger tboerger added the enhancement New feature or request label Jul 8, 2026
@tboerger tboerger added this to the v17.0.0 milestone Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add cumulative Prometheus counters for completed workflow jobs

4 participants