Skip to content

Commit b511953

Browse files
authored
Trim down metrics cardinality (#3003)
1 parent 2117fd1 commit b511953

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

cmd/githubrunnerscalesetlistener/metrics.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

33
import (
4-
"strconv"
5-
64
"github.com/actions/actions-runner-controller/github/actions"
75
"github.com/prometheus/client_golang/prometheus"
86
)
@@ -18,8 +16,6 @@ const (
1816
labelKeyJobWorkflowRef = "job_workflow_ref"
1917
labelKeyEventName = "event_name"
2018
labelKeyJobResult = "job_result"
21-
labelKeyRunnerID = "runner_id"
22-
labelKeyRunnerName = "runner_name"
2319
)
2420

2521
const githubScaleSetSubsystem = "gha"
@@ -43,10 +39,15 @@ var (
4339
labelKeyEventName,
4440
}
4541

46-
completedJobsTotalLabels = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName)
47-
jobExecutionDurationLabels = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName)
48-
startedJobsTotalLabels = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName)
49-
jobStartupDurationLabels = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName)
42+
completedJobsTotalLabels = append(jobLabels, labelKeyJobResult)
43+
jobExecutionDurationLabels = append(jobLabels, labelKeyJobResult)
44+
startedJobsTotalLabels = jobLabels
45+
jobStartupDurationLabels = []string{
46+
labelKeyRepository,
47+
labelKeyOrganization,
48+
labelKeyEnterprise,
49+
labelKeyEventName,
50+
}
5051
)
5152

5253
// metrics
@@ -274,19 +275,24 @@ func (b *baseLabels) scaleSetLabels() prometheus.Labels {
274275

275276
func (b *baseLabels) completedJobLabels(msg *actions.JobCompleted) prometheus.Labels {
276277
l := b.jobLabels(&msg.JobMessageBase)
277-
l[labelKeyRunnerID] = strconv.Itoa(msg.RunnerId)
278278
l[labelKeyJobResult] = msg.Result
279-
l[labelKeyRunnerName] = msg.RunnerName
280279
return l
281280
}
282281

283282
func (b *baseLabels) startedJobLabels(msg *actions.JobStarted) prometheus.Labels {
284283
l := b.jobLabels(&msg.JobMessageBase)
285-
l[labelKeyRunnerID] = strconv.Itoa(msg.RunnerId)
286-
l[labelKeyRunnerName] = msg.RunnerName
287284
return l
288285
}
289286

287+
func (b *baseLabels) jobStartupDurationLabels(msg *actions.JobStarted) prometheus.Labels {
288+
return prometheus.Labels{
289+
labelKeyEnterprise: b.enterprise,
290+
labelKeyOrganization: b.organization,
291+
labelKeyRepository: b.repository,
292+
labelKeyEventName: msg.EventName,
293+
}
294+
}
295+
290296
func (m *metricsExporter) withBaseLabels(base baseLabels) {
291297
m.baseLabels = base
292298
}
@@ -307,6 +313,7 @@ func (m *metricsExporter) publishJobStarted(msg *actions.JobStarted) {
307313
l := m.startedJobLabels(msg)
308314
startedJobsTotal.With(l).Inc()
309315

316+
l = m.jobStartupDurationLabels(msg)
310317
startupDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.ScaleSetAssignTime.Unix()
311318
jobStartupDurationSeconds.With(l).Observe(float64(startupDuration))
312319
}

0 commit comments

Comments
 (0)