run the metrics store and its auth responders as pods
This commit is contained in:
parent
3f71739852
commit
07a004fad1
1 changed files with 1308 additions and 1031 deletions
|
|
@ -3,8 +3,9 @@
|
|||
The swarm services that have a pod run in the host's cluster and nowhere else:
|
||||
`swarm-notify-router`, `swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
|
||||
`swarm-claude-login`, `swarm-controller`, the queue with its auth callout
|
||||
(`swarm-nats`) and the log store with its responders (`swarm-victorialogs`,
|
||||
`swarm-logs-auth`). Each runs once per swarm, because two copies would share one
|
||||
(`swarm-nats`), the log store with its responders (`swarm-victorialogs`,
|
||||
`swarm-logs-auth`) and the metrics store with its responders (`swarm-victoriametrics`,
|
||||
`swarm-metrics-auth`). Each runs once per swarm, because two copies would share one
|
||||
queue consumer and one set of buckets, or two cursors that push every CI run
|
||||
twice. A host that enables one gets [the cluster node](node.md) with it: no
|
||||
option moves a service between the host and the cluster, and the host has no
|
||||
|
|
@ -15,7 +16,8 @@ gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host.
|
|||
|
||||
`services.hyperhive.deploy.k8s.enable` defaults on where the host enables any
|
||||
of `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
|
||||
`claude-login`, `nats`, `swarm-controller` or `victorialogs`. `deploy.singleHostSwarm` and
|
||||
`claude-login`, `nats`, `swarm-controller`, `victorialogs` or `victoriametrics`.
|
||||
`deploy.singleHostSwarm` and
|
||||
`deploy.allSwarmServices` enable them, so an all-local host gets the node and
|
||||
every service in the cluster with no further option. A host that sets
|
||||
`deploy.k8s.enable = false` while it enables one fails at evaluation, and the
|
||||
|
|
@ -58,6 +60,9 @@ The data stays where it was:
|
|||
way.
|
||||
- The log store's pod mounts `/var/lib/nixos-containers/swarm-victorialogs/var/lib/victorialogs`,
|
||||
the directory the container's store used ([The log store](#the-log-store)).
|
||||
- The metrics store's pod mounts
|
||||
`/var/lib/nixos-containers/swarm-victoriametrics/var/lib/victoriametrics`, the
|
||||
directory the container's store used ([The metrics store](#the-metrics-store)).
|
||||
- The other services keep nothing a move has to carry.
|
||||
|
||||
The pods log in to the store with their ServiceAccount tokens, so the store's
|
||||
|
|
@ -377,6 +382,83 @@ writes to the store and Grafana that reads it.
|
|||
either pod, and no journal forwarder: the host collector reads the pods'
|
||||
output from the node like any pod's.
|
||||
|
||||
## The metrics store
|
||||
|
||||
`swarm-victoriametrics` is the swarm's metrics store: one VictoriaMetrics, with
|
||||
the two `auth_request` responders of its gateway vhost in a second pod, the
|
||||
shape of [the log store](#the-log-store). The gateway's vhost
|
||||
`metrics.<swarm domain>` stays on the host, and so do the swarm collector that
|
||||
pushes to the store and Grafana that reads it.
|
||||
|
||||
- **The store's pod.** The module defines the daemon's `ExecStart`, with its flags
|
||||
(`-storageDataPath`, `-httpListenAddr`, `-retentionPeriod`) as a list, and its
|
||||
`StateDirectory`, and the renderer reads the pod from those. The image holds
|
||||
the nixpkgs build of `victoria-metrics` and nothing else. The pod serves plain
|
||||
HTTP on port 8428, logs in to nothing and pushes no telemetry: its output is
|
||||
the pod's log, which the host collector reads like any pod's
|
||||
([logs](telemetry.md#logs)), and the collector scrapes the store's own metrics
|
||||
through the gateway. Its Deployment has one replica and the `Recreate`
|
||||
strategy.
|
||||
- **Probes.** The store opens its storage before it serves HTTP, so it answers
|
||||
nothing while a large store opens. The pod's startup probe requests `/health`
|
||||
every ten seconds for up to ten minutes, and the liveness and readiness probes
|
||||
begin once it has succeeded. The kubelet restarts a pod that fails the startup probe,
|
||||
so a store that needs longer than that restarts in a loop. The termination
|
||||
grace period is the renderer's 15 seconds; the store writes its in-memory data to disk when it
|
||||
stops.
|
||||
- **State.** The store's data directory on the host is
|
||||
`/var/lib/nixos-containers/swarm-victoriametrics/var/lib/victoriametrics`: the
|
||||
claim `swarm-victoriametrics-store` binds a static local volume on it, so the
|
||||
history the store holds survives a restart or an upgrade of the pod. Its
|
||||
`nodeAffinity` and the pod's `nodeSelector` both name the node label
|
||||
`hyperhive.darkest.space/state-victoriametrics`
|
||||
([node labels](node.md#node-labels)). The files in the directory belong to a
|
||||
user of its own, which the pod's user isn't: the pod's `fsGroup` is `65532`
|
||||
with the `OnRootMismatch` policy, as for the log store, so the first start gives
|
||||
the pod's group the whole tree and later starts look at the directory alone.
|
||||
The module makes the directory when it's missing and leaves the owner and mode
|
||||
of an existing one alone. The volume is the plain directory: a store that keeps
|
||||
its history under `private/` (the layout of a `DynamicUser` unit) isn't
|
||||
covered. The volume's capacity is nominal, and retention
|
||||
(`deploy.victoriametrics.retentionPeriod`, 5
|
||||
years) bounds the store.
|
||||
- **The gateway's hop.** The store serves TCP and a ClusterIP Service,
|
||||
`swarm-victoriametrics.<namespace>.svc.<cluster domain>`, publishes it. The
|
||||
vhost's locations dial the Service's name through nginx's `resolver` and a
|
||||
variable, as the log store's do, so `gateway.dns.enable` has to be on. An exact
|
||||
location names its path after the variable, so the store receives the path
|
||||
nginx matched and the request's query string, as it did over the socket. The
|
||||
two prefix locations (`/api/v1/label/` and `/vmui/`) name none, so the request's
|
||||
own path reaches the store: a decoded path in a `proxy_pass` could carry a line
|
||||
break into the request line. The collector's push and scrape, Grafana's
|
||||
datasource, the controller's and hive-c0re's URLs and the agents'
|
||||
`swarm-metrics` all use `metrics.<swarm domain>`, which the host serves: none
|
||||
of them changes. The vhost has no location for the store's import and admin
|
||||
routes, so the gateway refuses them.
|
||||
- **The responders' pod.** The agents' check (the `swarm-logs-auth` binary on
|
||||
the metrics surface, which checks an agent's bearer and its `metrics`
|
||||
permission) and Grafana's (`swarm-metrics-auth`, which checks the bearer
|
||||
Grafana's datasource sends) run as two containers of one Deployment,
|
||||
`swarm-metrics-auth`. Both log in as the cert role `swarm-metrics-auth` does, so
|
||||
the pod has one ServiceAccount and one jwt role of that name, and both read the
|
||||
store with the pod's token. They hold no state, so the pod has no node label
|
||||
and runs on any node. Each serves TCP (`--listen`) on 8083 and 8084 behind a
|
||||
Service of its own. The second container names its ports `grafana-api` and
|
||||
`grafana-health`: a Service resolves a named port to the first container of the
|
||||
pod that declares the name, so a shared name would send Grafana's bearer to the
|
||||
agents' responder.
|
||||
- **Who reaches what.** Both pods have a NetworkPolicy that selects them for
|
||||
ingress and allows none, so only the node's own traffic reaches them: the
|
||||
host's nginx, which dials the Services, and the kubelet's probes. The store
|
||||
takes writes, deletes and reads with no credential, so a process on the host
|
||||
can use all three: see [Agent security](../../2-handbook/agents/security.md).
|
||||
The responders' policy also lets the pod reach cluster DNS and the secret
|
||||
store's pod listener (`egress = [ "store" ]`).
|
||||
- **The host's part.** The host keeps the vhost, `gateway.localNames` and the
|
||||
options (`retentionPeriod`, `agentAuthRate`, `agentAuthBurst`,
|
||||
`agentAuthVerdictTtl` and the store identity files). The host collector reads
|
||||
the pods' output from the node like any pod's.
|
||||
|
||||
## Resources and sandbox
|
||||
|
||||
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
|
||||
|
|
|
|||
Loading…
Reference in a new issue