Skip to content

metrics_port: 0 does not disable the metrics listener — it defaults back to 8080 #212

Closed

Description

@scttfrdmn

What

Setting global.metrics_port: 0 to turn the metrics endpoint off leaves it listening on 8080.

metrics.NewCollector treats any non-positive port as unset and fills it from the defaults
(internal/metrics/collector.go:94-96):

defaults := DefaultConfig()
if config.Port <= 0 {
    config.Port = defaults.Port      // 8080
}

Verified

RESULT: Port:0 defaulted to 8080 and BOUND it — port 0 does NOT disable
RESULT: Enabled:false bound nothing — this is the disable switch

(Constructed a collector with Enabled: true, Port: 0, called Start, then dialled
127.0.0.1:8080 in a loop for 2s.)

Nothing in Configuration.Validate() rejects port 0, so the config loads clean and the mount logs
metrics server started port=8080 — which an operator who wrote 0 is unlikely to read as
contradicting what they asked for.

Why it matters

0 is the conventional "disabled" value for a port, and this repo already uses it that way one
field over: internal/adapter/adapter.go:207 gates the health listener on
HTTPEnabled: a.config.Global.HealthPort > 0. So health_port: 0 disables and metrics_port: 0
does not, which is worse than either behaviour on its own — the operator has no reason to expect the
two adjacent fields to differ.

The failure direction is the bad one: someone trying to close a network port ends up with it open on
the default. That is the same class as the withdrawn v0.10.0 at_rest: true key — a configuration
value that reads as a security decision and isn't one.

Proposed

Pick one and make both ports agree:

  1. 0 means off for both, matching health_port and the convention. NewCollector's
    defaulting then needs to distinguish "unset" from "explicitly zero" — the honest way is for the
    adapter to gate the call the way it already gates health, rather than for the collector to guess.
  2. 0 is invalid for both, rejected in Validate() naming the field, with enabled: false as
    the only way to disable.

(1) is better: it is what the adjacent field already does, and it is what an operator will try
first.

Either way Validate() should reject a port outside 1–65535 rather than letting it reach a
net.Listen that fails on a goroutine — Collector.Start's listener error is logged from inside a
go func() and nothing propagates it, so a bad port today is a silent no-endpoint.

Also worth a test asserting the two fields behave the same way, since the whole defect is that they
don't.

Related: #211 (both listeners bind all interfaces).

Activity

  1. added
    type: bug
    priority: medium
    area: metrics
    area: config
    effort: xs
    on Aug 2, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed and shipped in the v0.11.0 Unreleased changelog, and fixed by removing the setting rather than by special-casing zero.

    There is no 0 in an address. global.metrics_port and global.health_port are gone, replaced by monitoring.metrics.addr and monitoring.health_checks.addr, and each listener's enabled flag sits directly beside its addr — so turning an endpoint off is enabled: false and only that.

    That is the fix this issue was asking for at its root. A port had two spellings of "off" that disagreed: health_port: 0 disabled its listener, while metrics_port: 0 read as unset, defaulted back to 8080, and bound it — two adjacent fields, and the metrics one failed in the direction that leaves a port open. An address subsumes a port, so keeping both would have preserved the disagreement.

    Validation came with it: net.SplitHostPort accepts "99999", so the port range is checked explicitly and the error names the field. health_port: 99999 used to reach net.Listen straight from YAML.

    Recorded in SECURITY.md under Turning a listener off is enabled: false, and only that, so the old behavior is documented as history rather than forgotten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: configarea: metricseffort: xspriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions