metricshandler: stop busy-looping and honor ctx in collector#428
Open
tamalsaha wants to merge 1 commit into
Open
metricshandler: stop busy-looping and honor ctx in collector#428tamalsaha wants to merge 1 commit into
tamalsaha wants to merge 1 commit into
Conversation
StartMetricsCollector ran an unbounded for-loop that:
- called "continue" on a collection error, skipping the time.Sleep and
busy-looping (hammering the API server) whenever collection kept failing;
- never observed the passed ctx, so the goroutine kept running after the
manager shut down.
Replace the loop with wait.UntilWithContext, which waits a full
MetricsRefreshPeriod between runs regardless of success/failure and returns
when ctx is cancelled.
Also harden MetricsStore.WriteAll with a bounds check so a partially
populated store (fewer families than headers) cannot panic the /metrics
handler with an index-out-of-range.
Signed-off-by: Tamal Saha <tamal@appscode.com>
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.
Problem
StartMetricsCollectorran an unboundedfor { ... }loop with two issues (pkg/metricshandler/handler.go):continuejumps back to the top without sleeping, so any persistent collection error turns this into a hot loop hammering the API server.ctx, so the goroutine keeps running after the manager shuts down.Fix
wait.UntilWithContext, which always waits a fullMetricsRefreshPeriodbetween runs (success or failure) and returns whenctxis cancelled.MetricsStore.WriteAllso a partially populated store (fewer families than headers) can't panic the/metricshandler with an index-out-of-range. In normal operation headers and families are built behind the same install flags and stay in sync, so this is hardening rather than a live bug.Testing
go build ./...passes.go vetandgofmtclean on the changed files.