Skip to content

textfile: fix panic on a metric without HELP after inconsistent help texts - #3866

Open
vignesh2027 wants to merge 1 commit into
prometheus:masterfrom
vignesh2027:textfile-missing-help-panic
Open

vignesh2027 wants to merge 1 commit into
prometheus:masterfrom
vignesh2027:textfile-missing-help-panic

Conversation

@vignesh2027

Copy link
Copy Markdown

@SuperQ

The textfile collector panics with a nil pointer dereference when the same metric appears in three or more .prom files, two of them with different HELP texts and a later one with no HELP line at all.

After the first mismatch, the help text check treats every later family with that name as inconsistent because of the || helpTexts[1] != "" branch. That branch is also taken when the family has no HELP, and the code then reads *mf.Help, which is nil. The panic happens inside the per-collector goroutine started by NodeCollector.Collect, so nothing recovers it and node_exporter exits.

This change logs the help text through mf.GetHelp() and only overwrites the recorded help text when the new family has one. A family with no HELP is now dropped and reported through node_textfile_scrape_error, the same way other inconsistent families are.

TestTextfileCollectorInconsistentHelpThenNoHelp writes four files: HELP "First", HELP "Second", no HELP, and HELP "First" again. On main it fails with the recovered nil pointer panic. With this change only the first file's metric is exported and the scrape error is set. The fourth file checks that a family with no HELP does not clear the inconsistency marker.

…texts

Once a metric has been seen with two different help texts, every later
family with the same name is treated as inconsistent. If such a later
family has no HELP line, the collector dereferenced its nil help text
and panicked. The panic happens in the per-collector goroutine, so it
takes down node_exporter.

Use the getter for the log line and keep the recorded help text when
the new family has none.

Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant