run the metrics store and its auth responders as pods
This commit is contained in:
parent
3f71739852
commit
07a004fad1
4 changed files with 1308 additions and 1031 deletions
|
|
@ -30,6 +30,8 @@ A service gets manifests on the host whose configuration deploys it:
|
|||
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolume and Claim |
|
||||
| `swarm-victorialogs` | Deployment | Service, NetworkPolicy, PersistentVolume and Claim |
|
||||
| `swarm-logs-auth` | Deployment | ServiceAccount, two Services, NetworkPolicy |
|
||||
| `swarm-victoriametrics` | Deployment | Service, NetworkPolicy, PersistentVolume and Claim |
|
||||
| `swarm-metrics-auth` | Deployment | ServiceAccount, two Services, NetworkPolicy |
|
||||
|
||||
`namespace.yaml` holds the Namespace ([Pod Security](#pod-security)), and
|
||||
`default-deny-ingress/networkpolicy.yaml` its default-deny ingress policy
|
||||
|
|
@ -136,14 +138,15 @@ credential directory.
|
|||
every pod and admits nobody. The cluster's policy engine takes the union of
|
||||
the policies that select a pod and always admits the node's own addresses, so
|
||||
the node reaches a pod, and so does whatever its own policy names. A service with
|
||||
a listener and `egress` (`swarm-logs-auth`) has the one policy: it admits the
|
||||
a listener and `egress` (`swarm-logs-auth`, `swarm-metrics-auth`) has the one policy: it admits the
|
||||
node to the listener and nothing else, and allows the egress above.
|
||||
- **Probes:** a service with an opt-in health listener gets its variable set to
|
||||
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
|
||||
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
|
||||
them, with `SWARM_CONTROLLER_HEALTH_ADDR`. A third-party daemon with no health variable,
|
||||
`victoria-logs`, names a `probe` path instead (`/health`), which both probes
|
||||
request on its listener. The health port takes no credential, because the
|
||||
`victoria-logs` and `victoria-metrics`, names a `probe` path instead (`/health`), which both probes
|
||||
request on its listener. A `startupFailureThreshold` in it (`victoria-metrics`, 60) adds a
|
||||
startup probe on the same path, tried every ten seconds, before the other two begin. The health port takes no credential, because the
|
||||
kubelet's probes carry none and the routes answer a status code with no body.
|
||||
Only the node reaches it, through the namespace's default-deny
|
||||
ingress policy and the pod's own policy, which admit no other pod and no
|
||||
|
|
@ -156,7 +159,7 @@ credential directory.
|
|||
gets an init container and a renewal container that issue its leaf into an
|
||||
`emptyDir` ([runtime](runtime.md#the-controller)). The image of those
|
||||
containers is part of `system.build.k8sImages`. A listener with no `tlsDir`
|
||||
(`swarm-victorialogs`, `swarm-logs-auth`) serves plain HTTP: it gets the
|
||||
(`swarm-victorialogs`, `swarm-logs-auth`, `swarm-victoriametrics`, `swarm-metrics-auth`) serves plain HTTP: it gets the
|
||||
Service and the policy and no leaf, init container or renewal container.
|
||||
- **More than the daemon:** a service whose pod holds more than its daemon
|
||||
(the queue, whose server and exporter run beside the responder) names a
|
||||
|
|
@ -166,10 +169,11 @@ credential directory.
|
|||
daemon's binary, and the credential directory its unit loads from follows
|
||||
the daemon's name. The pod runs under one ServiceAccount, so a queue that
|
||||
holds two store roles has both bound to it
|
||||
([runtime](runtime.md#the-queue)). The responders' pod of the log store holds a second container the same way
|
||||
([runtime](runtime.md#the-log-store)).
|
||||
([runtime](runtime.md#the-queue)). The responders' pods of the log and metrics
|
||||
stores hold a second container the same way
|
||||
([runtime](runtime.md#the-log-store), [runtime](runtime.md#the-metrics-store)).
|
||||
- **A unit of the module's own making:** a service that never ran under systemd on the
|
||||
host (`swarm-victorialogs`, `swarm-logs-auth`) gives the renderer the
|
||||
host (`swarm-victorialogs`, `swarm-logs-auth`, `swarm-victoriametrics`, `swarm-metrics-auth`) gives the renderer the
|
||||
`serviceConfig`, `environment` and `path` of one as a plain attribute set, with
|
||||
the daemon's flags as a list in `ExecStart`. The renderer reads nothing else of
|
||||
a unit. `fsGroupChangePolicy` in the entry sets the pod's field of that name.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
`services.hyperhive.deploy.k8s.enable` makes the host run the main node of a k3s
|
||||
cluster for the swarm services that run in the cluster. It defaults on where the
|
||||
host enables one of them (`deploy.notify-router`, `stt`, `ci-metrics`,
|
||||
`review-classifier`, `claude-login`, `nats` or `swarm-controller`), which
|
||||
`review-classifier`, `claude-login`, `nats`, `swarm-controller`, `victorialogs` or
|
||||
`victoriametrics`), which
|
||||
`services.hyperhive.deploy.singleHostSwarm` and
|
||||
`services.hyperhive.deploy.allSwarmServices` do, so the all-local host gets the
|
||||
cluster with its services in it and no option set. Setting it to `false` on such
|
||||
|
|
@ -70,7 +71,7 @@ says so with a label. The module sets the labels
|
|||
(`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`):
|
||||
|
||||
- `hyperhive.darkest.space/state-<service>=true`, one per service whose data
|
||||
the cluster keeps. Today that's `nats`, `ci-metrics` and `victorialogs`, each when its
|
||||
the cluster keeps. Today that's `nats`, `ci-metrics`, `victorialogs` and `victoriametrics`, each when its
|
||||
`deploy.<service>.enable` is on. The
|
||||
service's static local volume has a `nodeAffinity` on the label, and its pod a
|
||||
`nodeSelector` on it, so a node without the label can't run the pod and shows
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Pod logs and metrics
|
||||
|
||||
The swarm's metric store is a container on the host and its log store is a pod
|
||||
([the log store](runtime.md#the-log-store)). A pod's output reaches both
|
||||
The swarm's log and metrics stores are pods ([the log store](runtime.md#the-log-store),
|
||||
[the metrics store](runtime.md#the-metrics-store)). A pod's output reaches both
|
||||
through the hive collector that runs on the host
|
||||
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), which pushes to
|
||||
the stores through the gateway, so
|
||||
|
|
|
|||
Loading…
Reference in a new issue