Watch
0
0
Fork
You've already forked hyperhive
0

run the metrics store and its auth responders as pods

This commit is contained in:
atlas 2026-11-27 09:11:27 +01:00 • committed by maia
commit 07a004fad1
13 changed files with 1308 additions and 1031 deletions

View file

@ -66,7 +66,6 @@
./glue-secret-publisher-bao-identity.nix
./glue-swarm-bao-otel-oidc-client.nix
./glue-swarm-otel-oidc-client.nix
./glue-victoriametrics-otel-oidc-client.nix
./swarm-archive.nix
./swarm-attic-options.nix
./swarm-attic.nix

View file

@ -112,9 +112,8 @@ in
binds no host port. Remove this definition.
'')
(lib.mkRemovedOptionModule [ "services" "hyperhive" "swarm" "victoriametrics" "port" ] ''
VictoriaMetrics listens on a unix socket in a network namespace of its
own, and the gateway reaches it there, so it binds no host port. Remove
this definition.
VictoriaMetrics runs as a pod behind a Service the gateway dials, so it
binds no host port. Remove this definition.
'')
(lib.mkRemovedOptionModule [ "services" "hyperhive" "swarm" "otel" "port" ] ''
The swarm collector's OTLP receivers listen on unix sockets in a network

View file

@ -7,7 +7,7 @@
#
# Gated on authelia being HERE, not on this host running the cache: a client is
# a row in THIS host's provider config, the split
# ./glue-victoriametrics-otel-oidc-client.nix makes for the same reason.
# ./glue-grafana-otel-oidc-client.nix makes for the same reason.
{
lib,
config,

View file

@ -1,37 +0,0 @@
# Glue: register the metrics store container's journal forwarder as an OIDC
# client wherever authelia runs.
#
# ONE PAIRING PER FILE: that forwarder ← authelia, and nothing else.
# Without it authelia mints no secret, the publisher has nothing to copy into
# the store, and the forwarder's export is a 401.
#
# Gated on authelia being HERE, not on this host running the metrics store: a
# client is a row in THIS host's provider config, the split
# ./glue-swarm-bao-otel-oidc-client.nix makes for the same reason.
{
lib,
config,
...
}:
let
hyperhiveCfg = config.services.hyperhive;
clientId = hyperhiveCfg.swarm.victoriametrics.otel.clientId;
in
{
config = lib.mkIf hyperhiveCfg.deploy.authelia.enable {
services.hyperhive.swarm.authelia.oidc.clients = [
{
id = clientId;
description = "HyperHive metrics store journal forwarder";
kind = "machine";
redirectUris = [ ];
# Its own id as its own permitted audience, the one the swarm
# collector's receiver for this container checks.
audience = [ clientId ];
# The receiver verifies the token offline against `/jwks.json`;
# authelia's default opaque handle fails there.
accessTokenSignedResponseAlg = "RS256";
}
];
};
}

View file

@ -130,13 +130,19 @@ let
"nats"
"swarm-controller"
"victorialogs"
"victoriametrics"
];
enabledServices = lib.filter (name: deployCfg.${name}.enable) swarmServices;
# The services whose data the module keeps in the cluster. Each puts its state
# label on this node.
stateful = lib.filterAttrs (_: svc: svc.enable) {
inherit (deployCfg) nats ci-metrics victorialogs;
inherit (deployCfg)
nats
ci-metrics
victorialogs
victoriametrics
;
};
in
{
@ -265,7 +271,7 @@ in
none of those pods.
- `hyperhive.darkest.space/state-<service>` for each service whose data the
cluster keeps: `nats`, `ci-metrics` and `victorialogs`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
cluster keeps: `nats`, `ci-metrics`, `victorialogs` and `victoriametrics`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
- `hyperhive.darkest.space/entry`: the node the hosts' DNS points at.
- `svccontroller.k3s.cattle.io/enablelb`: with it on any node, the
service load balancer binds a published port on the labelled nodes

View file

@ -135,7 +135,8 @@ let
# service has one, is the TCP port a Service publishes and the directory the
# pod's init container writes the leaf to; without a `tlsDir` it is plain HTTP
# and no leaf is issued. `probe` is the path a service without a `healthEnv` is
# probed on, and `fsGroupChangePolicy` the pod's setting of that name.
# probed on (with `startupFailureThreshold`, a startup probe of that many
# ten-second tries first), and `fsGroupChangePolicy` the pod's setting of that name.
# `ephemeralState` gives a service an `emptyDir` in place of a claim for its
# state directory: what it keeps there is re-derived at start. A pod starts on
# whatever volume it gets.
@ -295,6 +296,49 @@ let
egress = [ "store" ];
otlp = "none";
};
# The metrics store: the VictoriaMetrics daemon alone, on a static local
# volume on the store's data directory. It holds no store
# identity and pushes no telemetry; its own `/metrics` is scraped through
# the gateway. It opens its storage before it serves HTTP, so the pod has a
# startup probe that outlasts a large store's open.
swarm-victoriametrics = {
inherit (deployCfg.victoriametrics) enable package unit;
daemon = "victoria-metrics";
kind = "Deployment";
healthEnv = null;
probe = {
path = "/health";
startupFailureThreshold = 60;
};
etcFiles = [ ];
publicCredentials = { };
listener.port = deployCfg.victoriametrics.servicePort;
localState = {
service = "victoriametrics";
hostDir = deployCfg.victoriametrics.hostDataDir;
};
fsGroupChangePolicy = "OnRootMismatch";
otlp = "none";
};
# The two `auth_request` responders of the metrics store's gateway vhost,
# which log in to the secret store under one role. They keep no state, so
# they run on any node. The Grafana responder is the second container of the
# pod, in `pod`; the first is the `swarm-logs-auth` binary on the metrics
# surface.
swarm-metrics-auth = {
inherit (deployCfg.victoriametrics) enable;
package = deployCfg.victoriametrics.agentAuthPackage;
daemon = "swarm-logs-auth";
unit = deployCfg.victoriametrics.authUnit;
inherit (deployCfg.victoriametrics) pod;
kind = "Deployment";
healthEnv = "SWARM_LOGS_AUTH_HEALTH_ADDR";
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
listener.port = deployCfg.victoriametrics.authServicePort;
egress = [ "store" ];
otlp = "none";
};
};
# Where a pod pushes telemetry. A `"hive"` service pushes to the hive
@ -902,6 +946,17 @@ let
periodSeconds = 10;
};
}
# The liveness and readiness probes wait for this one to succeed once.
// lib.optionalAttrs (svc.probe.startupFailureThreshold or null != null) {
startupProbe = {
httpGet = {
inherit (svc.probe) path;
port = "api";
};
periodSeconds = 10;
failureThreshold = svc.probe.startupFailureThreshold;
};
}
// lib.optionalAttrs (svc.healthEnv != null) {
livenessProbe = {
httpGet = {

View file

@ -175,11 +175,11 @@ let
}
];
# The metrics store's responders under one leaf: the agent one checks the
# secret an agent presents against the one stored for it (the same `+` leaf
# as the log store's) and reads the agent's mirrored grant, the other checks the bearer Grafana presents; and the
# host unit that fetches the store container's journal forwarder secret.
# Nothing else.
# The metrics store's auth responders, which run in one pod under one role:
# the agent one checks the secret an agent presents against the one stored for
# it (the same `+` leaf as the log store's) and reads the agent's mirrored
# grant, the other checks the bearer Grafana presents against Grafana's
# metrics bearer. Nothing else.
metricsAuthReaders = [
{
name = "swarm-metrics-auth";
@ -188,9 +188,7 @@ let
policyText =
readStanza "${credentialMountPath}/data/swarm/agents/+/queue"
+ readStanza "${credentialMountPath}/data/swarm/agents/+/observability"
+ readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}"
# The metrics store container's journal forwarder, fetched on its host.
+ readStanza "${credentialMountPath}/data/swarm/services/${hyperhiveCfg.swarm.victoriametrics.otel.clientId}/oidc/client";
+ readStanza "${credentialMountPath}/data/${grafanaMetricsBearerLeaf}";
}
];
@ -419,6 +417,9 @@ let
# The log store's two responders hold one role, under the ServiceAccount of
# their pod (./k8s/render.nix, `swarm-logs-auth`).
++ logsAuthReaders
# The metrics store's two responders, likewise under the ServiceAccount of
# their pod (./k8s/render.nix, `swarm-metrics-auth`).
++ metricsAuthReaders
++ [ { name = controllerPolicyName; } ]
# The queue's pod holds both of its roles under one ServiceAccount: the
# server's leaf is issued with `swarm-nats`, and the responder reads its

