Skip to content

feat(cluster): objectfs cluster status, and the endpoint it reads (#147) - #414

Merged
scttfrdmn merged 4 commits into
mainfrom
feat/147-cluster-status
Aug 9, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
feat/147-cluster-status

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #147.

#147 asked for a client for an endpoint that did not exist, so this is two halves: /health/cluster (internal/health/cluster.go) and objectfs cluster status [--json] [--endpoint] [--config] (cmd/objectfs/cluster.go).

internal/health does not import internal/distributed — a ClusterStatusProvider returning any keeps the seam — while the concrete distributed.ClusterStatus is shared by producer and consumer, so the wire format has one definition. The endpoint is registered through Checker.ClusterPath() rather than a constant, so it follows a customized HTTPPath.

Pre-existing defect found by running it, not by reading it

refreshLocalStats only ever reached gp.localNode — the struct the gossip alive-message is built from — so a node published its cache figures to every peer and never recorded them in its own membership map. Every node showed each peer's cache in full and its own as "not reported", and cluster-wide TotalCacheSize under-reported by one node's worth, on every node.

cluster_test.go:732 had documented the symptom as expected behaviour — "zero here, since nothing refreshed it" — which is exactly why reading the tests would not have surfaced it. Fixed with refreshSelfEntry(), using a -1 sentinel so "no cache injected" stays distinguishable from "an empty cache".

What the issue's mockup asked for and does not appear here

Printing a number nobody assigns is worse than printing nothing, so each of these is absent and says why in the output:

Mockup field Disposition
Role: Leader/Follower Only when enable_consensus is set. A mount leaves consensus off, so IsLeader is false on every node of a healthy cluster. Leadership is a nil pointer, not a zero struct.
per-node cache hit % nil until requests > 0, printing hit=not measured. A 0.0 rate by arithmetic is indistinguishable from a cache that misses every read.
"Top 5 keys by access" Dropped. No per-key access counter is reachable from the cluster layer. recentHoldings orders by last announced — a different quantity, and publishing it under this label would be a proxy read as the real thing. AnnouncedKeys is printed as the count it is.
quorum in the exit code Replaced by dead-or-suspect-nodes. Quorum is a Raft concept; this project coordinates by CAS against S3 and a 2-node cluster with one node down works correctly.
8 ClusterStats fields Dropped — five are assigned nowhere, three only by SetLeader, which only consensus reaches. Also NodeInfo.Version (hardcoded "1.0.0", not the build).

Clustering disabled exits 0: it is the default configuration, so anything else pages on every single-node mount.

Verification

40 new tests. Two claims re-verified by mutation in review rather than taken from the implementation:

  • removing the refreshSelfEntry() call → TestStatusSnapshot_IncludesThisNodesOwnCacheFigures and TestStatusSnapshot_HitRateIsAbsentUntilACacheServesSomething both fail
  • forcing the CacheRequests > 0 guard true → the latter plus TestStatusSnapshot_ClusterHitRateSkipsNodesThatMeasuredNothing fail

go build ./..., gofmt -l ., go vet ./..., golangci-lint run (0 issues), go test -race ./... (no FAIL, panic or race), go test -race -tags=distributed ./internal/distributed/... all clean. Coverage: cmd/objectfs 85.9% (floor 77), internal/distributed 84.3% (67), internal/health 60.1% (48).

"cluster" is added to docs_symbols_test.go's subcommands map and main_test.go's help list — TestSubcommandsMatchTheBinary parses the dispatch switch with go/ast and correctly caught the new arm.

#147 asked for a client for an endpoint that did not exist, so this is two
halves.

Server: internal/health/cluster.go serves /health/cluster, registered through
Checker.ClusterPath() so it follows a customized HTTPPath rather than a
constant. A ClusterStatusProvider returning `any` keeps internal/health from
importing internal/distributed, while the concrete distributed.ClusterStatus
is shared by producer and consumer so the wire format has one definition. The
endpoint answers 200 whenever it can answer at all: the status code reports
the endpoint's health and the payload reports the cluster's, and conflating
them makes a degraded cluster indistinguishable from an unreachable mount.

Client: `objectfs cluster status [--json] [--endpoint] [--config]`.

Fixes a pre-existing defect found by running the command against a live
two-node cluster rather than by reading. refreshLocalStats only ever reached
gp.localNode — the struct the alive message is built from — so a node
published its cache figures to every peer and never recorded them in its own
membership map. Each node showed every peer's cache in full and itself as
"not reported", and TotalCacheSize omitted the local node entirely.
cluster_test.go:732 had documented the symptom as expected behavior ("zero
here, since nothing refreshed it"). refreshSelfEntry() fixes it, using a -1
sentinel so "no cache injected" stays distinct from "an empty cache".

Several fields from the issue's mockup are deliberately absent, because
printing a number nobody assigns is worse than printing nothing:

- Role/leader is omitted unless EnableConsensus is set. A mount leaves
  consensus off, so IsLeader is false on every node of a healthy cluster;
  the report says leader election is not running and that coordination is
  compare-and-swap against S3. Leadership is a nil pointer, not a zero struct.
- "Top 5 keys by access" is dropped: no per-key access counter is reachable
  from the cluster layer. Coordinator.recentHoldings orders by last-announced,
  a different quantity, and publishing it under the mockup's label would be a
  proxy read as the real thing. AnnouncedKeys is printed as the count it is.
- Cache hit rate is a nil pointer until requests > 0, printing "not measured".
  A cache that has served nothing has a 0.0 rate by arithmetic, which is
  indistinguishable from one that misses every read.
- Five ClusterStats counters (MessagesSent/Received, NetworkErrors,
  ReplicationEvents, ConsistencyViolations) are assigned nowhere; three more
  only by SetLeader, which only consensus reaches. NodeInfo.Version was
  hardcoded "1.0.0", not the build.

The exit code is dead-or-suspect-nodes, not quorum. Quorum is a Raft concept,
this project runs CAS against S3, and a two-node cluster with one node down
works correctly. Clustering disabled exits 0 — it is the default config, so
anything else pages on every single-node mount.

40 tests. Two claims were re-verified here by mutation rather than taken from
the implementation: removing the refreshSelfEntry call fails
TestStatusSnapshot_IncludesThisNodesOwnCacheFigures and
TestStatusSnapshot_HitRateIsAbsentUntilACacheServesSomething, and forcing the
hit-rate guard true fails that test plus
TestStatusSnapshot_ClusterHitRateSkipsNodesThatMeasuredNothing.

Adds "cluster" to docs_symbols_test.go's subcommands map and to
main_test.go's help list; TestSubcommandsMatchTheBinary parses the dispatch
switch with go/ast and correctly caught the new arm.
Comment thread internal/distributed/cluster.go Fixed
The gosec job failed on PR #414 with "integer overflow conversion uint64 ->
int64" at the CacheRequests assignment. The code carried a //nolint:gosec,
which golangci-lint honours and the standalone gosec CI job does not — and
adding a second suppression would have been the wrong fix anyway.

Hits and Misses are uint64 while CacheRequests is int64, because every other
field on NodeInfo is signed and a mixed-signedness pair of related fields is
its own bug. Reaching 2^63 operations takes 292 years at a billion per
second, so this is unreachable. It is worth a clamp rather than a suppression
because of what happens if it is ever reached: a negative CacheRequests reads
as "nothing has asked yet" to the `requests > 0` guard that decides whether a
hit rate is reported at all, so the busiest cache in the cluster would report
`hit=not measured`. That is a wrong answer wearing the costume of an honest
absence, which is precisely what this status surface was built to avoid.

The check is on the sum before the cast, not on the result after it: Hits +
Misses is uint64 arithmetic and wraps on its own, so a post-cast check would
be reasoning about a value that had already lost the overflow.

Tested both ways, and the test verified by mutation — replacing the clamp with
the plain conversion gives CacheRequests = -9223372036854775799 for the
above-MaxInt64 case and 1 for the case where the uint64 sum itself wraps. The
first mutation attempt looked like a pass only because removing the clamp left
`math` unused and the package failed to build; a build failure is not a test
result, and the retry kept the import referenced.
@scttfrdmn
scttfrdmn merged commit c47be1b into main Aug 9, 2026
38 checks passed
@scttfrdmn
scttfrdmn deleted the feat/147-cluster-status branch August 9, 2026 18:04
scttfrdmn added a commit that referenced this pull request Aug 14, 2026
…ined (#415) (#435)

A gosec finding did not block a merge, and every part of the mechanism looked
like it did. `Security Scan` runs `gosec -no-fail`, so the job passed on any
number of findings. The check that went red was `gosec` — the code-scanning
check derived from the SARIF upload, a different check with a different name —
and that one reports on pull requests and not on `push: main`, measured across
four commits. So it could not be added to the required contexts either: a
required check that does not always report blocks every PR forever (#413).

The result was that #414 added a `uint64 -> int64` conversion, gosec reported
"1 new alert including 1 error", and the PR stayed mergeable. It was caught by
someone reading the checks by hand.

`-no-fail` stays. The upload needs the complete report, including the three
`sdks/c` G115 findings that the "Fix Gosec SARIF format" step back-fills a path
onto — and which golangci-lint discards for the same cgo reason, so they reach
no other tool. Dropping the flag would end the job before either step ran,
which reads as a tightening and is a loosening.

The gate is instead a final step running .github/scripts/gosec-gate.sh, which
diffs the report against .github/gosec-baseline.txt. `Security Scan` is a job
name, so it reports on every trigger the workflow has, which is what lets it be
required. Last in the job and `if: always()`, so a new conversion does not also
cost the run its govulncheck result, Trivy upload and license check.

The baseline is the twelve pre-existing findings across eight files, keyed by
(rule, file, count). Not by line number, which moves whenever anything above it
moves, so a line-keyed baseline goes stale on unrelated edits and reports on the
wrong thing. A severity threshold was not available: all twelve are G115 at
`error` level, identical to what a new finding reports, so there is nothing to
threshold on. The ratchet is exact in both directions — fixing one of these
fails too, until its line goes with it, because a slot kept after its finding
was fixed is permanent headroom for the next conversion in that file.

Two things are gated in Go, in internal/config/gosec_gate_test.go, because both
failure modes are silent: every path in the baseline must exist (a renamed file
leaves a standing allowance pointing at nothing, and the script would report it
as a fixed finding, which is true said misleadingly), and the workflow must
still invoke the script, still pass `-no-fail`, and the script must still be
executable. All six branches were mutation-verified: each fails with its own
message and the suite returns to green.

The script's own failure path was verified by running it, not by reading it —
and that caught a bug in it. `diff` exits 1 on a difference, `pipefail` promotes
that to the pipeline, and `set -e` ended the script at `diff | tail`, so the
first mutant printed the diff and then none of the three paragraphs explaining
what to do about it. Which is the exact failure #433 had just fixed elsewhere,
sitting directly below a comment describing it.

Refs #415
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.

B2-3: Add objectfs cluster status subcommand

2 participants