Make the debug metrics endpoints leader aware#192
Open
jakubpliszka wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the debug metrics endpoints leader-aware by filtering out aggregated.* and probes.* metrics on follower nodes, preventing Datadog from observing stale/frozen expvar values after a leader demotion.
Changes:
- Replaces the old
/debug/varsand/debug/metricshandler with anAPIImpl.Metricsmethod that filtersaggregated.*andprobes.*when not leader. - Forces registry metrics to be (re)published into Go’s global
expvarregistry before rendering the filtered JSON response. - Adds a unit test to verify expvar values persist after unregister and are filtered on followers.
Show a summary per file
| File | Description |
|---|---|
| pkg/http/api.go | Adds a leader-aware Metrics handler and routes /debug/vars and /debug/metrics through it with filtering. |
| pkg/http/api_test.go | Adds coverage for leader vs follower behavior and expvar persistence after registry unregister. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Low
Comment on lines
+368
to
+372
| func (api *APIImpl) Metrics(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||
| exp.ExpHandler(metrics.DefaultRegistry).ServeHTTP(discardWriter{Writer: io.Discard}, r) | ||
| isLeader := api.consensusService != nil && api.consensusService.IsLeader() | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") |
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.
This pull requests omits
aggregated.*andprobes.*metrics on followers.After a leader is demoted, active metric collection stops, but previously exported values remain in Go’s global expvar registry. Consequently, Datadog continues observing frozen aggregate gauges and zero-rate probe counters from the former leader.
Removing metrics from go-metrics does not remove values already published to expvar, so filtering is applied when rendering the metrics response.