diff --git a/nix/host-modules/swarm-otel.nix b/nix/host-modules/swarm-otel.nix index 40331543..7460c85e 100644 --- a/nix/host-modules/swarm-otel.nix +++ b/nix/host-modules/swarm-otel.nix @@ -37,14 +37,14 @@ in options.services.hyperhive.swarm.otel = { enable = lib.mkOption { type = lib.types.bool; - default = swarmCfg.enableRequiredServices; - defaultText = lib.literalExpression "services.hyperhive.swarm.enableRequiredServices"; + default = false; description = '' Run the swarm's telemetry collector on this host. - Derived from `swarm.enableRequiredServices` like the swarm's other - shared services: a swarm has one of these, and it belongs wherever - the shared services live rather than on every hive. + Asserted from `swarm.enableRequiredServices` in + ./swarm-required-services.nix, with the metrics pair this + collector feeds: a swarm has one of these, and it belongs + wherever the shared services live rather than on every hive. A hive that does not run it still runs its own hive-tier collector (`services.hyperhive.otel.enable`) and points it here with @@ -54,6 +54,7 @@ in machine = lib.mkOption { type = lib.types.str; + readOnly = true; default = "swarm-otel"; description = '' Name of the nixos-container this collector runs in — also the @@ -162,6 +163,19 @@ in config = { ... }: { + # This tier is the one that resolves an operator-configured + # hostname: `otel.endpoint` is an external URL, and reaching it + # is the entire reason this container holds a credential. The + # `/etc/resolv.conf` nixos-containers copies in is a snapshot + # taken once at boot, so without this the upstream export + # depends on the host's file having been right at that instant. + imports = [ + (import ./swarm-container-resolver.nix { + inherit (config.services.hyperhive.network) bridgeIp; + dnsConsumers = [ "opentelemetry-collector.service" ]; + }) + ]; + system.stateVersion = config.system.stateVersion; networking.firewall.enable = false; # Keep the host-copied /etc/resolv.conf intact — same reasoning diff --git a/nix/host-modules/swarm-required-services.nix b/nix/host-modules/swarm-required-services.nix index 81b2c779..f12d84dd 100644 --- a/nix/host-modules/swarm-required-services.nix +++ b/nix/host-modules/swarm-required-services.nix @@ -70,6 +70,12 @@ in # exactly one still sets it directly, which `mkDefault` allows. victoriametrics.enable = lib.mkDefault swarmCfg.enableRequiredServices; grafana.enable = lib.mkDefault swarmCfg.enableRequiredServices; + + # The collector that feeds the pair above, and the only tier holding + # the upstream credential. Same rule as the rest: once per swarm, + # optional, and a hive that is not the service host is a *client* of + # it (`swarm.otel.url`) rather than a second one. + otel.enable = lib.mkDefault swarmCfg.enableRequiredServices; }; # The collector that feeds the pair above (note: no `swarm.` prefix,