Skip to content

Cover the beat lifecycle (New/Run/Stop) to satisfy the coverage gate#15

Merged
cjimti merged 1 commit into
masterfrom
14-cover-beat-lifecycle
Jun 17, 2026
Merged

Cover the beat lifecycle (New/Run/Stop) to satisfy the coverage gate#15
cjimti merged 1 commit into
masterfrom
14-cover-beat-lifecycle

Conversation

@cjimti

@cjimti cjimti commented Jun 17, 2026

Copy link
Copy Markdown
Member

Closes #14.

Raises beater coverage from ~27% to 89% (repo 86.8%), clearing the >= 80% Codecov gate, with a real lifecycle test rather than coverage padding. make verify passes; go test -race -count=10 is clean.

Test

TestRunLifecycle drives the full beat through a fake libbeat pipeline:
NewRun on an ephemeral port → POST /in (asserts the pipeline receives the published events) → GET /metrics → invoke the captured ACK handler → Stop (asserts the client closes and Run returns nil).

Per-function after this change: Stop 100%, Run ~93%, New 75%, buildEvents/inHandler 100%. The remaining gaps are unreachable error paths (a logger-build failure, log.Fatalf on a bind error).

Production change (behavior-preserving DI seam)

Rtbeat gains optional registerer/gatherer fields, both nil in production, resolving to the global default registerer/gatherer. Metrics are built via promauto.With(registerer); /metrics is served via promhttp.InstrumentMetricHandler(registerer, HandlerFor(gatherer, HandlerOpts{})).

Verified against client_golang v1.23.2 source that promhttp.Handler() is exactly InstrumentMetricHandler(DefaultRegisterer, HandlerFor(DefaultGatherer, HandlerOpts{})) — so with the fields nil the prod /metrics output (go_*, process_*, promhttp_metric_handler_*, and the four rtbeat_* metrics) is unchanged. The seam exists so tests can inject a private registry; otherwise a second Run in one process would panic on the global registry's duplicate-registration guard (a fragility this PR also removes).

Review

Adversarial review confirmed prod equivalence (against the actual module source), a race-free/non-flaky test, and meaningful assertions. A naive HandlerFor-only handler would have dropped two promhttp_metric_handler_* metrics from prod — caught and corrected to use InstrumentMetricHandler.

Raise beater coverage from ~27% to ~89% (repo 86.8%) with a real
lifecycle test, clearing the >=80% Codecov gate.

Test:
- TestRunLifecycle drives the full beat through a fake libbeat
  pipeline: New -> Run on an ephemeral port -> POST /in (asserts the
  pipeline receives the published events) -> GET /metrics -> invoke
  the ACK handler -> Stop (asserts the client closes and Run returns).

Production change (behavior-preserving DI seam):
- Rtbeat gains optional registerer/gatherer fields, both nil in
  production, resolving to the global default registerer/gatherer.
  Metrics are built via promauto.With(registerer); /metrics is served
  via promhttp.InstrumentMetricHandler(registerer, HandlerFor(gatherer,
  ...)), which is exactly what promhttp.Handler() does against the
  global default. Tests inject a private registry so repeated Run calls
  don't collide on the global registry's duplicate-registration guard.

Verified against client_golang v1.23.2 that the prod /metrics output
(go_*, process_*, promhttp_metric_handler_*, and the four rtbeat_*
metrics) is unchanged. make verify passes; go test -race -count=10 is
clean.

Closes #14
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.99%. Comparing base (ccb809e) to head (75e7de2).

Files with missing lines Patch % Lines
beater/rtbeat.go 71.42% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #15       +/-   ##
===========================================
+ Coverage   25.43%   86.99%   +61.55%     
===========================================
  Files           2        2               
  Lines         114      123        +9     
===========================================
+ Hits           29      107       +78     
+ Misses         85       10       -75     
- Partials        0        6        +6     
Files with missing lines Coverage Δ
beater/rtbeat.go 89.16% <71.42%> (+63.04%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cjimti cjimti merged commit 1cef2bf into master Jun 17, 2026
9 checks passed
@cjimti cjimti deleted the 14-cover-beat-lifecycle branch June 17, 2026 00:17
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.

Cover the beat lifecycle (New/Run/Stop) to satisfy the 80% coverage gate

1 participant