diff --git a/internal/prometheus/job_metrics.go b/internal/prometheus/job_metrics.go index 3d980b327..b0f63c3fa 100644 --- a/internal/prometheus/job_metrics.go +++ b/internal/prometheus/job_metrics.go @@ -61,9 +61,9 @@ func EnqueueJobMetrics(jobType string) { PendingJobs.WithLabelValues(jobType).Inc() } -func DequeueJobMetrics(queued time.Time, started time.Time, jobType string) { - if !started.IsZero() && !queued.IsZero() { - diff := started.Sub(queued).Seconds() +func DequeueJobMetrics(pending time.Time, started time.Time, jobType string) { + if !started.IsZero() && !pending.IsZero() { + diff := started.Sub(pending).Seconds() JobWaitDuration.WithLabelValues(jobType).Observe(diff) PendingJobs.WithLabelValues(jobType).Dec() RunningJobs.WithLabelValues(jobType).Inc() diff --git a/internal/worker/server.go b/internal/worker/server.go index 56c5fa0f6..1416fb6ef 100644 --- a/internal/worker/server.go +++ b/internal/worker/server.go @@ -455,13 +455,23 @@ func (s *Server) requestJob(ctx context.Context, arch string, jobTypes []string, return } + // Record how long the job has been pending for, that is either how + // long it has been queued for, in case it has no dependencies, or + // how long it has been since all its dependencies finished, if it + // has any. + pending := status.Queued + for _, depID := range depIDs { // TODO: include type of arguments var result json.RawMessage - _, result, _, _, _, _, _, err = s.jobs.JobStatus(depID) + var finished time.Time + _, result, _, _, finished, _, _, err = s.jobs.JobStatus(depID) if err != nil { return } + if finished.After(pending) { + pending = finished + } dynamicArgs = append(dynamicArgs, result) } @@ -474,7 +484,7 @@ func (s *Server) requestJob(ctx context.Context, arch string, jobTypes []string, // TODO: Drop the ':$architecture' for metrics too, first prometheus queries for alerts and // dashboards need to be adjusted. - prometheus.DequeueJobMetrics(status.Queued, status.Started, jobType) + prometheus.DequeueJobMetrics(pending, status.Started, jobType) if jobType == "osbuild:"+arch { jobType = "osbuild" } else if jobType == "osbuild-koji:"+arch {