Skip to content

Commit

Permalink
ACCDT-1239: reduce cardinality of metrics (#4)
Browse files Browse the repository at this point in the history
* remove unused labels

* only store duration for specific statuses

* do not process empty labels
  • Loading branch information
sindunuragarp authored Nov 15, 2023
1 parent be1bfcb commit db13bb6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions pkg/actionsmetrics/event_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
keysAndValues = []interface{}{"job_id", fmt.Sprint(*e.WorkflowJob.ID)}
)

if len(e.WorkflowJob.Labels) == 0 {
return
}

runsOn := strings.Join(e.WorkflowJob.Labels, `,`)
labels["runs_on"] = runsOn

Expand All @@ -75,10 +79,6 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
labels["repository"] = *n
keysAndValues = append(keysAndValues, "repository", *n)
}
if n := e.Repo.FullName; n != nil {
labels["repository_full_name"] = *n
keysAndValues = append(keysAndValues, "repository_full_name", *n)
}

if e.Repo.Owner != nil {
if l := e.Repo.Owner.Login; l != nil {
Expand All @@ -98,19 +98,13 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
labels["organization"] = org

var wn string
var hb string
if e.WorkflowJob != nil {
if n := e.WorkflowJob.WorkflowName; n != nil {
wn = *n
keysAndValues = append(keysAndValues, "workflow_name", *n)
}
if n := e.WorkflowJob.HeadBranch; n != nil {
hb = *n
keysAndValues = append(keysAndValues, "head_branch", *n)
}
}
labels["workflow_name"] = wn
labels["head_branch"] = hb

log := reader.Log.WithValues(keysAndValues...)

Expand Down Expand Up @@ -203,8 +197,10 @@ func (reader *EventReader) ProcessWorkflowJobEvent(ctx context.Context, event in
).Inc()
}

if runTimeSeconds != nil {
githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(*runTimeSeconds)
if *e.WorkflowJob.Conclusion != "cancelled" && *e.WorkflowJob.Conclusion != "skipped" && *e.WorkflowJob.Conclusion != "timed_out" {
if runTimeSeconds != nil {
githubWorkflowJobRunDurationSeconds.With(extraLabel("job_conclusion", *e.WorkflowJob.Conclusion, labels)).Observe(*runTimeSeconds)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/actionsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func initGithubWorkflowJobRunDurationSeconds(buckets []float64) *prometheus.Hist
}

var (
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "repository_full_name", "owner", "workflow_name", "head_branch"}
commonLabels = []string{"runs_on", "job_name", "organization", "repository", "owner", "workflow_name"}
githubWorkflowJobQueueDurationSeconds *prometheus.HistogramVec
githubWorkflowJobRunDurationSeconds *prometheus.HistogramVec
githubWorkflowJobConclusionsTotal = prometheus.NewCounterVec(
Expand Down

0 comments on commit db13bb6

Please sign in to comment.