Skip to content

Commit 3349589

Browse files
Fix CI
Fix lint warnings. Signed-off-by: martincostello <martin@martincostello.com>
1 parent c8a254b commit 3349589

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

expfmt/openmetrics_parse.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"time"
2727

2828
dto "github.com/prometheus/client_model/go"
29-
3029
"google.golang.org/protobuf/proto"
3130
"google.golang.org/protobuf/types/known/timestamppb"
3231

@@ -366,9 +365,10 @@ func (p *OpenMetricsParser) startLabelName() stateFn {
366365
}
367366
// Special summary/histogram treatment. Don't add 'quantile' and 'le'
368367
// labels to 'real' labels.
369-
if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) &&
370-
!(p.currentMF.GetType() == dto.MetricType_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) &&
371-
!(p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) &&
368+
if (p.currentMF.GetType() != dto.MetricType_SUMMARY || p.currentLabelPair.GetName() != model.QuantileLabel) &&
369+
((p.currentMF.GetType() != dto.MetricType_HISTOGRAM &&
370+
p.currentMF.GetType() != dto.MetricType_GAUGE_HISTOGRAM) ||
371+
p.currentLabelPair.GetName() != model.BucketLabel) &&
372372
!p.currentIsMetricCreated {
373373
if p.currentIsExemplar {
374374
p.currentExemplar.Label = append(p.currentExemplar.Label, p.currentLabelPair)
@@ -390,11 +390,9 @@ func (p *OpenMetricsParser) startLabelName() stateFn {
390390
lName := l.GetName()
391391
if _, exists := labels[lName]; !exists {
392392
labels[lName] = struct{}{}
393-
} else {
394-
if !p.currentIsMetricCreated {
395-
p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
396-
return nil
397-
}
393+
} else if !p.currentIsMetricCreated {
394+
p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
395+
return nil
398396
}
399397
}
400398
}
@@ -470,11 +468,12 @@ func (p *OpenMetricsParser) readingValue() stateFn {
470468
// When we are here, we have read all the labels, so for the
471469
// special case of a summary/histogram, we can finally find out
472470
// if the metric already exists.
473-
if p.currentMF.GetType() == dto.MetricType_SUMMARY {
471+
switch p.currentMF.GetType() {
472+
case dto.MetricType_SUMMARY:
474473
p.currentMetric = p.getOrCreateMetric(p.summaries)
475-
} else if p.currentMF.GetType() == dto.MetricType_HISTOGRAM || p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
474+
case dto.MetricType_HISTOGRAM, dto.MetricType_GAUGE_HISTOGRAM:
476475
p.currentMetric = p.getOrCreateMetric(p.histograms)
477-
} else {
476+
default:
478477
p.currentMF.Metric = append(p.currentMF.Metric, p.currentMetric)
479478
}
480479
}
@@ -559,9 +558,10 @@ func (p *OpenMetricsParser) readingValue() stateFn {
559558
default:
560559
p.err = fmt.Errorf("unexpected type for metric name %q", p.currentMF.GetName())
561560
}
562-
if p.currentByte == '\n' {
561+
switch p.currentByte {
562+
case '\n':
563563
return p.startOfLine
564-
} else if p.currentByte == '#' {
564+
case '#':
565565
return p.startExemplar
566566
}
567567
return p.startTimestamp
@@ -621,10 +621,9 @@ func (p *OpenMetricsParser) startTimestamp() stateFn {
621621
if p.currentToken.Len() > 0 {
622622
if p.currentToken.String() == "#" {
623623
return p.startExemplar
624-
} else {
625-
p.parseError(fmt.Sprintf("spurious string after timestamp: %q", p.currentToken.String()))
626-
return nil
627624
}
625+
p.parseError(fmt.Sprintf("spurious string after timestamp: %q", p.currentToken.String()))
626+
return nil
628627
}
629628
return p.startOfLine
630629
}

0 commit comments

Comments
 (0)