feat(otel): one path out of the hive, not two
mara: 'there should only be the one via otel-collector'. Collapses
collector.enable away - enabling otel runs the collector, and agents
always export to it.
The argument for it is the same one the collector exists for: as long
as the direct path stays selectable, the credential-in-settings.json
hole stays selectable. An option that can reintroduce a hole is a hole
with extra steps. HYPERHIVE_OTEL_HEADERS_CREDENTIAL is now never
forwarded to containers at all rather than conditionally.
Two consequences, both deliberate:
- the enable option's own promise changes. It said each harness exports
directly so telemetry survives anything host-side being down; that is
now false for every hive rather than for opted-in ones. Stated in the
option text rather than left for a reader to discover.
- the collector-requires-headersCredential assertion is gone. It was
correct only under the shape it was written for: when the collector
was opt-in FOR the credential, opting in without one was pure
indirection. With one path it isn't - an upstream needing no auth
header is legitimate, and the assertion would have rejected it. The
upstream header block is now omitted entirely in that case, rather
than rendering an ${env:...} reference nothing sets.
This commit is contained in:
parent
f7fbad7655
commit
9549cdf9bd
2 changed files with 41 additions and 74 deletions
|
|
@ -16,9 +16,19 @@
|
|||
enable = lib.mkEnableOption ''
|
||||
hive-wide export of every agent's Claude Code stats (token usage,
|
||||
cost, tool calls) to an OTLP endpoint via Claude Code's built-in
|
||||
OpenTelemetry. One switch for all agents; each harness exports
|
||||
directly to the collector, so it keeps working even when hive-c0re
|
||||
is down
|
||||
OpenTelemetry. One switch for all agents.
|
||||
|
||||
Enabling this also runs a collector on the host: there is exactly
|
||||
one way telemetry leaves this hive, and it is through that
|
||||
collector. Agents export unauthenticated to a bridge address only
|
||||
their own containers can reach, and the collector is the only
|
||||
holder of the upstream credential — an agent never sees it.
|
||||
|
||||
⚠️ The collector is therefore in the path of all telemetry. It runs
|
||||
on the same host as the agents and restarts on failure, and
|
||||
telemetry is not the control plane, so degraded telemetry is not
|
||||
degraded operation — but the export no longer survives independently
|
||||
of anything host-side
|
||||
'';
|
||||
|
||||
endpoint = lib.mkOption {
|
||||
|
|
@ -88,31 +98,6 @@
|
|||
'';
|
||||
};
|
||||
|
||||
collector.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Run an OpenTelemetry collector on this host and have agents
|
||||
export to it instead of straight to `endpoint`.
|
||||
|
||||
The point is the credential. Without this, every agent needs
|
||||
`headersCredential` in order to talk to the upstream — and the
|
||||
harness delivers it into the agent's own `settings.json`, where
|
||||
the agent can read it. With a collector the token stops at the
|
||||
host: the collector holds it, agents send unauthenticated to a
|
||||
bridge address only their own containers can reach.
|
||||
|
||||
⚠️ It also makes the collector a dependency in the export path.
|
||||
Today each harness exports directly, so telemetry survives
|
||||
anything host-side being down. That property is traded for the
|
||||
credential reduction; the collector is on the same host as the
|
||||
agents, so the window is small, but it is not zero.
|
||||
|
||||
Off by default, and off means *absent*: no unit, no port, and
|
||||
`endpoint` keeps its current meaning for every agent.
|
||||
'';
|
||||
};
|
||||
|
||||
collector.upstreamHeaderName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "Authorization";
|
||||
|
|
@ -176,7 +161,7 @@
|
|||
];
|
||||
})
|
||||
|
||||
(lib.mkIf (config.services.hyperhive.otel.enable && config.services.hyperhive.otel.collector.enable)
|
||||
(lib.mkIf config.services.hyperhive.otel.enable (
|
||||
(
|
||||
let
|
||||
otel = config.services.hyperhive.otel;
|
||||
|
|
@ -192,31 +177,19 @@
|
|||
upstreamName = if grpcUpstream then "otlp" else "otlphttp";
|
||||
upstream = {
|
||||
endpoint = otel.endpoint;
|
||||
}
|
||||
// lib.optionalAttrs (otel.headersCredential != null) {
|
||||
# The value is interpolated by the collector at runtime from
|
||||
# its environment, never by nix. `EnvironmentFile` below is
|
||||
# what puts it there.
|
||||
# what puts it there. No credential configured means no
|
||||
# header at all — an upstream that needs no auth is a
|
||||
# legitimate deployment, and rendering `${env:…}` for a
|
||||
# variable nothing sets would send the literal.
|
||||
headers.${otel.collector.upstreamHeaderName} = "\${env:${otel.collector.upstreamHeaderName}}";
|
||||
}
|
||||
// lib.optionalAttrs (otel.protocol == "http/json") { encoding = "json"; };
|
||||
in
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
# The collector's whole purpose is to hold the credential so
|
||||
# agents do not have to. With none configured it is pure
|
||||
# indirection, and the operator has almost certainly not got
|
||||
# the deployment they think they have.
|
||||
assertion = otel.headersCredential != null;
|
||||
message = ''
|
||||
services.hyperhive.otel.collector.enable is true but
|
||||
otel.headersCredential is null. The collector exists to be
|
||||
the only holder of the upstream credential; with no
|
||||
credential it just forwards, and every agent's exporter
|
||||
would be unauthenticated end to end.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
# Reachable from agent containers and nowhere else: this opens
|
||||
# the port on the bridge interface only.
|
||||
services.hyperhive.network.exposeHostPorts = [ otel.collector.port ];
|
||||
|
|
@ -244,9 +217,13 @@
|
|||
# systemd's EnvironmentFile format — so the secret reaches the
|
||||
# process as an environment variable without ever being read by
|
||||
# nix, written to the store, or passed in argv.
|
||||
systemd.services.opentelemetry-collector.serviceConfig.EnvironmentFile = otel.headersCredential;
|
||||
systemd.services.opentelemetry-collector.serviceConfig =
|
||||
lib.optionalAttrs (otel.headersCredential != null)
|
||||
{
|
||||
EnvironmentFile = otel.headersCredential;
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
))
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue