-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Stop counterCache only when already started #19103
Conversation
Signed-off-by: chrismark <[email protected]>
Pinging @elastic/integrations-platforms (Team:Platforms) |
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
@exekias I think this is ready for a review ;), let me know what you think. |
attempts := 0 | ||
for !m.eventGenStarted { | ||
time.Sleep(m.period) | ||
// waiting 2 periods so as the first Fetch to start the generator, otherwise return since | ||
// Fetch is not called at all | ||
if attempts > 2 { | ||
return nil | ||
} | ||
attempts++ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need a backoff here. MB will make sure Fetch is not called after Close. This could just be:
if !m.eventGenStarted {
m.promEventsGen.Stop()
}
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
Signed-off-by: chrismark <[email protected]>
(cherry picked from commit 4a45bb4)
What does this PR do?
Adds a better handling for
counterCache
stop in order to avoid trying to stop a Janitor that is not yet started which will lead topanic
errors. This will happen in cases where the Metricset is stopped before the first Fetch is called and hence the generator is not yet started:beats/metricbeat/module/prometheus/collector/collector.go
Line 129 in 3ebceec
In order to handle this properly we wait 2 periods (the fetching period of the metricset) until we try to stop the counterCache. If after 2 periods the generator is not marked as started then we just return in
Stop
without stoping the counterCache since this indicates that the metricset was stoped before the firstFetch
.Why is it important?
To avoid having panic crashes on Autodiscover scenarios.
Related issues