Watch
0
0
Fork
You've already forked hyperhive
0

k8s: pod logs and metrics reach the hive collector

This commit is contained in:
atlas 2026-11-21 14:01:39 +01:00 • committed by maia
commit 4ec7513b1b
2 changed files with 447 additions and 51 deletions

View file

@ -35,9 +35,10 @@ 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. The renderer fails if the unit's `path` holds
anything beyond the NixOS default tools, because the image doesn't carry
them.
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
renderer fails if the unit's `path` holds anything beyond the NixOS default
tools, because the image doesn't carry them.
- **Files:** the pod mounts each file the unit names at the same path,
so the environment carries over unchanged:
- credentials at `/run/credentials/<service>.service/<id>`, from the Secret
@ -98,11 +99,8 @@ object.
## Not covered yet
- The pods reach the swarm's host-run services (store, queue, identity
provider) by the same names as the units do. Those names don't resolve to
the host from inside a cluster yet.
- `OTEL_EXPORTER_OTLP_ENDPOINT` keeps the unit's value. For
`swarm-notify-router` that's its container's local log and metrics
forwarder, which a pod doesn't have.
provider) by the same names as the units do. The node's CoreDNS answers those
names with the hive bridge's address.
- `swarm-controller`'s socket lives in an `emptyDir`, so only the pod can
reach it.

View file

@ -0,0 +1,62 @@
# Pod logs and metrics
The swarm's log and metric stores stay where they are. A pod's output reaches
them through the hive collector that runs on the host
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), so
`swarm-logs query` and `swarm-metrics` show a pod's records next to the ones
the same service produced as a host unit.
## Metrics
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.
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.
## Logs
With `services.hyperhive.deploy.k8s.enable` on a host that runs the hive
collector, the collector gains a `file_log/pods` receiver on
`/var/log/pods/*/*/*.log`, where the container runtime writes each container's
output. One node means one reader, with no per-node agent. The receiver:
- reads the CRI framing, and takes the namespace, pod, uid and container name
from the file's path into resource attributes (`k8s.*`);
- reads the level of hive-log's text format, a timestamp then the level
(`WARN`, `INFO`), into the record's severity. A line in another shape
keeps no severity;
- keeps its read offsets in the collector's `file_storage`, so a restart resumes
where it stopped.
`service.name` is the container's name without `swarm-`: `controller`,
`notify-router`, `ci-metrics`. That matches what the swarm's container services
stamp on their journal records. The host units of `swarm-controller` and
`swarm-ci-metrics` carry no `service.name` on their journal records, so a pod's
output is the first to carry one for them.
## Access to the files
The container runtime writes a log file as root with mode 0640, and the
nixpkgs collector unit runs as a dynamic user. With the node on, the collector
runs as the static user `opentelemetry-collector`, and `systemd-tmpfiles` puts
an ACL on `/var/log/pods`: read and traverse for that user on the directory and
on everything under it, with a default entry so the directories kubelet creates
later inherit it. The rule also creates the directory, mode 0755 as kubelet
creates it. The user reads nothing else the file mode doesn't already let
every user read. With the node off, the unit and the collector's configuration
are the ones it has without the module.
## Validation
`module-eval-k8s` checks the configuration with the option on and off, the
rendered endpoints, and the ACL's path. The VM test `k8s-node` runs a pod that
writes a `WARN` and an `INFO` line, and checks that the collector's user reads
the pod's log file, that the lines arrive with those severities under the
container's name, and that a metric a pod pushes arrives.