aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/agent-messaging
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-28 18:18:28 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-28 18:21:39 +0100
commit6e8d5b084a9639e78e395c15cc3aba609b03b6d7 (patch)
tree30d79a7a31aa7c88fb91bbc4864c285b1587e456 /guix-build-coordinator/agent-messaging
parentf6716c91bbc363fe7d6785033beb3be3b4302f91 (diff)
downloadbuild-coordinator-6e8d5b084a9639e78e395c15cc3aba609b03b6d7.tar
build-coordinator-6e8d5b084a9639e78e395c15cc3aba609b03b6d7.tar.gz
Rework the way metrics are handled
Start writing a proper Prometheus client, hopefully this code can be extracted at some point.
Diffstat (limited to 'guix-build-coordinator/agent-messaging')
-rw-r--r--guix-build-coordinator/agent-messaging/http.scm83
1 files changed, 79 insertions, 4 deletions
diff --git a/guix-build-coordinator/agent-messaging/http.scm b/guix-build-coordinator/agent-messaging/http.scm
index 6c5bf51..4b569f1 100644
--- a/guix-build-coordinator/agent-messaging/http.scm
+++ b/guix-build-coordinator/agent-messaging/http.scm
@@ -40,6 +40,7 @@
#:use-module (guix serialization)
#:use-module (guix build utils)
#:use-module (guix-build-coordinator utils)
+ #:use-module (guix-build-coordinator metrics)
#:use-module (guix-build-coordinator datastore)
#:use-module (guix-build-coordinator metrics)
#:use-module (guix-build-coordinator coordinator)
@@ -86,6 +87,10 @@ if there was no request body."
(make-worker-thread-channel (const '())
#:parallelism 4))
+ (define update-base-datastore-metrics!
+ (base-datastore-metrics-updater datastore
+ coordinator-metrics-registry))
+
(trigger-build-allocation)
(call-with-error-handling
(lambda ()
@@ -105,7 +110,8 @@ if there was no request body."
datastore
trigger-build-allocation
hook-channel
- chunked-request-channel)))
+ chunked-request-channel
+ update-base-datastore-metrics!)))
#:host host
#:port port))
#:on-error 'backtrace
@@ -146,6 +152,68 @@ port. Also, the port used can be changed by passing the --port option.\n"
(list (build-response #:code 204)
""))
+(define (base-datastore-metrics-updater datastore registry)
+ (define namespace
+ "guixbuildcoordinator")
+
+ (let ((builds-total
+ (make-gauge-metric registry
+ (string-append namespace
+ "_builds_total")))
+ (allocated-builds-total
+ (make-gauge-metric registry
+ (string-append namespace
+ "_allocated_builds_total")
+ #:labels '(agent_id)))
+ (build-results-total
+ (make-gauge-metric registry
+ (string-append namespace
+ "_build_results_total")
+ #:labels '(agent_id result)))
+ (setup-failures-total
+ (make-gauge-metric registry
+ (string-append namespace
+ "_setup_failures_total")
+ #:labels '(agent_id reason)))
+ (build-allocation-plan-total
+ (make-gauge-metric registry
+ (string-append namespace
+ "_build_allocation_plan_total")
+ #:labels '(agent_id))))
+ (lambda ()
+ (metric-set builds-total
+ (datastore-count-builds datastore))
+ (for-each (match-lambda
+ ((agent-id . count)
+ (metric-set allocated-builds-total
+ count
+ #:label-values
+ `((agent_id . ,agent-id)))))
+ (datastore-count-allocated-builds datastore))
+ (for-each (match-lambda
+ (((agent-id result) . count)
+ (metric-set build-results-total
+ count
+ #:label-values
+ `((agent_id . ,agent-id)
+ (result . ,result)))))
+ (datastore-count-build-results datastore))
+ (for-each (match-lambda
+ (((agent-id reason) . count)
+ (metric-set setup-failures-total
+ count
+ #:label-values
+ `((agent_id . ,agent-id)
+ (reason . ,reason)))))
+ (datastore-count-setup-failures datastore))
+ (for-each (match-lambda
+ ((agent-id . count)
+ (metric-set build-allocation-plan-total
+ count
+ #:label-values
+ `((agent_id . ,agent-id)))))
+ (datastore-count-build-allocation-plan-entries datastore)))))
+
(define (controller request
method-and-path-components
body
@@ -153,7 +221,8 @@ port. Also, the port used can be changed by passing the --port option.\n"
datastore
trigger-build-allocation
hook-channel
- chunked-request-channel)
+ chunked-request-channel
+ update-base-datastore-metrics!)
(define (authenticated? uuid request)
(let* ((authorization-base64
(match (assq-ref (request-headers request)
@@ -299,8 +368,14 @@ port. Also, the port used can be changed by passing the --port option.\n"
"access denied"
#:code 403))))
(('GET "metrics")
- (render-text
- (metrics datastore)))
+ (update-base-datastore-metrics!)
+ (list (build-response
+ #:code 200
+ #:headers '((content-type . (text/plain))
+ (vary . (accept))))
+ (lambda (port)
+ (write-metrics coordinator-metrics-registry
+ port))))
(_
(render-json
"not-found"