Remove continue with label (#1084)

Instead of continue with label use helper function
Signed-off-by: dmaiocchi <dmaiocchi@suse.com>
This commit is contained in:
Dario Maiocchi 2018-10-05 13:20:30 +02:00 committed by Julius Volz
parent a1ce712e22
commit 01ec8c5c5c
2 changed files with 20 additions and 10 deletions

View File

@ -1,2 +1,2 @@
* Ben Kochie <superq@gmail.com> * Ben Kochie <superq@gmail.com> @SuperQ
* Johannes 'fish' Ziemke <github@freigeist.org> * Johannes 'fish' Ziemke <github@freigeist.org> @discordianfish

View File

@ -193,7 +193,6 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error {
error = 1.0 error = 1.0
} }
fileLoop:
for _, f := range files { for _, f := range files {
if !strings.HasSuffix(f.Name(), ".prom") { if !strings.HasSuffix(f.Name(), ".prom") {
continue continue
@ -213,14 +212,13 @@ fileLoop:
error = 1.0 error = 1.0
continue continue
} }
for _, mf := range parsedFamilies { if hasTimestamps(parsedFamilies) {
for _, m := range mf.Metric {
if m.TimestampMs != nil {
log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path) log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path)
error = 1.0 error = 1.0
continue fileLoop continue
}
} }
for _, mf := range parsedFamilies {
if mf.Help == nil { if mf.Help == nil {
help := fmt.Sprintf("Metric read from %s", path) help := fmt.Sprintf("Metric read from %s", path)
mf.Help = &help mf.Help = &help
@ -249,3 +247,15 @@ fileLoop:
) )
return nil 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
}