From 01ec8c5c5c3636a52d6f9e7c6f6cebaeb9f07af4 Mon Sep 17 00:00:00 2001 From: Dario Maiocchi Date: Fri, 5 Oct 2018 13:20:30 +0200 Subject: [PATCH] Remove continue with label (#1084) Instead of continue with label use helper function Signed-off-by: dmaiocchi --- MAINTAINERS.md | 4 ++-- collector/textfile.go | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 7088f96e..ffe90361 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -1,2 +1,2 @@ -* Ben Kochie -* Johannes 'fish' Ziemke +* Ben Kochie @SuperQ +* Johannes 'fish' Ziemke @discordianfish diff --git a/collector/textfile.go b/collector/textfile.go index bc2ac43c..ddd88b85 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -193,7 +193,6 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { error = 1.0 } -fileLoop: for _, f := range files { if !strings.HasSuffix(f.Name(), ".prom") { continue @@ -213,14 +212,13 @@ fileLoop: error = 1.0 continue } + if hasTimestamps(parsedFamilies) { + log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path) + error = 1.0 + continue + } + for _, mf := range parsedFamilies { - for _, m := range mf.Metric { - if m.TimestampMs != nil { - log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path) - error = 1.0 - continue fileLoop - } - } if mf.Help == nil { help := fmt.Sprintf("Metric read from %s", path) mf.Help = &help @@ -249,3 +247,15 @@ fileLoop: ) return nil } + +// hasTimestamps returns true when metrics contain unsupported timestamps. +func hasTimestamps(parsedFamilies map[string]*dto.MetricFamily) bool { + for _, mf := range parsedFamilies { + for _, m := range mf.Metric { + if m.TimestampMs != nil { + return true + } + } + } + return false +}