Pull the metrics registry out of the controller

This will allow for instrumenting low level database functionality, before
anything starts using the database.
This commit is contained in:
Christopher Baines 2023-01-01 12:27:34 +00:00
parent 7b69611755
commit 926cb2a5e1
2 changed files with 24 additions and 13 deletions

View file

@ -1,6 +1,6 @@
;;; Guix Data Service -- Information about Guix over time
;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2019 Christopher Baines <mail@cbaines.net>
;;; Copyright © 2019, 2020, 2022, 2023 Christopher Baines <mail@cbaines.net>
;;;
;;; This program is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU Affero General Public License
@ -26,6 +26,7 @@
#:use-module (system repl error-handling)
#:use-module (ice-9 atomic)
#:use-module (fibers web server)
#:use-module (prometheus)
#:use-module (guix-data-service web controller)
#:use-module (guix-data-service web util)
#:export (start-guix-data-service-web-server))
@ -39,7 +40,8 @@
#t)
#f))
(define (handler request body controller secret-key-base startup-completed)
(define (handler request body controller secret-key-base startup-completed
render-metrics)
(display
(format #f "~a ~a\n"
(request-method request)
@ -53,16 +55,24 @@
mime-types
body
secret-key-base
(check-startup-completed startup-completed)))))
(check-startup-completed startup-completed)
render-metrics))))
(define* (start-guix-data-service-web-server port host secret-key-base
startup-completed)
(define registry
(make-metrics-registry #:namespace "guixdataservice"))
(define render-metrics
(make-render-metrics registry))
(call-with-error-handling
(lambda ()
(run-server (lambda (request body)
(handler request body controller
secret-key-base
startup-completed))
startup-completed
render-metrics))
#:host host
#:port port))
#:on-error 'backtrace