Skip to content

otel: ObserveLeader, gauges of a node's grpcproc/leader elections - #70

Merged
floatdrop merged 1 commit into
mainfrom
otel-observe-leader
Oct 12, 2026
Merged

floatdrop merged 1 commit into
mainfrom
otel-observe-leader

Conversation

@floatdrop

Copy link
Copy Markdown
Owner

What

grpcprocotel.Hooks.ObserveLeader(node) registers gauges read at each collection from the node's grpcproc/leader electors, one set per election, by grpcproc.leader.cluster:

Gauge Meaning
grpcproc.leader.electors 1, with grpcproc.leader.role: leader, candidate, follower or unclustered
grpcproc.leader.stalled 1 while the elector is on one message for a second or more, or does not answer within one
grpcproc.leader.term, .view, .quorum what the elector believes
grpcproc.leader.reachable nodes of the view it hears from, itself included
grpcproc.leader.singleton 1 while the singleton runs on this node
grpcproc.leader.checkpoints.waiting Checkpoint calls waiting for a majority

The otel README and the observability guide list PromQL alerts per cluster:

  • no leader, or two leaders;
  • the singleton runs nowhere, or twice;
  • one more lost node would leave this side without a majority;
  • the term keeps changing;
  • checkpoints are waiting;
  • an elector is stalled.

They also say how long a for: each needs.

How

  • Built against v0.13.0. It needs the core only as published. It reads the map each elector publishes through WithInspect, the same way tools/client reads elections.
  • No compile-time check. The inspect keys, the elector's label and the PID's form are not leader's API. TestObserveLeader runs a real election against the core otel requires, so a change to any of them fails it when otel moves to the next core.
  • Bounded collections. The electors are asked all at once, within one second per collection.
  • Stalled electors. One that the snapshot shows on one message for a second (BusyFor), or that doesn't answer within the second, is reported as stalled with no other gauge. A collection that ends sooner reports nothing about it.

Testing

  • In otel: vet, golangci-lint, go test -race, and 100% coverage.
  • The new tests: 25 times each on 1, 2, 4 and 8 CPUs under -race.
  • The ctx check: I removed the check on why the wait ended, and TestObserveLeaderStalled failed as it should.
  • Root: gofmt -l.
  • Site: npm run check, plus a build.

Known gaps

  • One condition has no test: skipping an elector that is in the middle of exiting.
  • The stall limit is fixed at one second. The docs say to give the stalled alert a for: longer than an ElectionTimeout above that.

🤖 Generated with Claude Code

ObserveLeader reads each elector on the node at each collection, from the
map it publishes through WithInspect, and reports one set of gauges per
election by grpcproc.leader.cluster: electors (1, by grpcproc.leader.role),
stalled, term, view, quorum, reachable (the view it hears from, itself
included), singleton (1 while it runs here) and checkpoints.waiting.

- Electors are the processes named leader.ElectorName(cluster) with the
  elector's label; one that publishes no role, or is exiting, is skipped.
- They are asked at once, within one second of the collection. One that
  the snapshot shows on one message for a second (BusyFor), or that does
  not answer within the second, is reported as stalled with no other
  gauge: what it answered before may no longer be what it believes. A
  collection that ends sooner reports nothing of it.
- It builds on leader v0.13.0 as published: the inspect keys, the label
  and the PID's form are leader's, not its API, and TestObserveLeader,
  against a real election, is what notices a change to them.
- Observe and ObserveLeader share one gauge helper.

The otel README and the observability guide list the gauges and PromQL
alerts per cluster (no leader, two leaders, the singleton nowhere or
twice, one node from losing a majority, term churn, waiting checkpoints,
a stalled elector) and what to set their for: to. The operations guide's
"no metric carries the term" now points at grpcproc.leader.term, and the
leader README and guide at ObserveLeader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@floatdrop
floatdrop merged commit 25aa993 into main Oct 12, 2026
11 checks passed
@floatdrop
floatdrop deleted the otel-observe-leader branch October 12, 2026 06:17
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