From 57aedc82aede46ebc252ac0fc59584a9f924397d Mon Sep 17 00:00:00 2001 From: atlas Date: Sat, 12 Sep 2026 14:38:35 +0200 Subject: [PATCH] swarm-otel: say what is measured about _HOSTNAME, not a mechanism that is wrong MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit's comments explained `_HOSTNAME` being `nixos` with "no container sets `networking.hostName`", read off a `git grep` of this tree. That grep answers a question about our source; the default is nixpkgs': `nixos/modules/virtualisation/nixos-containers.nix` sets `networking.hostName = mkDefault name` for every `containers.` guest, which is how every swarm service container here is declared. So the stated cause is wrong, and why the default does not reach these guests is still open. What is measured is narrower: an agent container reports `nixos`, and `_MACHINE_ID` is per-machine by construction. The comments now claim only that, and say the rest is unresolved. The code is unchanged — `_MACHINE_ID` in `_stream_fields` is correct regardless of which explanation turns out to be true. Refs #4304 --- nix/host-modules/swarm-otel.nix | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/nix/host-modules/swarm-otel.nix b/nix/host-modules/swarm-otel.nix index b79258aa..f3294def 100644 --- a/nix/host-modules/swarm-otel.nix +++ b/nix/host-modules/swarm-otel.nix @@ -1107,10 +1107,12 @@ in # "everything except user sessions" is not expressible. # # Attribution is journald's either way — these fields are - # written by it rather than by the logging process. ⚠️ But - # `_MACHINE_ID` is the only one that separates containers: - # none sets `networking.hostName`, so `_HOSTNAME` is the - # NixOS default `nixos` everywhere but the host itself. + # written by it rather than by the logging process. ⚠️ Use + # `_MACHINE_ID` to tell machines apart, not `_HOSTNAME`: an + # agent container reports the NixOS default `nixos`. Whether + # every container does, and why the `networking.hostName` + # nixos-containers sets does not reach them, is unresolved — + # so rely on the field that is per-machine by construction. // lib.optionalAttrs collectLogs { journald = { directory = hostJournalDir; @@ -1158,11 +1160,13 @@ in # literal `missing _msg field` as its message and text search # finds nothing, while ingest keeps answering 200. # `_stream_fields` is one stream per unit per machine. - # `_MACHINE_ID` is what makes that true: `_HOSTNAME` reads - # `nixos` in every container, so naming it alone merges every - # container's stream for a unit name into one — which is how - # two collectors sharing `opentelemetry-collector.service` - # became one series. + # `_MACHINE_ID` is what makes that true — it is per-machine by + # construction, where `_HOSTNAME` is only as distinct as the + # hostnames happen to be, and an agent container's is the + # NixOS default `nixos`. Keying on the hostname alone merges + # the streams of any two machines sharing one, which is what + # the host and containerised `opentelemetry-collector.service` + # would do. "otlphttp/victorialogs" = { logs_endpoint = logsPushUrl + "?_msg_field=MESSAGE&_stream_fields=_HOSTNAME,_MACHINE_ID,_SYSTEMD_UNIT";