Repository navigation
feat: measure the node statistics gossip has always carried - #274
Merged
Merged
Conversation
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
enabled auto-merge (squash)
August 3, 2026 17:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The six resource and cache fields on the local
NodeInfowere set at constructionand 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
ReadMemStatsstops the world, so its frequency should be bounded bysomething.
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:
NodeInfo, so the transport was never missing.StrategyLeastLoaddoes not read these fields. It readsLoadBalancerStats.NodeLoad(coordinator.go:913), which is populated.CPUUsagecannot beHeapInuse/HeapSysas proposed — that is the expressionalready assigned to
MemoryUsage.CPUUsage,DiskUsage, andNetworkBandwidthare therefore left at zero, with thereason on the fields and pinned by a test. Each needs a platform-specific source that
is not in this repository:
/proc/statorhost_statisticsfor CPU,statfsagainsta 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
CPUUsageprompts someone toimplement 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
calculateClusterStatssummed atotalCacheSizeand discarded it with_ =. Thevalue 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 anode.Loadfieldthat does not exist and contained an invalid
:= cluster.GetLeader(), and recordswhich figures mean anything.
Verification
Five mutations, each caught by a test that names the consequence:
TestPerformGossipRefreshesTheAdvertisedStatsTestRefreshLocalStats_LeavesCacheFieldsAloneWithNoCacheCPUUsageproxied from heap figuresTestRefreshLocalStats_LeavesUnmeasurableFieldsAtZerototalCacheSizediscarded againTestCalculateClusterStats_SumsCacheSizeAcrossAliveNodesTestCalculateClusterStats_SumsCacheSizeAcrossAliveNodesGates: build, vet, gofmt clean; full
-racesuite green; coverage gate 35 packages ator above floor with
internal/distributed71.3% → 73.4%;golangci-lint --new-from-merge-base=origin/main0 issues.Closes #132