Repository navigation
fix(mecak8s): make Prometheus listener test deterministic - #2620
Merged
Merged
Conversation
Bind the metrics listener on an OS-selected port and observe its actual address through a per-invocation serve hook. Replace free-port handoff and unbounded polling with a context-bound scrape, early startup error reporting, and cancellation plus join on every assertion path. Add an occupied-address regression that requires the bind diagnostic and forbids a startup callback on failure. Co-authored-by: Mecatl <[email protected]>
10 of 14 tasks
Merged
2 tasks
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.
Summary
127.0.0.1:0and report its actual bound address through an instance-localservehook. The test no longer reserves/closes a port and hopes it is still free when startup reaches metrics.http.Getcalls with one context-bound scrape after the listener has bound; report earlyserveexits and HTTP/body errors directly.listen metricsdiagnostic and proving startup is not announced after a failed bind.The successful test still builds the real mock/miniredis service, drives a run, executes the full server startup/shutdown implementation, and requires a real
/metricsresponse containing amecatl_series. Production supplies no observer; listener ownership and behavior are unchanged. The shared free-port helper remains for other tests outside this PR's scope.Fixes #2074.
Evidence and limits
The exact cause of the historical CI failure remains unproven. This removes the documented port-handoff race and unbounded polling hazards rather than increasing the readiness or shutdown timeouts. The occupied-address test deterministically exercises the startup failure the old handoff could permit; it does not reproduce the historical CI schedule.
Verification
go test -race ./cmd/mecak8s -run '^TestTelemetryMetricsAddr(ServesPrometheus|BindFailure)$' -count=50 -cpu=1,2,4— passed, 150 executions per test / 300 total.task lint— passed, zero issues across all modules.task test— passed (final integrated change, all modules and standalone proofs).task test:race— passed (all modules and standalone proofs; mecak8s package 8.425s).go run ./cmd/mecademo— passed; tool call, permission ask/approval, tool result, and final result observed.git diff main...HEAD --check— passed.Review
Independent Spec, Standards, Test adequacy, Architecture, Library reuse, and Duplication reviews. The initial missing occupied-address regression was added and re-reviewed; no unresolved findings. A suggestion to remove the shared port helper was withdrawn after checking its other callers.
API compatibility
No remote-observable contract changes: no API major/feature changes, protobuf changes, public Go API changes, or stored-data changes. The only production-code addition is an unexported bound-listener observation seam; production uses a nil observer. Existing clients and deployments require no upgrades or configuration changes.