From 34f2a6271a86786fed4ae543d1861f9669be9e71 Mon Sep 17 00:00:00 2001 From: Tiit Hansen Date: Fri, 13 Dec 2024 09:36:33 +0200 Subject: [PATCH] feat: Add new metric which would enable to join job to runner pod to query memory, cpu and cpu throttling metrics --- cmd/ghalistener/metrics/metrics.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/ghalistener/metrics/metrics.go b/cmd/ghalistener/metrics/metrics.go index c06b688361..ae51ce4e5a 100644 --- a/cmd/ghalistener/metrics/metrics.go +++ b/cmd/ghalistener/metrics/metrics.go @@ -20,6 +20,7 @@ const ( labelKeyJobName = "job_name" labelKeyEventName = "event_name" labelKeyJobResult = "job_result" + labelKeyRunnerPodName = "pod_name" ) const githubScaleSetSubsystem = "gha" @@ -47,6 +48,7 @@ var ( startedJobsTotalLabels = jobLabels lastJobStartupDurationLabels = jobLabels jobQueueDurationLabels = jobLabels + runnerLabels = append(jobLabels, labelKeyRunnerPodName) ) var ( @@ -168,6 +170,15 @@ var ( }, lastJobExecutionDurationLabels, ) + + runnerJob = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Subsystem: githubScaleSetSubsystem, + Name: "runner_job", + Help: "Job information for the runner.", + }, + runnerLabels, + ) ) type baseLabels struct { @@ -212,6 +223,12 @@ func (b *baseLabels) startedJobLabels(msg *actions.JobStarted) prometheus.Labels return l } +func (b *baseLabels) runnerLabels(msg *actions.JobMessageBase, runnerName string) prometheus.Labels { + l := b.jobLabels(msg) + l[labelKeyRunnerPodName] = runnerName + return l +} + //go:generate mockery --name Publisher --output ./mocks --outpkg mocks --case underscore type Publisher interface { PublishStatic(min, max int) @@ -268,6 +285,7 @@ func NewExporter(config ExporterConfig) ServerPublisher { jobLastQueueDurationSeconds, jobLastStartupDurationSeconds, jobLastExecutionDurationSeconds, + runnerJob, ) mux := http.NewServeMux() @@ -334,6 +352,9 @@ func (e *exporter) PublishJobStarted(msg *actions.JobStarted) { queueDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.QueueTime.Unix() jobLastQueueDurationSeconds.With(l).Set(float64(queueDuration)) } + + rl := e.runnerLabels(&msg.JobMessageBase, msg.RunnerName) + runnerJob.With(rl).Set(1) } func (e *exporter) PublishJobCompleted(msg *actions.JobCompleted) { @@ -344,6 +365,9 @@ func (e *exporter) PublishJobCompleted(msg *actions.JobCompleted) { executionDuration := msg.JobMessageBase.FinishTime.Unix() - msg.JobMessageBase.RunnerAssignTime.Unix() jobLastExecutionDurationSeconds.With(l).Set(float64(executionDuration)) } + + rl := e.runnerLabels(&msg.JobMessageBase, msg.RunnerName) + runnerJob.Delete(rl) } func (m *exporter) PublishDesiredRunners(count int) {