4 KiB
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), 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). The renderer 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 is one: its 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.
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.