Skip to content

Commit

Permalink
feat: Add metric to export last duration job spent waiting in queue i…
Browse files Browse the repository at this point in the history
…n otherwords waiting for a runner
  • Loading branch information
tiithansen committed Jan 4, 2025
1 parent ddda17f commit 12eedb9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/ghalistener/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
lastJobExecutionDurationLabels = append(jobLabels, labelKeyJobResult)
startedJobsTotalLabels = jobLabels
lastJobStartupDurationLabels = jobLabels
jobQueueDurationLabels = jobLabels
)

var (
Expand Down Expand Up @@ -141,6 +142,15 @@ var (

// Becasue jobs might not run with uniform frequency calculating rates from histogram might not be suitable for all jobs.
// With last durations we can use prometheus <aggr>_over_time functions to display the last duration of the job.
jobLastQueueDurationSeconds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetSubsystem,
Name: "job_last_queue_duration_seconds",
Help: "Last duration spent in the queue by the job (in seconds).",
},
jobQueueDurationLabels,
)

jobLastStartupDurationSeconds = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: githubScaleSetSubsystem,
Expand Down Expand Up @@ -255,6 +265,7 @@ func NewExporter(config ExporterConfig) ServerPublisher {
idleRunners,
startedJobsTotal,
completedJobsTotal,
jobLastQueueDurationSeconds,
jobLastStartupDurationSeconds,
jobLastExecutionDurationSeconds,
)
Expand Down Expand Up @@ -318,6 +329,11 @@ func (e *exporter) PublishJobStarted(msg *actions.JobStarted) {
startupDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.ScaleSetAssignTime.Unix()
jobLastStartupDurationSeconds.With(l).Set(float64(startupDuration))
}

if !msg.JobMessageBase.QueueTime.IsZero() && !msg.JobMessageBase.RunnerAssignTime.IsZero() {
queueDuration := msg.JobMessageBase.RunnerAssignTime.Unix() - msg.JobMessageBase.QueueTime.Unix()
jobLastQueueDurationSeconds.With(l).Set(float64(queueDuration))
}
}

func (e *exporter) PublishJobCompleted(msg *actions.JobCompleted) {
Expand Down

0 comments on commit 12eedb9

Please sign in to comment.