From 254055111b4962e169b4ce62edf443ef97552622 Mon Sep 17 00:00:00 2001 From: sindunuragarp Date: Tue, 14 Nov 2023 08:57:19 +0100 Subject: [PATCH 1/3] add runner_name as extra label --- pkg/actionsmetrics/event_reader.go | 2 +- pkg/actionsmetrics/metrics.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 606891fe5e..201268b046 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -137,7 +137,7 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds()) case "completed": - githubWorkflowJobsCompletedTotal.With(labels).Inc() + githubWorkflowJobsCompletedTotal.With(extraLabel("runner_name", *e.WorkflowJob.RunnerName, labels)).Inc() // job_conclusion -> (neutral, success, skipped, cancelled, timed_out, action_required, failure) githubWorkflowJobConclusionsTotal.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Inc() diff --git a/pkg/actionsmetrics/metrics.go b/pkg/actionsmetrics/metrics.go index 972a6f9f5e..877b905b81 100644 --- a/pkg/actionsmetrics/metrics.go +++ b/pkg/actionsmetrics/metrics.go @@ -175,7 +175,7 @@ var ( Name: "github_workflow_jobs_completed_total", Help: "Total count of workflow jobs completed (events where job_status=completed)", }, - metricLabels(), + metricLabels("runner_name"), ) githubWorkflowJobFailuresTotal = prometheus.NewCounterVec( prometheus.CounterOpts{ From 70e3260ac81251dc3dcaf40d6bd5c546537af33f Mon Sep 17 00:00:00 2001 From: sindunuragarp Date: Tue, 14 Nov 2023 10:46:34 +0100 Subject: [PATCH 2/3] check for existence of runner name --- pkg/actionsmetrics/event_reader.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 201268b046..8867c47594 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -137,7 +137,11 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds()) case "completed": - githubWorkflowJobsCompletedTotal.With(extraLabel("runner_name", *e.WorkflowJob.RunnerName, labels)).Inc() + workflowCompletedLabels := labels + if n := e.WorkflowJob.RunnerName; n != nil { + workflowCompletedLabels = extraLabel("runner_name", *n, labels) + } + githubWorkflowJobsCompletedTotal.With(workflowCompletedLabels).Inc() // job_conclusion -> (neutral, success, skipped, cancelled, timed_out, action_required, failure) githubWorkflowJobConclusionsTotal.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Inc() From 5b6d8cc45eda1cae7042660b23aea6f757d78941 Mon Sep 17 00:00:00 2001 From: sindunuragarp Date: Tue, 14 Nov 2023 12:00:45 +0100 Subject: [PATCH 3/3] keep consistency of cardinality --- pkg/actionsmetrics/event_reader.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/actionsmetrics/event_reader.go b/pkg/actionsmetrics/event_reader.go index 8867c47594..a1b7e2f40e 100644 --- a/pkg/actionsmetrics/event_reader.go +++ b/pkg/actionsmetrics/event_reader.go @@ -137,11 +137,11 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in githubWorkflowJobQueueDurationSeconds.With(labels).Observe(parseResult.QueueTime.Seconds()) case "completed": - workflowCompletedLabels := labels + var rn string if n := e.WorkflowJob.RunnerName; n != nil { - workflowCompletedLabels = extraLabel("runner_name", *n, labels) + rn = *n } - githubWorkflowJobsCompletedTotal.With(workflowCompletedLabels).Inc() + githubWorkflowJobsCompletedTotal.With(extraLabel("runner_name", rn, labels)).Inc() // job_conclusion -> (neutral, success, skipped, cancelled, timed_out, action_required, failure) githubWorkflowJobConclusionsTotal.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Inc()