Skip to content

Commit

Permalink
feat: Add new metric which would enable to join job to runner pod to …
Browse files Browse the repository at this point in the history
…query memory, cpu and cpu throttling metrics
  • Loading branch information
tiithansen committed Jan 4, 2025
1 parent 12eedb9 commit 34f2a62
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/ghalistener/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
labelKeyJobName = "job_name"
labelKeyEventName = "event_name"
labelKeyJobResult = "job_result"
labelKeyRunnerPodName = "pod_name"
)

const githubScaleSetSubsystem = "gha"
Expand Down Expand Up @@ -47,6 +48,7 @@ var (
startedJobsTotalLabels = jobLabels
lastJobStartupDurationLabels = jobLabels
jobQueueDurationLabels = jobLabels
runnerLabels = append(jobLabels, labelKeyRunnerPodName)
)

var (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -268,6 +285,7 @@ func NewExporter(config ExporterConfig) ServerPublisher {
jobLastQueueDurationSeconds,
jobLastStartupDurationSeconds,
jobLastExecutionDurationSeconds,
runnerJob,
)

mux := http.NewServeMux()
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 34f2a62

Please sign in to comment.