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 Dec 13, 2024
1 parent 83a75d7 commit c2eba45
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 @@ -139,6 +140,15 @@ var (
completedJobsTotalLabels,
)

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 @@ -253,6 +263,7 @@ func NewExporter(config ExporterConfig) ServerPublisher {
idleRunners,
startedJobsTotal,
completedJobsTotal,
jobLastQueueDurationSeconds,
jobLastStartupDurationSeconds,
jobLastExecutionDurationSeconds,
)
Expand Down Expand Up @@ -316,6 +327,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 c2eba45

Please sign in to comment.