Trim down metrics cardinality (#3003)
This commit is contained in:
		
							parent
							
								
									2117fd1892
								
							
						
					
					
						commit
						b511953df7
					
				|  | @ -1,8 +1,6 @@ | ||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"strconv" |  | ||||||
| 
 |  | ||||||
| 	"github.com/actions/actions-runner-controller/github/actions" | 	"github.com/actions/actions-runner-controller/github/actions" | ||||||
| 	"github.com/prometheus/client_golang/prometheus" | 	"github.com/prometheus/client_golang/prometheus" | ||||||
| ) | ) | ||||||
|  | @ -18,8 +16,6 @@ const ( | ||||||
| 	labelKeyJobWorkflowRef          = "job_workflow_ref" | 	labelKeyJobWorkflowRef          = "job_workflow_ref" | ||||||
| 	labelKeyEventName               = "event_name" | 	labelKeyEventName               = "event_name" | ||||||
| 	labelKeyJobResult               = "job_result" | 	labelKeyJobResult               = "job_result" | ||||||
| 	labelKeyRunnerID                = "runner_id" |  | ||||||
| 	labelKeyRunnerName              = "runner_name" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const githubScaleSetSubsystem = "gha" | const githubScaleSetSubsystem = "gha" | ||||||
|  | @ -43,10 +39,15 @@ var ( | ||||||
| 		labelKeyEventName, | 		labelKeyEventName, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	completedJobsTotalLabels   = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName) | 	completedJobsTotalLabels   = append(jobLabels, labelKeyJobResult) | ||||||
| 	jobExecutionDurationLabels = append(jobLabels, labelKeyJobResult, labelKeyRunnerID, labelKeyRunnerName) | 	jobExecutionDurationLabels = append(jobLabels, labelKeyJobResult) | ||||||
| 	startedJobsTotalLabels     = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName) | 	startedJobsTotalLabels     = jobLabels | ||||||
| 	jobStartupDurationLabels   = append(jobLabels, labelKeyRunnerID, labelKeyRunnerName) | 	jobStartupDurationLabels   = []string{ | ||||||
|  | 		labelKeyRepository, | ||||||
|  | 		labelKeyOrganization, | ||||||
|  | 		labelKeyEnterprise, | ||||||
|  | 		labelKeyEventName, | ||||||
|  | 	} | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // metrics
 | // metrics
 | ||||||
|  | @ -274,19 +275,24 @@ func (b *baseLabels) scaleSetLabels() prometheus.Labels { | ||||||
| 
 | 
 | ||||||
| func (b *baseLabels) completedJobLabels(msg *actions.JobCompleted) prometheus.Labels { | func (b *baseLabels) completedJobLabels(msg *actions.JobCompleted) prometheus.Labels { | ||||||
| 	l := b.jobLabels(&msg.JobMessageBase) | 	l := b.jobLabels(&msg.JobMessageBase) | ||||||
| 	l[labelKeyRunnerID] = strconv.Itoa(msg.RunnerId) |  | ||||||
| 	l[labelKeyJobResult] = msg.Result | 	l[labelKeyJobResult] = msg.Result | ||||||
| 	l[labelKeyRunnerName] = msg.RunnerName |  | ||||||
| 	return l | 	return l | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (b *baseLabels) startedJobLabels(msg *actions.JobStarted) prometheus.Labels { | func (b *baseLabels) startedJobLabels(msg *actions.JobStarted) prometheus.Labels { | ||||||
| 	l := b.jobLabels(&msg.JobMessageBase) | 	l := b.jobLabels(&msg.JobMessageBase) | ||||||
| 	l[labelKeyRunnerID] = strconv.Itoa(msg.RunnerId) |  | ||||||
| 	l[labelKeyRunnerName] = msg.RunnerName |  | ||||||
| 	return l | 	return l | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (b *baseLabels) jobStartupDurationLabels(msg *actions.JobStarted) prometheus.Labels { | ||||||
|  | 	return prometheus.Labels{ | ||||||
|  | 		labelKeyEnterprise:   b.enterprise, | ||||||
|  | 		labelKeyOrganization: b.organization, | ||||||
|  | 		labelKeyRepository:   b.repository, | ||||||
|  | 		labelKeyEventName:    msg.EventName, | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (m *metricsExporter) withBaseLabels(base baseLabels) { | func (m *metricsExporter) withBaseLabels(base baseLabels) { | ||||||
| 	m.baseLabels = base | 	m.baseLabels = base | ||||||
| } | } | ||||||
|  | @ -307,6 +313,7 @@ func (m *metricsExporter) publishJobStarted(msg *actions.JobStarted) { | ||||||
| 	l := m.startedJobLabels(msg) | 	l := m.startedJobLabels(msg) | ||||||
| 	startedJobsTotal.With(l).Inc() | 	startedJobsTotal.With(l).Inc() | ||||||
| 
 | 
 | ||||||
|  | 	l = m.jobStartupDurationLabels(msg) | ||||||
| 	startupDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.ScaleSetAssignTime.Unix() | 	startupDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.ScaleSetAssignTime.Unix() | ||||||
| 	jobStartupDurationSeconds.With(l).Observe(float64(startupDuration)) | 	jobStartupDurationSeconds.With(l).Observe(float64(startupDuration)) | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue