about summary refs log tree commit diff
path: root/guix
diff options
context:
space:
mode:
authorArun Isaac2026-08-30 01:16:04 +0100
committerArun Isaac2026-08-30 01:17:21 +0100
commiteeb5a3694d66992d8eae4c87ecf071df0c4bd4c3 (patch)
treea382f7a6f2e58e3d57a4a97e1c7355524552f262 /guix
parent1da5d61410cd0df2f7b18ed1605c87b53059a7d1 (diff)
downloadguix-forge-main.tar.gz
guix-forge-main.tar.lz
guix-forge-main.zip
anubis: Support Prometheus metrics server. HEAD main
Diffstat (limited to 'guix')
-rw-r--r--guix/forge/anubis.scm29
1 files changed, 26 insertions, 3 deletions
diff --git a/guix/forge/anubis.scm b/guix/forge/anubis.scm
index 6863d40..369daa6 100644
--- a/guix/forge/anubis.scm
+++ b/guix/forge/anubis.scm
@@ -23,6 +23,7 @@
   #:use-module (gnu services)
   #:use-module (gnu services shepherd)
   #:use-module (gnu system file-systems)
+  #:use-module (gnu build linux-container)
   #:use-module (guix build-system gnu)
   #:use-module (guix download)
   #:use-module (guix gexp)
@@ -30,10 +31,12 @@
   #:use-module ((guix licenses) #:prefix license:)
   #:use-module (guix packages)
   #:use-module (guix records)
+  #:use-module (forge socket)
   #:use-module (ice-9 match)
   #:export (anubis-configuration
             anubis-configuration?
             anubis-configuration-package
+            anubis-configuration-metrics-socket
             anubis-service-type
             %anubis-unix-socket))
 
@@ -93,7 +96,9 @@ internet from the endless storm of requests that flood in from AI companies.")
   anubis-configuration make-anubis-configuration
   anubis-configuration?
   (package anubis-configuration-package
-           (default anubis-ai-firewall)))
+           (default anubis-ai-firewall))
+  (metrics-socket anubis-configuration-metrics-socket
+                  (default #f)))
 
 ;; TODO: Do not hard-code.
 (define %anubis-unix-socket
@@ -109,7 +114,7 @@ internet from the endless storm of requests that flood in from AI companies.")
 
 (define anubis-shepherd-service
   (match-lambda
-    (($ <anubis-configuration> package)
+    (($ <anubis-configuration> package metrics-socket)
      (shepherd-service
        (documentation "Run the Anubis AI firewall.")
        (provision '(anubis))
@@ -121,9 +126,27 @@ internet from the endless storm of requests that flood in from AI companies.")
                           #:mappings (list (file-system-mapping
                                              (source (dirname %anubis-unix-socket))
                                              (target source)
-                                             (writable? #t))))
+                                             (writable? #t)))
+                          ;; Run anubis in its own network namespace unless the
+                          ;; metrics server is enabled and we need to expose a
+                          ;; TCP socket to the outside world.
+                          #:namespaces (if metrics-socket
+                                           (delq 'net %namespaces)
+                                           %namespaces))
                        "-bind" #$%anubis-unix-socket
                        "-bind-network" "unix"
+                       #$@(cond
+                           ((not metrics-socket)
+                            (list))
+                           ((forge-ip-socket? metrics-socket)
+                            (list "-metrics-bind"
+                                  (string-append (forge-ip-socket-ip metrics-socket)
+                                                 ":"
+                                                 (number->string (forge-ip-socket-port metrics-socket)))
+                                  "-metrics-bind-network" "tcp"))
+                           (else
+                            (leave (G_ "Invalid metrics socket ~s; only <forge-ip-socket> is supported.~%")
+                                   metrics-socket)))
                        "-target" " ")
                  #:user "nginx"
                  #:group "nginx"