Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/docs/4-implementation/k8s/telemetry.md
atlas dca4720b7b run the log store and its auth responders as pods
swarm-logs-auth and swarm-metrics-auth take --listen for a TCP address beside
--socket. The log store is a Deployment on a static local volume that is its
old container's data directory, behind a ClusterIP Service the gateway dials by
name. Its two auth_request responders are one unpinned pod with a jwt role.
The renderer gains a plain HTTP listener, a probe path, fsGroupChangePolicy,
and one policy for a pod with both a listener and egress.
2026-11-27 21:30:12 +01:00

86 lines
4.6 KiB
Markdown

# 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
through the hive collector that runs on the host
(`opentelemetry-collector`, [Telemetry](../swarm/telemetry.md)), which pushes to
the stores through the gateway, 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 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` and
`swarm-controller` are two. The controller's unit sets
`OTEL_EXPORTER_OTLP_ENDPOINT` to its route of the swarm collector and mints its
own bearer, so its pod keeps that value. The poller reads
`SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm collector,
`https://<swarm.otel.domain>/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. A daemon that pushes no telemetry of its own, the queue's
responder, has `"none"` in its entry and gets no endpoint. The queue's logs are
the pod's, read like any pod's ([logs](#logs)): the container's journal
forwarder has no counterpart in the pod. Its metrics are the exporter's, which
the swarm collector scrapes through the gateway, as it does for the container.
## 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.
A collector that already runs as a dynamic user when you turn the node on keeps
its state, such as the journald cursor. systemd moves the state directory out
of `/var/lib/private` for the static user, and the unit sees the files as its
own, so the receiver resumes from its cursor and ships nothing twice.
## 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-collector-switch`
switches a running collector from a dynamic to the static user and checks that
its cursor survives. 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.