-
Notifications
You must be signed in to change notification settings - Fork 5k
[metricbeat/prometheus] Add panic recovery for Prometheus textparser #47914
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
base: main
Are you sure you want to change the base?
Conversation
Add safeLabels and safeExemplar wrappers to prevent panics from malformed Prometheus metrics crashing the application. The underlying Prometheus textparse library can panic on certain malformed inputs. Also fix nil pointer dereference in MetricFamily.GetUnit().
🤖 GitHub commentsJust comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
|
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
mykola-elastic
left a comment
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.
LGTM!
Proposed commit message
This PR hardens the Prometheus metrics parser against panics caused by malformed input data. The underlying Prometheus
textparselibrary can panic on certain malformed inputs when callingparser.Labels()orparser.Exemplar(). These panics can crash Metricbeat when scraping endpoints that return unexpected data.safeLabelsandsafeExemplarwrapper functions that usedefer recover()to catch panics from the Prometheus parser libraryMetricFamily.GetUnit()to check for nilUnitbefore dereferencingChecklist
stresstest.shscript to run them under stress conditions and race detector to verify their stability../changelog/fragmentsusing the changelog tool.Author's Checklist
TestParseMetricFamiliesMalformedInputwith known crash-inducing inputsFuzzParseMetricFamiliesto discover future crash inputs