Cover the beat lifecycle (New/Run/Stop) to satisfy the coverage gate#15
Merged
Conversation
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 Report❌ Patch coverage is
Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
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.
Closes #14.
Raises
beatercoverage from ~27% to 89% (repo 86.8%), clearing the >= 80% Codecov gate, with a real lifecycle test rather than coverage padding.make verifypasses;go test -race -count=10is clean.Test
TestRunLifecycledrives the full beat through a fake libbeat pipeline:New→Runon an ephemeral port →POST /in(asserts the pipeline receives the published events) →GET /metrics→ invoke the captured ACK handler →Stop(asserts the client closes andRunreturns nil).Per-function after this change:
Stop100%,Run~93%,New75%,buildEvents/inHandler100%. The remaining gaps are unreachable error paths (a logger-build failure,log.Fatalfon a bind error).Production change (behavior-preserving DI seam)
Rtbeatgains optionalregisterer/gathererfields, both nil in production, resolving to the global default registerer/gatherer. Metrics are built viapromauto.With(registerer);/metricsis served viapromhttp.InstrumentMetricHandler(registerer, HandlerFor(gatherer, HandlerOpts{})).Verified against
client_golangv1.23.2 source thatpromhttp.Handler()is exactlyInstrumentMetricHandler(DefaultRegisterer, HandlerFor(DefaultGatherer, HandlerOpts{}))— so with the fields nil the prod/metricsoutput (go_*,process_*,promhttp_metric_handler_*, and the fourrtbeat_*metrics) is unchanged. The seam exists so tests can inject a private registry; otherwise a secondRunin 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 twopromhttp_metric_handler_*metrics from prod — caught and corrected to useInstrumentMetricHandler.