Skip to content

fix: one address per listener, beside the flag that enables it - #246

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/202-listener-addresses
Aug 3, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/202-listener-addresses

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #202, #211, #212, and #192's validation half.

These are one code path, not four issues. The listener endpoints bound a hardcoded wildcard, and the settings that would have changed them were inert.

Why a port could not be fixed in place

A port cannot name an interface. fmt.Sprintf(":%d", port) was the only bind it could produce, so every value of monitoring.metrics_port published an unauthenticated endpoint on every interface (#211).

A port also cannot say "off" without overloading zero, and the two blocks overloaded it in opposite directions: health_port: 0 disabled its listener, while metrics_port: 0 was treated as unset, defaulted back to 8080, and bound it (#212). Two adjacent fields spelled "off" differently, and the metrics one failed in the direction that leaves a port open.

Meanwhile monitoring declared metrics_addr and health_check_addr, defaulted them, documented them — and read neither (#202). So an operator who set health_check_addr: 127.0.0.1:8081 to keep a diagnostic endpoint off the network got a wildcard bind and no warning: the live setting could not express a host, and the expressive setting was dead.

An address subsumes a port, so keeping both would preserve the disagreement.

What changed

Removed: global.metrics_port, global.health_port, global.profile_port, monitoring.metrics_addr, monitoring.health_check_addr, monitoring.enable_pprof.

Added: monitoring.metrics.addr and monitoring.health_checks.addr — each inside the block whose enabled flag governs it, both defaulting to loopback (127.0.0.1:8080, 127.0.0.1:8081). Same ports, so an existing same-host Prometheus scrape survives the upgrade; the host is what changed. Both endpoints are on by default and neither is authenticated: between them they report per-operation counts, error rates, sizes and timings, and /health reports component names and error strings.

Removed rather than deprecated, because strict decoding then names the key and line to edit. A key kept as an ignored field means an operator's listener settings silently stop applying on upgrade.

enable_pprof/profile_port are removed rather than wired. Nothing read either. The one pprof server in the tree is pkg/profiling's, which has no importer, also binds every interface, and serves mutating /memory/gc and /memory/free with no authentication — binding a third unauthenticated listener inside the change that stops binding two of them was the wrong trade on the strength of a boolean nothing read. Filed as #245.

Bind errors propagate. Both servers bound on a goroutine and logged. That deliberately contradicts #192's reasoning that non-fatal was "the right call for observability": enabled: false is already how you ask for no endpoint, and an operator who asked for one and did not get it finds out when a liveness probe starts failing.

Validation catches what a listener reports badly. net.SplitHostPort accepts "99999", so the 1–65535 range is checked explicitly and the error names the field. health_port: 99999 used to reach net.Listen from YAML unchecked. Names like localhost are allowed — the shape is checked, not the resolution.

OBJECTFS_METRICS_ENABLED is now wired, along with a new OBJECTFS_HEALTH_ENABLED. The former was documented in cmd/objectfs/doc.go and OBJECTFS.md and assigned nothing — #202's shape in the setting that closes an endpoint rather than the one that moves it. Both parse strictly and fail startup naming the variable, where the feature-flag variables coerce anything but "true" to false: these govern unauthenticated endpoints that default to on, so silent coercion is wrong whichever direction it picks.

The test gap

The more interesting half. TestStartMetricsBindsTheEndpoint scraped 127.0.0.1 and passed against a wildcard bind — because a wildcard bind answers on loopback too. The tests asserted that something was listening, never that it was listening where the configuration said.

Collector.Addr() now reports the bound address, and three new regression tests (metrics, health, adapter) assert two things:

  1. the bound address equals the configured one — a wildcard bind reports 0.0.0.0 or [::] here;
  2. the endpoint does not answer on a routable non-loopback IPv4 address of the host.

Verified by mutation. Restoring the ":"+port bind fails both halves (bound [::]:61260, configured 127.0.0.1:61260, and /metrics answered on 192.168.6.94) while the old-shaped TestScrapeServesTheDocumentedPath stays green — demonstrating the gap the issue describes. Deleting the SDK's cfg.Monitoring.Metrics.Addr = c.opts.metricsAddr mapping fails the new SDK tests, including the guard that refuses a fixture equal to the field's default.

Gates

  • go build ./..., go vet ./... (and -tags=e2e) clean
  • go test -race ./... — 33 packages, all green
  • golangci-lint run --new-from-merge-base=origin/main — 0 issues
  • scripts/coverage-gate.sh — every floor met; internal/config 87.7% → 90.4%, validateListenAddr to 100%

Doc and config surfaces repointed together, so strict decoding does not reject a file this repo ships or documents: examples/config.yaml, configs/example.yaml, SECURITY.md, OBJECTFS.md, cmd/objectfs/doc.go, internal/config/doc.go, internal/metrics/doc.go, docs-platform/guide/getting-started.md, all three SDKs, and tests/{unit,integration,e2e}_test.go.

Closes #202, #211, #212, and #192's validation half. They are one code path: the
endpoints bound a hardcoded wildcard, and the settings that would have changed
them were inert.

A port cannot express what these settings need. It cannot name an interface — so
`fmt.Sprintf(":%d", port)` was the only bind possible, and every value of
`metrics_port` published an unauthenticated endpoint on every interface (#211) —
and it cannot say "off" without overloading zero, which the two blocks did
differently: `health_port: 0` disabled its listener while `metrics_port: 0` read
as unset, defaulted back to 8080, and bound it (#212).

`monitoring` already declared `metrics_addr` and `health_check_addr`, defaulted
them, documented them, and read neither (#202). So an operator who set
`health_check_addr: 127.0.0.1:8081` got a wildcard bind and no warning: the live
setting could not express a host and the expressive setting was dead.

An address subsumes a port, so keeping both would preserve the disagreement.
Removed: `global.metrics_port`, `global.health_port`, `global.profile_port`,
`monitoring.metrics_addr`, `monitoring.health_check_addr`,
`monitoring.enable_pprof`. Added: `monitoring.metrics.addr` and
`monitoring.health_checks.addr`, each inside the block whose `enabled` flag
governs it, both defaulting to loopback. Same ports, so a same-host scrape
survives the upgrade; the host is what changed.

`enable_pprof`/`profile_port` are removed rather than wired. Nothing read either,
and `pkg/profiling` — the only pprof server here — has no importer, binds every
interface too, and serves mutating /memory/gc and /memory/free with no auth.
Filed as #245.

Bind errors now propagate. Both servers used to bind on a goroutine and log,
which contradicts #192's claim that non-fatal was right for observability:
`enabled: false` is already how you ask for no endpoint, and an operator who
asked for one and did not get it finds out when a probe fails.

`OBJECTFS_METRICS_ENABLED` was documented in two places and assigned nothing —
#202's shape in the setting that closes an endpoint rather than the one that
moves it. Now wired, with a new `OBJECTFS_HEALTH_ENABLED`. Both parse strictly:
these govern unauthenticated endpoints that default to on, so coercing a typo is
wrong whichever direction it picks.

The test gap is the more interesting half. `TestStartMetricsBindsTheEndpoint`
scraped 127.0.0.1 and passed against a wildcard bind, because a wildcard answers
on loopback too — the tests asserted that something was listening, never that it
was listening where configured. `Collector.Addr()` now reports the bound address,
and the regression tests assert both that it equals what was configured and that
the endpoint does *not* answer on a routable non-loopback address of the host.
Verified by mutation: restoring the `":"+port` bind fails both halves while the
old-shaped test stays green.

internal/config 87.7% → 90.4%; validateListenAddr to 100%.
#192's third gap, which the address work did not close. `grep -rn health_port docs/ README.md
configs/ examples/` returned nothing: the knob existed, was read, changed behavior, and was named
in no shipped documentation. That is still true of the addresses that replaced it — they are in the
two example config files and in package docs, neither of which is where someone looks to find out
what a mount publishes.

README gains a *Metrics and health endpoints* section: both addresses, the `curl` that reaches each,
the four environment overrides, `enabled: false` as the only spelling of off, why port 0 is rejected
rather than read as off, and that a Prometheus scrape of localhost:8080 needs no change on upgrade.
Its YAML block is checked against the live schema by TestDocumentedConfigYAMLMatchesTheSchema, so it
cannot drift into describing keys the loader does not have.

docs/index.md listed "Health monitoring: health endpoint and internal checks" with nowhere to point
a probe. It now names the address each endpoint is on and links the README section and SECURITY.md.

Also corrects validateListenAddr's own doc comment, which described the pre-fix behavior in the
present tense — "both servers bind on a goroutine and log the error" stopped being true in the same
change that added the validation. What the check actually buys now is where the failure is reported:
net.Listen can only say "invalid port", naming neither the setting nor the file, and it says it after
the backend is constructed. The non-numeric-port error message carried the same stale claim.

Refs #192
@scttfrdmn
scttfrdmn merged commit e2882a6 into main Aug 3, 2026
23 checks passed
@scttfrdmn
scttfrdmn deleted the fix/202-listener-addresses branch August 3, 2026 08:59
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.

config: four monitoring fields are declared, defaulted, and read by nothing — including the two that would fix #192

1 participant