Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# HELP foo First help text.
# TYPE foo gauge
foo{file="a"} 1
# HELP node_textfile_mtime_seconds Unixtime mtime of textfiles successfully read.
# TYPE node_textfile_mtime_seconds gauge
node_textfile_mtime_seconds{file="fixtures/textfile/metrics_merge_inconsistent_then_no_help/a.prom"} 1
node_textfile_mtime_seconds{file="fixtures/textfile/metrics_merge_inconsistent_then_no_help/b.prom"} 1
node_textfile_mtime_seconds{file="fixtures/textfile/metrics_merge_inconsistent_then_no_help/c.prom"} 1
node_textfile_mtime_seconds{file="fixtures/textfile/metrics_merge_inconsistent_then_no_help/d.prom"} 1
# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
# TYPE node_textfile_scrape_error gauge
node_textfile_scrape_error 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# HELP foo First help text.
# TYPE foo gauge
foo{file="a"} 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# HELP foo Second help text.
# TYPE foo gauge
foo{file="b"} 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TYPE foo gauge
foo{file="c"} 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# HELP foo First help text.
# TYPE foo gauge
foo{file="d"} 4
6 changes: 4 additions & 2 deletions collector/textfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error {
// Check for metrics with inconsistent help texts and take the first help text occurrence.
if helpTexts, seen := metricsNamesToHelpTexts[*mf.Name]; seen {
if mf.Help != nil && helpTexts[0] != *mf.Help || helpTexts[1] != "" {
metricsNamesToHelpTexts[*mf.Name] = [2]string{helpTexts[0], *mf.Help}
if mf.Help != nil {
metricsNamesToHelpTexts[*mf.Name] = [2]string{helpTexts[0], *mf.Help}
}
errored = true
c.logger.Error("inconsistent metric help text",
"metric", *mf.Name,
"original_help_text", helpTexts[0],
"new_help_text", *mf.Help,
"new_help_text", mf.GetHelp(),
// Only the first file path will be recorded in case of two or more inconsistent help texts.
"file", metricsNamesToFiles[*mf.Name][0])
continue
Expand Down
4 changes: 4 additions & 0 deletions collector/textfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func TestTextfileCollector(t *testing.T) {
paths: []string{"fixtures/textfile/metrics_merge_different_help"},
out: "fixtures/textfile/metrics_merge_different_help.out",
},
{
paths: []string{"fixtures/textfile/metrics_merge_inconsistent_then_no_help"},
out: "fixtures/textfile/metrics_merge_inconsistent_then_no_help.out",
},
}

for i, test := range tests {
Expand Down