Skip to content

fix(prometheus): keep alerts readable through a flapping link - #117

Merged
hackallcode merged 15 commits into
masterfrom
fix/prometheus-reachability-flapping
Nov 26, 2026
Merged

hackallcode merged 15 commits into
masterfrom
fix/prometheus-reachability-flapping

Conversation

@hackallcode

@hackallcode hackallcode commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

On a link that drops most inbound packets, scrapes, probes and NATS routes fail and pass in turn, and one outage turned into dozens of Telegram messages that were hard to read. This keeps such an outage to a few messages, each showing the whole state.

Flapping. InstanceDown, PrometheusIsolated, ProbeFailed and NatsRouteMissing carry keep_firing_for: 5m: one alert holds until the target has answered for five minutes.

NATS alerts name the host that is behind. The meta and stream leaders reported their peers by NATS server name, which need not match instance_name, and an alert about a lagging peer carried the leader's host. nats-metrics.py now has each server report itself from /healthz?details=true and its stream info: nats_jetstream_current and nats_stream_current{stream}, the latter 0 also for a copy that knows no leader, as a replica cut off from the cluster still counts itself current. NatsJetStreamBehind and NatsStreamBehind replace NatsPeerBehind and NatsStreamReplicaBehind; nats_jetstream_peer_current, nats_stream_replica_current and nats_stream_leader are gone. The nats role is unreleased, so nothing outside it depends on them.

Telegram message. The header carried one duration, the oldest firing alert's, so a message a new alert triggered read as if that alert had been down for minutes. The header now holds the firing severities, their hosts and their count, info alerts left out as events; items run oldest first, firing and resolved together, each with when it fired or resolved, its severity, host and category emoji, and its description below. Alertmanager orders a group's alerts by labels and templates cannot sort, so the template picks the earliest unprinted alert on each pass.

🚨⚠️🌍🍓 • 2 firing

00:09 • ✅🌍🖥️ • 👀🍓
node on host-1 does not answer

00:14 • ⚠️🍓🖥️ • 👀🌍🍓
tailscale on host-2 does not answer

00:17 • 🚨🌍🖥️ • 👀🍓
tailscale on host-1 does not answer

Observers. Two Prometheus servers watching one host sent the same labels, so their copies were one alert whose state the latest update decided: one seeing the host down and the other up flipped it between firing and resolved. With an observer label set through prometheus_alert_relabel_configs the copies stay apart, and an item shows 👀 and the emoji of each observer that sees it. The README suggests group_by: [], so each message carries everything that fires.

Alertmanager reload. Every template change restarted Alertmanager: the upstream role's copy notifies a restart, and so did this role after the instance emojis. A restart drops the alerts Alertmanager holds in memory; they came back from each Prometheus one by one and were notified again with old start times. The templates are now copied before the upstream role, which then finds them current, and a reload keeps the alerts.

On a link that drops most inbound packets, scrapes, probes and NATS routes
fail and pass in turn. Each of InstanceDown, PrometheusIsolated, ProbeFailed
and NatsRouteMissing then fired and resolved every minute or two, so one
outage became dozens of messages. keep_firing_for holds them as one alert
until the target has answered for five minutes.

The NATS leader reported its peers' replicas by their NATS server names,
which need not match the inventory names the other alerts and the
notification template key on, and put the leader's host on an alert about a
lagging peer. Each server now reports its own state from /healthz?details=true
and the stream info: NatsJetStreamBehind and NatsStreamBehind replace
NatsPeerBehind and NatsStreamReplicaBehind and name the host that is behind.
A replica cut off from the cluster still counts itself current, so a stream
copy without a known leader is reported as behind too.
@hackallcode

hackallcode commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner Author

Test plan

  • make test/prometheus-rules: new cases for a flapping target and a flapping route hold one alert and resolve five minutes after the last failure; the isolation case resolves after keep_firing_for.
  • make lint/yaml lint/markdown.
  • nats-metrics.py run by hand against a live cluster member cut off from its peers: nats_jetstream_current 0 and nats_stream_current 0 for its stream copy; on a healthy member both are 1.
  • amtool template render (Alertmanager v0.32.0) on firing, resolved, day-old, info and all-resolved alerts, with copies from two observers merged into one item.
  • CI green, including ansible-lint and the nats / prometheus molecule scenarios.

The header carried one duration, the oldest firing alert's, so a message
that a new alert triggered read as if that alert had been down for minutes,
and nothing showed which line was new. Each line now says when its alert
started and for how long, or when it ended; 🆕 marks an alert fired under a
minute ago, the one a group notification within group_interval is about.
@hackallcode hackallcode changed the title fix(prometheus): stop reachability and NATS alerts from flapping fix(prometheus): keep alerts readable through a flapping link Nov 26, 2026
Times trailing the description in italics read as part of it. A time column at the start, with ▸ on the new alert and a short duration at the end, reads like a log.
Status and category read as one icon pair; the hosts follow.
…own emoji

A message split firing and resolved alerts under headers of the first one's
severity and category, so a group of mixed alerts showed one icon set for all
and a new alert was hard to find. Lines now run oldest first, firing and
resolved together, each with when it fired or resolved and its own severity,
category and host emoji; the header carries the firing severities, their
hosts and their count. Alertmanager hands a group's alerts ordered by labels
and templates cannot sort, so the template picks the earliest unprinted one
on each pass.
…restarting it

Alertmanager keeps alerts in memory only. A restart dropped them; they came
back from each Prometheus one by one, each partial set differed from the
notification log, and the group was notified again with every alert's old
start time. Copying the templates before the upstream role leaves its copy,
and so its restart handler, with nothing to do, and a reload keeps the alerts.
The ✅ already says it; the word repeated it. The README now suggests one group per route, so every message carries the whole state.
…ager is installed

The templates dir can exist before the upstream role has created the
alertmanager user, as it does in the molecule scenario, and the copy then
failed to chown. A dir the alertmanager user owns means the upstream role has
run; on a first install there is nothing to keep from restarting.
…eload in place

The Telegram message format and NatsRouteMissing are unreleased, so their
entries under Changed and Added describe them as they are now rather than as
fixes. Reloading on a template change fixes a restart that 0.5.0 shipped.
… show who sees them

Two Prometheus servers watching one host sent the same labels, so their
copies were one alert whose state the latest update decided: one seeing the
host down and the other up flipped it between firing and resolved. With an
observer label naming each server's host the copies stay apart; an item
stands for all copies of a description and state and shows the observers'
emoji after 👀, its description on a line of its own.
An info alert is an event, such as a failover leader change, not a state that fires and resolves.
Items run oldest first and every message carries the whole state, so the change that sent it is the last item.
FailoverLeaderChanged fired only for a node that had not led in the ten
minutes before, to stay quiet when a leader drops out for a restart or a
fence and comes back. That also hid a real move back, such as a switch
shortly after a failover. A move now is a node leading that did not lead two
minutes before while another node did; a leader that returns after any gap
with no other leader stays quiet.
@hackallcode
hackallcode merged commit d9aefbd into master Nov 26, 2026
54 of 60 checks passed
@hackallcode
hackallcode deleted the fix/prometheus-reachability-flapping branch November 26, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant