From 58f623461ee4db9e95c161b1c35e0c2fb434b086 Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 22 Nov 2026 03:05:43 +0100 Subject: [PATCH] docs: the CI run poller's runtime, cursor volume, own telemetry route and CA ConfigMap --- docs/2-handbook/swarm/services.md | 5 +- docs/4-implementation/k8s/manifests.md | 8 +-- docs/4-implementation/k8s/runtime.md | 59 ++++++++++++++++++----- docs/4-implementation/k8s/telemetry.md | 18 +++++-- docs/4-implementation/swarm/ci-metrics.md | 21 ++++++++ 5 files changed, 90 insertions(+), 21 deletions(-) diff --git a/docs/2-handbook/swarm/services.md b/docs/2-handbook/swarm/services.md index 44e664e76..971b6d11f 100644 --- a/docs/2-handbook/swarm/services.md +++ b/docs/2-handbook/swarm/services.md @@ -214,8 +214,9 @@ and [`builder.md`](../../4-implementation/swarm/builder.md#binary-cache). ### CI metrics The CI run poller, a `swarm-ci-metrics` timer unit on the host that sets -`deploy.ci-metrics.enable`; set it to `false` to opt out. Every five minutes it -pushes the run time and queue wait of each newly finished forge Actions run to +`deploy.ci-metrics.enable`; set it to `false` to opt out. With +`deploy.ci-metrics.runtime = "k8s"` it runs as a CronJob in the host's cluster. Every +five minutes it pushes the run time and queue wait of each newly finished forge Actions run to the metrics store. What it reads and pushes: [`ci-metrics.md`](../../4-implementation/swarm/ci-metrics.md). diff --git a/docs/4-implementation/k8s/manifests.md b/docs/4-implementation/k8s/manifests.md index 094a83838..c4826963f 100644 --- a/docs/4-implementation/k8s/manifests.md +++ b/docs/4-implementation/k8s/manifests.md @@ -37,7 +37,8 @@ The renderer reads the service's evaluated unit, not a copy of its settings: - **Environment:** the unit's `environment`, including what other modules merge into it, minus `PATH`. A systemd `%d` becomes the credential directory it stands for. On a host with a hive collector, the OTLP endpoint - variables point at it ([Pod logs and metrics](telemetry.md)) instead. The + variables of a hive-tier service point at it ([Pod logs and metrics](telemetry.md)) + instead; a swarm-tier producer, `swarm-ci-metrics`, keeps its own. The renderer fails if the unit's `path` holds anything beyond the NixOS default tools, because the image doesn't carry them. The other change is the store login, [below](#the-store-login). @@ -75,8 +76,9 @@ It never names the host path the unit loads a credential from, and never its contents. Nothing here creates the Secret. A credential that holds a public CA file isn't a secret. `swarm-notify-router`'s -`notify-router-bao-server-ca` comes from the ConfigMap `hyperhive-ca-trust`, -key `bao-server-ca.pem`, and its trust bundles from the key `trust-bundle.pem`. +`notify-router-bao-server-ca` and `swarm-ci-metrics`'s `bao-ca.pem` come from +the ConfigMap `hyperhive-ca-trust`, key `bao-server-ca.pem`, and the trust +bundles from the key `trust-bundle.pem`. The manifests only name the ConfigMap, because the hive CA exists only at runtime. [The runtime switch](runtime.md#what-k8s-changes) publishes it from the host's files. A service with both kinds of credential gets one diff --git a/docs/4-implementation/k8s/runtime.md b/docs/4-implementation/k8s/runtime.md index 231857075..7b16c1a6a 100644 --- a/docs/4-implementation/k8s/runtime.md +++ b/docs/4-implementation/k8s/runtime.md @@ -4,9 +4,10 @@ A swarm service with a `runtime` option runs in one of two places: as its host unit, or as a pod in the host's cluster. `services.hyperhive.deploy..runtime` is `"host"` (the default) or `"k8s"`. The service runs once per swarm, so the option moves it and never copies it: the host unit and the pod never run -together, because they would share one queue consumer and one set of buckets. -`swarm-notify-router` and `swarm-stt` have the option today, and the other -services that run in the cluster follow the same pattern. +together, because they would share one queue consumer and one set of buckets, +or two cursors that push every CI run twice. `swarm-notify-router`, `swarm-stt` +and `swarm-ci-metrics` have the option today, and the other services that run +in the cluster follow the same pattern. ## Options @@ -15,6 +16,8 @@ services that run in the cluster follow the same pattern. evaluation fails without it. - `services.hyperhive.deploy.stt.runtime` (default `"host"`), with the same rule. +- `services.hyperhive.deploy.ci-metrics.runtime` (default `"host"`), with the + same rule. With `"host"`, a host without [the cluster node](node.md) renders the same configuration as before the option existed. With the node on and every service @@ -24,7 +27,8 @@ on `"host"`, the cluster holds no service objects. - **The host unit goes.** The configuration has no container for the service (`swarm-notify-router`, `swarm-stt`), no credential hand-ins for it and no - journal forwarder for it. + journal forwarder for it. `swarm-ci-metrics` has no container: its service, + its timer and the CA bundle unit of its service go. - **The service's objects go in.** The [rendered manifests](manifests.md) reach the cluster through `services.k3s.manifests`, one file per service plus the namespace. The cluster applies a file when its link appears in the manifests @@ -32,6 +36,8 @@ on `"host"`, the cluster holds no service objects. - **The pod reads the unit the container ran.** The unit comes from the container's own configuration, evaluated on its own when the host has no container, so the pod's environment is the unit's environment either way. + The poller has no container: the renderer evaluates its service and timer on + their own when the host doesn't run them, and the CronJob follows that timer. - **The host publishes the CA files.** `hyperhive-k8s-ca-trust.service` applies the `hyperhive-ca-trust` ConfigMap from the host's files, with no manual step: - `trust-bundle.pem`: the hive's trust bundle, where the gateway is @@ -56,8 +62,10 @@ cluster can apply the pod. The cluster doesn't delete what a manifest created after the manifest goes away, and it keeps the file's link in its manifests directory. Switching back to `"host"` therefore needs a step of its own. `-k8s-prune.service` belongs -to every configuration that has the node and the service on `"host"`, and the -service's host unit requires it and starts after it: +to every configuration that has the node and the service on `"host"`, and each +of the service's host units requires it and starts after it. The poller has +two, its timer and its service, so a pass started by hand can't run beside a +Job: 1. If the manifest's link exists, rename it to `.yaml.pruning`, so the cluster doesn't apply it again. The rename also records what remains to @@ -89,6 +97,15 @@ after a switch back, as every claim does, and the container's directory stays too. The whisper model isn't state: the pod's image holds it, from the same store path the container reads, and the volume doesn't. +`swarm-ci-metrics` keeps a cursor, `cursor.json`, which holds the run numbers +already pushed. On the host it sits in the service's state directory. In the +cluster it sits in the PersistentVolumeClaim `swarm-ci-metrics-state`, mounted +at the same path, and the claim binds with the first Job. A switch copies +neither, so each side keeps the cursor it last had, and the first pass on a side +with none pushes every run again, as the same points. A second Job on the same +side finds the cursor and pushes nothing. The claim stays after a switch back, +and so does the host's directory. + ## Resources and sandbox The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits @@ -102,16 +119,36 @@ a read-only root filesystem, every capability dropped, the runtime's default seccomp profile and no API token, which is its whole sandbox. Neither side restricts the network. +## Telemetry and credentials of the poller + +The pod of `swarm-ci-metrics` keeps pushing to its route of the swarm +collector, `https:///swarm-ci-metrics`, with the bearer it +mints for itself each pass. The renderer sets no hive collector endpoint for it +([telemetry](telemetry.md#metrics)). The pod holds no client certificate, so it +doesn't push the `bao.client_cert.*` gauges of the host unit. Its one credential +file is the store's CA, `bao-ca.pem`, which comes from the `hyperhive-ca-trust` +ConfigMap. The pod has no Secret volume, and no `swarm-ci-metrics-credentials` +Secret exists, because nothing creates it. + ## Validation `module-eval-k8s` checks that the host render with `"host"` holds the container, no cluster manifests and no CA objects, and that `swarm-stt`'s container and unit are as the module defines them. With `"k8s"` it checks that no container remains, that the manifests sit in `services.k3s.manifests`, and that the -evaluation refuses `"k8s"` without the node. The VM test `k8s-runtime-switch` -runs a router and the speech-to-text service against the real secret store and -a queue. It switches both from the host to the cluster and back, checks each -step for exactly one copy of each, and asserts that the router's pod logs in, -routes an event, and exits 0 when deleted. For `swarm-stt` it asserts that the +evaluation refuses `"k8s"` without the node, and that the poller's pod keeps +the swarm route its unit names, where every other pod gets the hive collector, +and mounts no Secret. The VM test `k8s-runtime-switch` +runs a router, the speech-to-text service and the CI run poller against the +real secret store and a queue. It switches all three from the host to the +cluster and back, checks each step for exactly one copy of each, and asserts +that the router's pod logs in, routes an event, and exits 0 when deleted. For `swarm-stt` it asserts that the pod is Ready, logged in to the store with its ServiceAccount token, carries the unit's limits, requests nothing and is Burstable, and has its cache volume bound. +For `swarm-ci-metrics` it asserts that the host has no timer or service on the +cluster side, and that the cluster has no CronJob, Job or pod on the host side +before the timer starts. A Job completes against a forge stub that lists one +run and pushes it to the poller's own route with a bearer the identity +provider stub minted. The pod holds no Secret and binds its cursor volume, and +a second Job, and a Job after a round trip through the host, push nothing. The +host's own pass against the same stubs is the control. diff --git a/docs/4-implementation/k8s/telemetry.md b/docs/4-implementation/k8s/telemetry.md index bc388b592..530b3be3d 100644 --- a/docs/4-implementation/k8s/telemetry.md +++ b/docs/4-implementation/k8s/telemetry.md @@ -11,15 +11,23 @@ the same service produced as a host unit. A pod pushes OTLP to `http://hive-collector.hive:4318`, the address agents use. The node's CoreDNS answers the name with the hive bridge's address ([The cluster node](node.md)). The [renderer](manifests.md) sets -`OTEL_EXPORTER_OTLP_ENDPOINT` to that address in every pod. For -`swarm-ci-metrics`, whose poller reads `SWARM_CI_METRICS_OTLP_ENDPOINT`, it sets -that variable too. A unit's own endpoint is a loopback forwarder or a gateway -route that needs a token, and a pod has neither. A host without a hive -collector keeps the unit's value. +`OTEL_EXPORTER_OTLP_ENDPOINT` to that address in every pod of a hive-tier +service. A unit's own endpoint is a loopback forwarder or a gateway route that +needs a token, and a pod has neither. A host without a hive collector keeps the +unit's value. The collector stamps the hive's `hive` label on what it forwards, as it does for agents. The pods run on that hive's node. +A swarm-tier producer keeps its own route. `swarm-ci-metrics` is one: its poller +reads `SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm +collector, `https:///swarm-ci-metrics`, and it mints the +bearer that route checks itself on each pass. The renderer sets nothing for such +a service (`otlp = "own"` in its entry of `render.nix`), because a series that +went through the hive collector would carry the `hive` label, and a swarm-level +series must not. The render refuses a service marked `"own"` whose unit names +no endpoint. + ## Logs With `services.hyperhive.deploy.k8s.enable` on a host that runs the hive diff --git a/docs/4-implementation/swarm/ci-metrics.md b/docs/4-implementation/swarm/ci-metrics.md index 6d2f41220..862a5b5df 100644 --- a/docs/4-implementation/swarm/ci-metrics.md +++ b/docs/4-implementation/swarm/ci-metrics.md @@ -25,6 +25,27 @@ the system CAs and the host's `trust-bundle.pem` into `SSL_CERT_FILE` ([CA](ca.md#the-trust-bundle)). Without it, every pass fails with `invalid peer certificate: UnknownIssuer`. +### In the cluster + +With `deploy.ci-metrics.runtime = "k8s"` (and `deploy.k8s.enable`) the host has +neither the service nor the timer, and the poller is a CronJob in the host's +cluster, on the timer's interval. A switch moves the poller, so one runs at any +time ([the runtime switch](../k8s/runtime.md)). The pod differs from the unit in +three places: + +- It pushes to the same route of the swarm collector, with the bearer it mints + each pass, not to the hive collector the other pods push to. A series that + went through the hive collector would carry a `hive` label, and a swarm-level + series must not. +- It logs in to the store with its ServiceAccount token, so it holds no client + certificate and doesn't push the `bao.client_cert.*` gauges the unit pushes. +- Its one credential file is the store's CA, from the `hyperhive-ca-trust` + ConfigMap. + +The cursor is in a volume of the cluster, `swarm-ci-metrics-state`. A switch +copies no cursor, so the first pass on a side that has none pushes every run +again, which changes no panel, as after a crash. + ## What it reads, and as whom | what | where | identity |