Skip to content

Commit 34f2a62

Browse files
committed
feat: Add new metric which would enable to join job to runner pod to query memory, cpu and cpu throttling metrics
1 parent 12eedb9 commit 34f2a62

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmd/ghalistener/metrics/metrics.go

+24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
labelKeyJobName = "job_name"
2121
labelKeyEventName = "event_name"
2222
labelKeyJobResult = "job_result"
23+
labelKeyRunnerPodName = "pod_name"
2324
)
2425

2526
const githubScaleSetSubsystem = "gha"
@@ -47,6 +48,7 @@ var (
4748
startedJobsTotalLabels = jobLabels
4849
lastJobStartupDurationLabels = jobLabels
4950
jobQueueDurationLabels = jobLabels
51+
runnerLabels = append(jobLabels, labelKeyRunnerPodName)
5052
)
5153

5254
var (
@@ -168,6 +170,15 @@ var (
168170
},
169171
lastJobExecutionDurationLabels,
170172
)
173+
174+
runnerJob = prometheus.NewGaugeVec(
175+
prometheus.GaugeOpts{
176+
Subsystem: githubScaleSetSubsystem,
177+
Name: "runner_job",
178+
Help: "Job information for the runner.",
179+
},
180+
runnerLabels,
181+
)
171182
)
172183

173184
type baseLabels struct {
@@ -212,6 +223,12 @@ func (b *baseLabels) startedJobLabels(msg *actions.JobStarted) prometheus.Labels
212223
return l
213224
}
214225

226+
func (b *baseLabels) runnerLabels(msg *actions.JobMessageBase, runnerName string) prometheus.Labels {
227+
l := b.jobLabels(msg)
228+
l[labelKeyRunnerPodName] = runnerName
229+
return l
230+
}
231+
215232
//go:generate mockery --name Publisher --output ./mocks --outpkg mocks --case underscore
216233
type Publisher interface {
217234
PublishStatic(min, max int)
@@ -268,6 +285,7 @@ func NewExporter(config ExporterConfig) ServerPublisher {
268285
jobLastQueueDurationSeconds,
269286
jobLastStartupDurationSeconds,
270287
jobLastExecutionDurationSeconds,
288+
runnerJob,
271289
)
272290

273291
mux := http.NewServeMux()
@@ -334,6 +352,9 @@ func (e *exporter) PublishJobStarted(msg *actions.JobStarted) {
334352
queueDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.QueueTime.Unix()
335353
jobLastQueueDurationSeconds.With(l).Set(float64(queueDuration))
336354
}
355+
356+
rl := e.runnerLabels(&msg.JobMessageBase, msg.RunnerName)
357+
runnerJob.With(rl).Set(1)
337358
}
338359

339360
func (e *exporter) PublishJobCompleted(msg *actions.JobCompleted) {
@@ -344,6 +365,9 @@ func (e *exporter) PublishJobCompleted(msg *actions.JobCompleted) {
344365
executionDuration := msg.JobMessageBase.FinishTime.Unix() - msg.JobMessageBase.RunnerAssignTime.Unix()
345366
jobLastExecutionDurationSeconds.With(l).Set(float64(executionDuration))
346367
}
368+
369+
rl := e.runnerLabels(&msg.JobMessageBase, msg.RunnerName)
370+
runnerJob.Delete(rl)
347371
}
348372

349373
func (m *exporter) PublishDesiredRunners(count int) {

0 commit comments

Comments
 (0)