View file

@ -1671,10 +1671,7 @@ in
identity the metrics store's auth responders present to read agent
queue credentials, `swarm/agents/<agent>/queue`, and the bearer
Grafana's datasource sends,
`swarm/services/<grafana client id>/metrics/bearer`, and the one
`swarm-victoriametrics-forwarder-oidc` presents to read
`swarm/services/<metrics store forwarder client id>/oidc/client`.
Nothing else.
`swarm/services/<grafana client id>/metrics/bearer`. Nothing else.
⚠️ Reserved as a hive name by ./swarm.nix, like its siblings.
'';

View file

@ -261,11 +261,6 @@ in
hive-matrix = {
clientId = hyperhiveCfg.swarm.matrix.otel.clientId;
};
# The forwarder in ./swarm-victoriametrics.nix, which reaches this route
# through its host's nginx.
swarm-victoriametrics = {
clientId = hyperhiveCfg.swarm.victoriametrics.otel.clientId;
};
# The CI run poller in ./swarm-ci-metrics.nix, a host unit that pushes
# its run samples here directly.
swarm-ci-metrics = {

View file

@ -250,8 +250,7 @@ let
# Every container with a `serviceProducers` entry (`swarm-bao`, `swarm-nats`,
# `swarm-builder`, `swarm-claude-login`, `swarm-notify-router`,
# `swarm-review-classifier`, `swarm-ci-runner`, `swarm-grafana`,
# `hive-forge`, `hive-matrix`, `swarm-victoriametrics`, `swarm-authelia`,
# `swarm-attic`) forwards its own
# `hive-forge`, `hive-matrix`, `swarm-authelia`, `swarm-attic`) forwards its own
# journal from its own collector, so this receiver never sees their units.
hostJournalDir = "/var/log/journal";
hostJournalMount = "/run/host-journal";

View file

@ -63,8 +63,6 @@ let
hyperhiveCfg.swarm.grafana.otel.clientId
hyperhiveCfg.swarm.forge.otel.clientId
hyperhiveCfg.swarm.matrix.otel.clientId
# The metrics store container's journal forwarder, whose host reads it.
hyperhiveCfg.swarm.victoriametrics.otel.clientId
# The CI run poller, which reads it itself on its host.
hyperhiveCfg.swarm.ci-metrics.clientId
# Authelia's container's journal forwarder, which reads it back under the

View file

@ -1,6 +1,6 @@
# The swarm's metrics store as every hive sees it: the name it answers on,
# identical on every host. What the host running it decides, and the
# container itself, are in ./swarm-victoriametrics.nix.
# identical on every host. What the host running it decides, and its
# pods, are in ./swarm-victoriametrics.nix.
{
lib,
config,
@ -20,32 +20,6 @@ in
# `enable`, `package` and `retentionPeriod` are decisions of the
# host that runs it and live under `deploy.*`.
options.services.hyperhive.swarm.victoriametrics = {
machine = lib.mkOption {
type = lib.types.str;
readOnly = true;
default = "swarm-victoriametrics";
description = ''
Container name. Read-only: the name appears in host paths and in
`machinectl`, so it is a fact other modules may read rather than a
knob.
'';
};
otel.clientId = lib.mkOption {
type = lib.types.str;
readOnly = true;
default = "swarm-victoriametrics-collector";
description = ''
OAuth2 client id the journal forwarder inside the metrics store's
container authenticates as, and the audience it asks its token for.
Read-only because three hosts have to agree on it: authelia
registers the client (`glue-victoriametrics-otel-oidc-client.nix`),
the swarm collector admits it on the container's receiver
(`swarm.otel.serviceProducers`), and authelia's mint stores
its secret in the store.
'';
};
domain = lib.mkOption {
type = lib.types.str;

File diff suppressed because it is too large Load diff