Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase timeout period for collecting metrics #755

Merged
merged 19 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/plugins/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func (m *Metrics) metricsGoroutine() {
}

func (m *Metrics) collectStats() (stats []*metrics.StatsEntityWrapper) {
// setups a collect duration of half-time of the poll interval
ctx, cancel := context.WithTimeout(m.ctx, m.interval/2)
// set a timeout for a millisecond less than the collection interval
ctx, cancel := context.WithTimeout(m.ctx, (m.interval - 1*time.Millisecond))
defer cancel()
// locks the m.collectors to make sure it doesn't get deleted in the middle
// of collection, as we will delete the old one if config changes.
Expand All @@ -232,7 +232,9 @@ func (m *Metrics) collectStats() (stats []*metrics.StatsEntityWrapper) {
// drain the buf, since our sources/collectors are all done, we can rely on buffer length
select {
case <-ctx.Done():
err := m.ctx.Err()
log.Debugf("context done in %s collectStats", time.Since(start))

err := ctx.Err()
if err != nil {
log.Errorf("error in done context collectStats %v", err)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading