metrics: build jobs arch label

Add the architecture label to build jobs
which will enable filtering and monitoring
build jobs by architecture. Build job results
contain the `arch` field in the results struct,
this is then used to pass to the metrics, where
there is a value, otherwise it is set to an
empty string.
This commit is contained in:
Gianluca Zuccarelli 2022-07-20 16:32:15 +01:00 committed by Tomáš Hozza
parent 8b4aff3857
commit 9f4e765657
2 changed files with 16 additions and 7 deletions

View file

@ -16,7 +16,7 @@ var (
Namespace: namespace,
Subsystem: workerSubsystem,
Help: "Total jobs",
}, []string{"type", "status", "tenant"})
}, []string{"type", "status", "tenant", "arch"})
)
var (
@ -44,7 +44,7 @@ var (
Subsystem: workerSubsystem,
Help: "Duration spent by workers on a job.",
Buckets: []float64{.1, .2, .5, 1, 2, 4, 8, 16, 32, 40, 48, 64, 96, 128, 160, 192, 224, 256, 320, 382, 448, 512, 640, 768, 896, 1024, 1280, 1536, 1792, 2049},
}, []string{"type", "status", "tenant"})
}, []string{"type", "status", "tenant", "arch"})
)
var (
@ -70,7 +70,7 @@ func DequeueJobMetrics(pending time.Time, started time.Time, jobType, tenant str
}
}
func CancelJobMetrics(started time.Time, jobType string, tenant string) {
func CancelJobMetrics(started time.Time, jobType, tenant string) {
if !started.IsZero() {
RunningJobs.WithLabelValues(jobType, tenant).Dec()
} else {
@ -78,11 +78,11 @@ func CancelJobMetrics(started time.Time, jobType string, tenant string) {
}
}
func FinishJobMetrics(started time.Time, finished time.Time, canceled bool, jobType, tenant string, status clienterrors.StatusCode) {
func FinishJobMetrics(started time.Time, finished time.Time, canceled bool, jobType, tenant, arch string, status clienterrors.StatusCode) {
if !finished.IsZero() && !canceled {
diff := finished.Sub(started).Seconds()
JobDuration.WithLabelValues(jobType, status.ToString(), tenant).Observe(diff)
TotalJobs.WithLabelValues(jobType, status.ToString(), tenant).Inc()
JobDuration.WithLabelValues(jobType, status.ToString(), tenant, arch).Observe(diff)
TotalJobs.WithLabelValues(jobType, status.ToString(), tenant, arch).Inc()
RunningJobs.WithLabelValues(jobType, tenant).Dec()
}
}

View file

@ -571,7 +571,8 @@ func (s *Server) FinishJob(token uuid.UUID, result json.RawMessage) error {
logrus.Errorf("error finding job status: %v", err)
} else {
statusCode := clienterrors.GetStatusCode(jobResult.JobError)
prometheus.FinishJobMetrics(status.Started, status.Finished, status.Canceled, jobType, channel, statusCode)
arch := getBuildJobArch(jobType, result)
prometheus.FinishJobMetrics(status.Started, status.Finished, status.Canceled, jobType, channel, arch, statusCode)
}
// Move artifacts from the temporary location to the final job
@ -587,6 +588,14 @@ func (s *Server) FinishJob(token uuid.UUID, result json.RawMessage) error {
return nil
}
func getBuildJobArch(jobType string, jobResult json.RawMessage) string {
if !strings.HasPrefix(jobType, "osbuild:") {
return ""
}
arch := strings.Split(jobType, ":")[1]
return arch
}
// apiHandlers implements api.ServerInterface - the http api route handlers
// generated from api/openapi.yml. This is a separate object, because these
// handlers should not be exposed on the `Server` object.