diff options
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index e5367c6..1dddc72 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -414,11 +414,18 @@ PRAGMA optimize;") (let ((setup-failures-total (make-gauge-metric registry "setup_failures_total" - #:labels '(agent_id reason)))) + #:labels '(agent_id reason))) + (background-jobs-inserted-total + (make-counter-metric registry + "coordinator_background_job_inserted_total" + #:labels '(job)))) (fibers-let ((setup-failure-counts (with-time-logging "counting setup failures" - (datastore-count-setup-failures datastore)))) + (datastore-count-setup-failures datastore))) + (background-job-counts + (with-time-logging "counting background jobs" + (datastore-count-background-jobs datastore)))) (for-each (match-lambda (((agent-id reason) . count) @@ -427,7 +434,14 @@ PRAGMA optimize;") #:label-values `((agent_id . ,agent-id) (reason . ,reason))))) - setup-failure-counts))) + setup-failure-counts) + + (for-each (match-lambda + ((type . count) + (metric-increment background-jobs-inserted-total + #:by count + #:label-values `((job . ,type))))) + background-job-counts))) #t) (define-method (datastore-update-metrics! @@ -1937,7 +1951,7 @@ WHERE builds.id = :build_id" result))) (let ((build-ids - (call-with-thread + (call-with-thread/delay-logging (slot-ref datastore 'reader-thread-pool) (lambda (db) (all-build-ids db))))) @@ -4506,7 +4520,14 @@ RETURNING id" (write args port)))) (match (sqlite-step-and-reset statement) - (#(id) id)))))) + (#(id) + + (metric-increment + (metrics-registry-fetch-metric + (slot-ref datastore 'metrics-registry) + "coordinator_background_job_inserted_total")) + + id)))))) (define-method (datastore-delete-background-job (datastore <sqlite-datastore>) @@ -4564,3 +4585,28 @@ LIMIT :limit" (sqlite-reset statement) result))))) args)) + +(define-method (datastore-count-background-jobs + (datastore <sqlite-datastore>)) + (call-with-thread + (slot-ref datastore 'reader-thread-pool) + (lambda (db) + (let ((statement + (sqlite-prepare + db + " +SELECT type, COUNT(*) +FROM background_jobs_queue +GROUP BY type" + #:cache? #t))) + + (let ((result + (sqlite-map + (match-lambda + (#(type count) + (cons type count))) + statement))) + (sqlite-reset statement) + + result))))) + |