branch: main
commit 0d2d372eaf73cd656f4d94dc76d2acc0423c6487
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jan 5 16:13:17 2025 +0100
metrics: Add ‘pending-builds-per-system’ metric.
* src/cuirass/metrics.scm (db-pending-builds): Add ‘system’ parameter
and honor it.
(%metrics): Adjust user accordingly. Add ‘pending-builds-per-system’.
(db-update-metrics): Add ‘db-update-metric’ calls for
‘pending-builds-per-system’.
* tests/metrics.scm ("exec-query"): Add system types.
("pending-builds-per-system")
("pending-builds-per-system, aarch64-linux")
("pending-builds-per-system, x86_64-linux"): New tests.
---
src/cuirass/metrics.scm | 33 ++++++++++++++++++++++++++-------
tests/metrics.scm | 27 ++++++++++++++++++++++++---
2 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/src/cuirass/metrics.scm b/src/cuirass/metrics.scm
index 5a3db4f..0578da3 100644
--- a/src/cuirass/metrics.scm
+++ b/src/cuirass/metrics.scm
@@ -1,6 +1,6 @@
;;; metrics.scm -- Compute and store metrics.
;;; Copyright © 2020 Mathieu Othacehe <[email protected]>
-;;; Copyright © 2024 Ludovic Courtès <[email protected]>
+;;; Copyright © 2024-2025 Ludovic Courtès <[email protected]>
;;;
;;; This file is part of Cuirass.
;;;
@@ -21,6 +21,7 @@
#:use-module (cuirass database)
#:use-module (cuirass logging)
#:use-module (cuirass specification)
+ #:use-module ((guix packages) #:select (%cuirass-supported-systems))
#:use-module (guix records)
#:use-module (squee)
#:use-module (srfi srfi-1)
@@ -122,12 +123,16 @@ to_timestamp(stoptime)::date = 'yesterday'::date;"))))
(exec-query/bind db "SELECT COUNT(*) from Builds
WHERE to_timestamp(timestamp)::date = 'yesterday'::date;"))))
-(define (db-pending-builds _)
- "Return the current pending builds count."
+(define* (db-pending-builds #:optional system)
+ "Return the total number of pending builds; when SYSTEM is specified, return
+the number of pending builds for that system only."
(with-db-connection db
(return-exact
- (exec-query/bind db "SELECT COUNT(*) from Builds
-WHERE status < 0;"))))
+ (if system
+ (exec-query/bind db "\
+SELECT COUNT(*) FROM Builds WHERE status < 0 AND system = " system ";")
+ (exec-query/bind db "\
+SELECT COUNT(*) FROM Builds WHERE status < 0;")))))
(define* (db-percentage-failed-eval-per-spec spec #:key limit)
"Return the failed evaluation percentage for SPEC. If LIMIT is set, limit
@@ -283,7 +288,7 @@ to_timestamp(stoptime)::date > 'today'::date - interval '1
day'"))))
;; Pending builds count.
(metric
(id 'pending-builds)
- (compute-proc db-pending-builds)
+ (compute-proc (lambda (_) (db-pending-builds)))
(field-proc db-current-day-timestamp))
;; New derivations per day.
@@ -329,7 +334,12 @@ to_timestamp(stoptime)::date > 'today'::date - interval '1
day'"))))
(metric
(id 'builds-per-machine-per-day)
(field-type 'string)
- (compute-proc db-builds-count-per-machine))))
+ (compute-proc db-builds-count-per-machine))
+
+ (metric
+ (id 'pending-builds-per-system)
+ (field-type 'string)
+ (compute-proc db-pending-builds))))
(define (metric->type metric)
"Return the index of the given METRIC in %metrics list. This index is used
@@ -466,6 +476,15 @@ UPDATE SET value = " value ", timestamp = " timestamp ";"))
(db-update-metric 'new-derivations-per-day)
(db-update-metric 'pending-builds)
+ ;; Update per-system pending build metrics; use the today-at-midnight
+ ;; as the timestamp, just like for the 'pending-builds' metric.
+ (let* ((now (time-second (current-time time-utc)))
+ (today (- now (modulo now 86400))))
+ (for-each (lambda (system)
+ (db-update-metric 'pending-builds-per-system system
+ #:timestamp today))
+ %cuirass-supported-systems))
+
;; Update specification related metrics.
(for-each (lambda (spec)
(db-update-metric
diff --git a/tests/metrics.scm b/tests/metrics.scm
index 13fbecf..de2d88b 100644
--- a/tests/metrics.scm
+++ b/tests/metrics.scm
@@ -1,5 +1,6 @@
;;; metrics.scm - tests for the (cuirass metrics) module
;;; Copyright © 2020, 2021 Mathieu Othacehe <[email protected]>
+;;; Copyright © 2025 Ludovic Courtès <[email protected]>
;;;
;;; This file is part of Cuirass.
;;;
@@ -73,16 +74,16 @@ INSERT INTO Workers (name, address, machine, systems,
last_seen) VALUES
(exec-query (%db) (format #f "\
INSERT INTO Builds (id, derivation, evaluation, job_name, system,
nix_name, log, status, timestamp, starttime, stoptime) VALUES
-(1, '/gnu/store/1.drv', 2, '', '', '', '', 0, ~a, ~a, ~a);\
+(1, '/gnu/store/1.drv', 2, '', 'x86_64-linux', '', '', 0, ~a, ~a, ~a);\
" yesterday (+ yesterday 1600) (+ yesterday 2600)))
(exec-query (%db) (format #f "\
INSERT INTO Builds (id, derivation, evaluation, job_name, system,
nix_name, log, status, timestamp, starttime, stoptime) VALUES
-(2, '/gnu/store/2.drv', 2, '', '', '', '', -2, 0, 0, 0);"))
+(2, '/gnu/store/2.drv', 2, '', 'aarch64-linux', '', '', -2, 0, 0, 0);"))
(exec-query (%db) (format #f "\
INSERT INTO Builds (id, derivation, evaluation, job_name, system,
nix_name, log, status, timestamp, starttime, stoptime) VALUES
-(3, '/gnu/store/3.drv', 4, '', '', '', '', 0, 1600174451, 1600174451,
+(3, '/gnu/store/3.drv', 4, '', 'x86_64-linux', '', '', 0, 1600174451,
1600174451,
1600174651);"))))
(test-equal "average-eval-duration-per-spec"
@@ -103,6 +104,26 @@ nix_name, log, status, timestamp, starttime, stoptime)
VALUES
(db-update-metric 'pending-builds)
(db-get-metrics-with-id 'pending-builds)))
+ (test-equal "pending-builds-per-system"
+ `((,today "aarch64-linux" 1.0) (,today "x86_64-linux" 0.0))
+ (begin
+ (db-update-metric 'pending-builds-per-system "x86_64-linux"
+ #:timestamp today)
+ (db-update-metric 'pending-builds-per-system "aarch64-linux"
+ #:timestamp today)
+ (db-get-metrics-with-id 'pending-builds-per-system
+ #:timestamp? #t)))
+
+ (test-equal "pending-builds-per-system, aarch64-linux"
+ `((,today . 1.0))
+ (db-get-metrics-with-id 'pending-builds-per-system
+ #:value "aarch64-linux"))
+
+ (test-equal "pending-builds-per-system, x86_64-linux"
+ `((,today . 0.0))
+ (db-get-metrics-with-id 'pending-builds-per-system
+ #:value "x86_64-linux"))
+
(test-equal "new-derivations-per-day"
`((,yesterday . 1.0))
(begin