swarm-otel: a timer starts the receiver-socket check again while it is failed
swarm-otel-sockets probes once at activation. On a fresh swarm the collector opens its sockets only after authelia answers, which is after the operator unseals the store, so the probe failed and stayed failed after ingest worked: the only red unit on the swarm. swarm-otel-sockets-recheck.timer now starts it again each minute, and only while it is failed (an ExecCondition on systemctl is-failed), with a restart that does not block. The check itself gets no Restart: a oneshot's start job stays pending through an automatic restart, so a switch would wait on it for as long as the collector is down, and the failed check is what the switch reports. full-setup waits for the check to be active after the collector has recovered, and the module-eval case pins the timer, the condition and the absence of a Restart. Closes #6836
This commit is contained in:
parent
870a0a6697
commit
912b2d9570
4 changed files with 72 additions and 2 deletions
|
|
@ -237,7 +237,12 @@ fails if a socket refuses for 30 seconds, or if a route answers `000`, `502` or
|
|||
`504`, or lacks its own `X-Swarm-Otel-Route` response header, for 30 seconds.
|
||||
The gateway sets that header, named after the route, on every response from a
|
||||
route, so a collector that's up but not listening, or an nginx that doesn't
|
||||
have the route, shows as a failed unit. Any status other than those passes,
|
||||
have the route, shows as a failed unit. On a fresh swarm the unit fails at
|
||||
activation, because the collector opens its sockets only once the operator has
|
||||
unsealed the store. A timer, `swarm-otel-sockets-recheck`, starts the unit again
|
||||
every minute while it is failed, so it turns `active` by itself once the
|
||||
collector listens. systemd never restarts the unit on its own: a switch would
|
||||
wait on the pending start for as long as the collector is down. Any status other than those passes,
|
||||
the collector's 4xx included. A switch leaves a window of about 20 seconds in which
|
||||
nginx and the container are out of step: the container stops before nginx
|
||||
restarts and starts about 18 seconds after it. Senders retry through that window.
|
||||
|
|
@ -267,7 +272,7 @@ swarm-otel-sockets` on the host shows whether the receiver sockets are there;
|
|||
`machinectl shell swarm-otel /run/current-system/sw/bin/journalctl -u
|
||||
opentelemetry-collector` shows why the collector didn't start. A collector that
|
||||
keeps retrying never reaches `failed`, so `systemctl --failed` doesn't list it.
|
||||
The signals are `swarm-otel-sockets` failing and the Grafana alert
|
||||
The signals are `swarm-otel-sockets` not `active` and the Grafana alert
|
||||
`no log records from <hive>`, which fires after about 15 minutes without a log
|
||||
record stamped with that hive's `sender`.
|
||||
|
||||
|
|
|
|||
|
|
@ -900,6 +900,33 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
# On a fresh swarm the collector opens its sockets only after authelia
|
||||
# answers, which is after the operator unseals the store, long after the
|
||||
# check's one attempt at activation. The check stays failed, which is what
|
||||
# the switch reports, so it is not given a restart of its own: a oneshot's
|
||||
# start job stays pending through an automatic restart, and the switch
|
||||
# would wait on it for as long as the collector is down. This timer starts
|
||||
# the check again each minute while, and only while, it is failed. The
|
||||
# restart does not block, so a check that fails again leaves nothing
|
||||
# waiting.
|
||||
systemd.services.swarm-otel-sockets-recheck = {
|
||||
description = "start the swarm collector socket check again while it is failed";
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
# Exit 1 (the check is not failed) skips the start and is no failure.
|
||||
ExecCondition = "${pkgs.systemd}/bin/systemctl is-failed --quiet swarm-otel-sockets.service";
|
||||
ExecStart = "${pkgs.systemd}/bin/systemctl restart --no-block swarm-otel-sockets.service";
|
||||
};
|
||||
};
|
||||
systemd.timers.swarm-otel-sockets-recheck = {
|
||||
description = "start the swarm collector socket check again while it is failed";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnActiveSec = "1min";
|
||||
OnUnitActiveSec = "1min";
|
||||
};
|
||||
};
|
||||
|
||||
assertions = [
|
||||
{
|
||||
# Shaped after ./swarm-grafana.nix's `haveClientIdentity` assertion —
|
||||
|
|
|
|||
|
|
@ -1230,6 +1230,31 @@ let
|
|||
&& lib.elem "container@swarm-otel.service" u.partOf
|
||||
&& lib.elem "multi-user.target" u.wantedBy;
|
||||
}
|
||||
{
|
||||
# On a fresh swarm the collector opens its sockets only after the store
|
||||
# is unsealed, long after the check's one attempt at activation. The check
|
||||
# itself is never restarted by systemd: a oneshot's start job stays
|
||||
# pending through an automatic restart, and a switch would wait on it for
|
||||
# as long as the collector is down. A timer starts it again, only while it
|
||||
# is failed (`ExecCondition`) and without blocking. Without the condition
|
||||
# a healthy check would restart every minute; without `timers.target` the
|
||||
# timer would never run.
|
||||
name = "a failed receiver-socket check is started again by a timer, and the check is not restarted by systemd";
|
||||
ok =
|
||||
let
|
||||
host = serviceContainersWithCi;
|
||||
check = host.systemd.services.swarm-otel-sockets;
|
||||
re = host.systemd.services.swarm-otel-sockets-recheck;
|
||||
t = host.systemd.timers.swarm-otel-sockets-recheck;
|
||||
in
|
||||
!(check.serviceConfig ? Restart)
|
||||
&& re.serviceConfig.Type == "oneshot"
|
||||
&& lib.hasInfix "is-failed --quiet swarm-otel-sockets.service" re.serviceConfig.ExecCondition
|
||||
&& lib.hasInfix "restart --no-block swarm-otel-sockets.service" re.serviceConfig.ExecStart
|
||||
&& lib.elem "timers.target" t.wantedBy
|
||||
&& t.timerConfig.OnUnitActiveSec == "1min"
|
||||
&& t.timerConfig ? OnActiveSec;
|
||||
}
|
||||
{
|
||||
# `DynamicUser` forces `ProtectSystem=strict`, which leaves `/run`
|
||||
# read-only unless the path is in `ReadWritePaths`. The controls: the
|
||||
|
|
|
|||
|
|
@ -226,6 +226,19 @@ with subtest("the swarm collector's client secret reaches the host"):
|
|||
"swarm-bao-otel-oidc",
|
||||
)
|
||||
|
||||
with subtest("the receiver-socket check is active once the collector has recovered"):
|
||||
# The collector opens its sockets only after authelia answers, which on a fresh swarm is
|
||||
# after the unseal. `swarm-otel-sockets` runs at activation, long before that, so its first
|
||||
# attempt fails; `swarm-otel-sockets-recheck` has to start it again, or it stays failed (and
|
||||
# the only red unit on the swarm) after ingest works. The timer fires each minute and an
|
||||
# attempt takes up to 30 s, so the wait covers several rounds.
|
||||
settle(
|
||||
'[ "$(systemctl is-active swarm-otel-sockets.service)" = active ]',
|
||||
600,
|
||||
"swarm-otel-sockets",
|
||||
"swarm-otel",
|
||||
)
|
||||
|
||||
with subtest("step 2: swarmctl user add"):
|
||||
machine.wait_until_succeeds(
|
||||
"swarmctl user add mara --display-name Mara --email mara@example.com --group admins "
|
||||
|
|
|
|||
Loading…
Reference in a new issue