Skip to content

fix(otelconf): report Prometheus HTTP server errors in v0.2.0 - #9653

Merged
pellared merged 2 commits into
open-telemetry:mainfrom
KR-Ravindra:fix/otelconf-v020-prometheus-serve-err
Sep 15, 2026
Merged

pellared merged 2 commits into
open-telemetry:mainfrom
KR-Ravindra:fix/otelconf-v020-prometheus-serve-err

Conversation

@KR-Ravindra

@KR-Ravindra KR-Ravindra commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem

go.opentelemetry.io/contrib/otelconf/v0.2.0 starts an HTTP server for the Prometheus pull exporter in a goroutine. The error check on server.Serve(lis) is inverted: a clean shutdown (http.ErrServerClosed) is reported through otel.Handle as "the Prometheus HTTP server exited unexpectedly", while every genuine Serve failure (accept errors, TLS/listener problems, etc.) is silently dropped. Operators therefore get a spurious error on every shutdown and no signal at all when the metrics endpoint actually stops serving.

Root cause

otelconf/v0.2.0/metric.go:369:

if err := server.Serve(lis); err != nil && errors.Is(err, http.ErrServerClosed) {

The condition is missing the negation. The sibling implementations in otelconf/v0.3.0/metric.go and otelconf/x/metric.go already use !errors.Is(err, http.ErrServerClosed).

Fix

  • Negate the predicate (err != nil && !errors.Is(err, http.ErrServerClosed)), so the goroutine in prometheusReader is now identical to the one in v0.3.0 and x.
  • Add a CHANGELOG.md entry under Unreleased / Fixed.

No public API changes.

The first revision extracted the check into a handleServeErr helper with a table test; it was inlined again in e769464 at review request so the three implementations stay the same.

How tested

The handler is the process-global otel.Handle, so this branch has no isolated unit test (see the discussion on #9097); the fix is the same code that v0.3.0 and x already run.

From otelconf/: go build ./..., go vet ./v0.2.0/..., go test -race ./v0.2.0/... (ok), golangci-lint run ./v0.2.0/... (0 issues).

Links

This change was prepared with an AI agent operated by KR-Ravindra, who reviewed and tested it.

The Serve error check in prometheusReader was inverted, so a clean
shutdown (http.ErrServerClosed) was reported as unexpected while real
Serve errors were dropped. Extract the check into handleServeErr with
the corrected predicate, matching otelconf/v0.3.0 and otelconf/x, and
cover it with a unit test.
@KR-Ravindra
KR-Ravindra force-pushed the fix/otelconf-v020-prometheus-serve-err branch from bae65e0 to 5136f7d Compare September 9, 2026 09:16
@KR-Ravindra
KR-Ravindra marked this pull request as ready for review September 9, 2026 09:32
@KR-Ravindra
KR-Ravindra requested review from a team and pellared as code owners September 9, 2026 09:32
@github-actions
github-actions Bot requested a review from codeboten September 9, 2026 09:33
Comment thread otelconf/v0.2.0/metric.go Outdated
Drop the handleServeErr helper and its unit test so prometheusReader in v0.2.0 has the same code as v0.3.0 and x, as requested in review.

Signed-off-by: KR Ravindra <42912207+KR-Ravindra@users.noreply.github.com>
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.2%. Comparing base (9f2e057) to head (e769464).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #9653     +/-   ##
=======================================
- Coverage   87.2%   87.2%   -0.1%     
=======================================
  Files        201     201             
  Lines      14029   14029             
=======================================
- Hits       12235   12234      -1     
- Misses      1794    1795      +1     
Files with missing lines Coverage Δ
otelconf/v0.2.0/metric.go 93.4% <100.0%> (-0.4%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pellared
pellared merged commit 79fdc2e into open-telemetry:main Sep 15, 2026
32 checks passed
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.

otelconf: Prometheus metrics server errors are silently ignored

4 participants