Skip to content

Commit

Permalink
Merge pull request prometheus-community#968 from breed808/textfile
Browse files Browse the repository at this point in the history
Skip processing files with duplicates metrics
  • Loading branch information
breed808 authored May 16, 2022
2 parents 824fdd4 + 0de7e44 commit 272b55e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion collector/textfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ fileLoop:
error = 1.0
continue
}

// Use temporary array to check for duplicates
var families_array []*dto.MetricFamily

for _, mf := range parsedFamilies {
families_array = append(families_array, mf)
for _, m := range mf.Metric {
if m.TimestampMs != nil {
log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path)
Expand All @@ -298,6 +303,13 @@ fileLoop:
}
}

// If duplicate metrics are detected in a *single* file, skip processing of file metrics
if duplicateMetricEntry(families_array) {
log.Errorf("Duplicate metrics detected in file %s. Skipping file processing.", f.Name())
error = 1.0
continue
}

// Only set this once it has been parsed and validated, so that
// a failure does not appear fresh.
mtimes[f.Name()] = f.ModTime()
Expand All @@ -307,8 +319,9 @@ fileLoop:
}
}

// If duplicates are detected across *multiple* files, return error.
if duplicateMetricEntry(metricFamilies) {
log.Errorf("Duplicate metrics detected in files")
log.Errorf("Duplicate metrics detected across multiple files")
error = 1.0
} else {
for _, mf := range metricFamilies {
Expand Down

0 comments on commit 272b55e

Please sign in to comment.