Skip to content

feat: measure the node statistics gossip has always carried - #274

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/node-stats
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/node-stats

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

The six resource and cache fields on the local NodeInfo were set at construction
and never written again, so the figures a peer received described a node that had
just started and never done anything.

Four now carry a measurement, taken once per gossip round and travelling with the
alive message that immediately follows: heap in use as a fraction of heap obtained,
and cache size, hit rate, and operation count from sources this package already had.
Once per round rather than on a ticker of its own, because the only consumer is that
message — and ReadMemStats stops the world, so its frequency should be bounded by
something.

This builds on #273: until an incarnation could advance, the receiving side discarded
every stats payload after the first one, so nothing here would have had an observable
effect after startup.

Three of #132's premises did not hold

The scope here is smaller than the issue asked for:

  • No new message type is needed. The alive message already carries the full
    NodeInfo, so the transport was never missing.
  • StrategyLeastLoad does not read these fields. It reads
    LoadBalancerStats.NodeLoad (coordinator.go:913), which is populated.
  • CPUUsage cannot be HeapInuse/HeapSys as proposed — that is the expression
    already assigned to MemoryUsage.

CPUUsage, DiskUsage, and NetworkBandwidth are therefore left at zero, with the
reason on the fields and pinned by a test. Each needs a platform-specific source that
is not in this repository: /proc/stat or host_statistics for CPU, statfs against
a cache directory this package does not know about for disk, and interface counters
sampled over an interval for bandwidth. A field filled with a proxy from an unrelated
quantity is worse than an empty one: an obviously-zero CPUUsage prompts someone to
implement it, while one carrying heap fragmentation looks like a measurement and gets
used as one.

Zero is likewise not written for "no cache injected" — an empty cache is a meaningful
zero, and reporting it for a cache-less node would make that node look like the
emptiest and most attractive one to a size-aware strategy.

Also

calculateClusterStats summed a totalCacheSize and discarded it with _ =. The
value was correct and simply never assigned. It is now a field, summed across alive
nodes only — a dead node's cache is not reachable, so counting it would overstate what
the cluster can serve without going to S3.

Corrects the health-monitoring example in doc.go, which printed a node.Load field
that does not exist and contained an invalid := cluster.GetLeader(), and records
which figures mean anything.

Verification

Five mutations, each caught by a test that names the consequence:

mutation caught by
refreshed stats never applied to the outgoing payload TestPerformGossipRefreshesTheAdvertisedStats
no-cache case zeroes the cache fields TestRefreshLocalStats_LeavesCacheFieldsAloneWithNoCache
CPUUsage proxied from heap figures TestRefreshLocalStats_LeavesUnmeasurableFieldsAtZero
totalCacheSize discarded again TestCalculateClusterStats_SumsCacheSizeAcrossAliveNodes
dead node's cache counted in the cluster total TestCalculateClusterStats_SumsCacheSizeAcrossAliveNodes

Gates: build, vet, gofmt clean; full -race suite green; coverage gate 35 packages at
or above floor with internal/distributed 71.3% → 73.4%; golangci-lint --new-from-merge-base=origin/main 0 issues.

Closes #132

The six resource and cache fields on the local NodeInfo were set at construction
and never written again, so the figures a peer received described a node that had
just started and never done anything.

Four now carry a measurement, taken once per gossip round and travelling with the
alive message that immediately follows: heap in use as a fraction of heap
obtained, and cache size, hit rate, and operation count from sources this package
already had. Once per round rather than on a ticker of its own, because the only
consumer is that message — and ReadMemStats stops the world, so its frequency
should be bounded by something.

Three of #132's premises did not hold, and the scope here is smaller than it
asked for. There is no new message type: the alive message already carries the
full NodeInfo, so the transport was never missing. StrategyLeastLoad does not
read these fields at all — it reads LoadBalancerStats.NodeLoad, which is
populated. And CPUUsage cannot be HeapInuse/HeapSys as proposed, because that is
the expression already assigned to MemoryUsage.

CPUUsage, DiskUsage, and NetworkBandwidth are therefore left at zero, with the
reason on the fields and pinned by a test. Each needs a platform-specific source
that is not in this repository. A field filled with a proxy from an unrelated
quantity is worse than an empty one: an obviously-zero CPUUsage prompts someone
to implement it, while one carrying heap fragmentation looks like a measurement
and gets used as one.

calculateClusterStats summed a totalCacheSize and discarded it with `_ =`. The
value was correct and simply never assigned anywhere. It is now a field, summed
across alive nodes only — a dead node's cache is not reachable, so counting it
would overstate what the cluster can serve without going to S3.

Also corrects the health-monitoring example in doc.go, which printed a node.Load
field that does not exist and contained `:= cluster.GetLeader()`, and records
which figures mean anything.

Five mutations checked, each failing a test that names the consequence.

Closes #132
@scttfrdmn scttfrdmn added type: enhancement New feature or improvement to existing functionality priority: medium Important but not urgent area: distributed Distributed coordination and consensus labels Aug 3, 2026
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 3, 2026 17:06
@scttfrdmn scttfrdmn added type: technical-debt Code refactoring, cleanup, or architecture improvements priority: high Important issue that should be addressed soon labels Aug 3, 2026
@scttfrdmn
scttfrdmn merged commit 75b70b9 into main Aug 3, 2026
29 checks passed
@scttfrdmn
scttfrdmn deleted the feat/node-stats branch September 20, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: distributed Distributed coordination and consensus priority: high Important issue that should be addressed soon priority: medium Important but not urgent type: enhancement New feature or improvement to existing functionality type: technical-debt Code refactoring, cleanup, or architecture improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A1-5: Populate NodeInfo stats via gossip heartbeat

1 participant