mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
refac: improve error handling
Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
parent
d4f13f6604
commit
8ccc9afa2a
|
@ -448,7 +448,13 @@ func (p *OpenMetricsParser) Next() (Entry, error) {
|
||||||
|
|
||||||
p.series = p.l.b[p.start:p.l.i]
|
p.series = p.l.b[p.start:p.l.i]
|
||||||
suffixEntry, err := p.parseMetricSuffix(p.nextToken())
|
suffixEntry, err := p.parseMetricSuffix(p.nextToken())
|
||||||
return p.skipCTParsing(suffixEntry, err)
|
if err != nil {
|
||||||
|
return EntryInvalid, err
|
||||||
|
}
|
||||||
|
if p.isCreatedSeries() && p.skipCTSeries {
|
||||||
|
return p.Next()
|
||||||
|
}
|
||||||
|
return suffixEntry, nil
|
||||||
case tMName:
|
case tMName:
|
||||||
p.offsets = append(p.offsets, p.start, p.l.i)
|
p.offsets = append(p.offsets, p.start, p.l.i)
|
||||||
p.series = p.l.b[p.start:p.l.i]
|
p.series = p.l.b[p.start:p.l.i]
|
||||||
|
@ -464,7 +470,13 @@ func (p *OpenMetricsParser) Next() (Entry, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
suffixEntry, err := p.parseMetricSuffix(t2)
|
suffixEntry, err := p.parseMetricSuffix(t2)
|
||||||
return p.skipCTParsing(suffixEntry, err)
|
if err != nil {
|
||||||
|
return EntryInvalid, err
|
||||||
|
}
|
||||||
|
if p.isCreatedSeries() && p.skipCTSeries {
|
||||||
|
return p.Next()
|
||||||
|
}
|
||||||
|
return suffixEntry, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = p.parseError("expected a valid start token", t)
|
err = p.parseError("expected a valid start token", t)
|
||||||
|
@ -580,23 +592,20 @@ func (p *OpenMetricsParser) parseLVals(offsets []int, isExemplar bool) ([]int, e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipCTParsing checks if the current series is a _created series and skips it if necessary.
|
// isCreatedSeries returns true if the current series is a _created series.
|
||||||
func (p *OpenMetricsParser) skipCTParsing(e Entry, err error) (Entry, error) {
|
func (p *OpenMetricsParser) isCreatedSeries() bool {
|
||||||
if e != EntrySeries || !p.skipCTSeries || err != nil {
|
|
||||||
return e, err
|
|
||||||
}
|
|
||||||
var newLbs labels.Labels
|
var newLbs labels.Labels
|
||||||
p.Metric(&newLbs)
|
p.Metric(&newLbs)
|
||||||
name := newLbs.Get(model.MetricNameLabel)
|
name := newLbs.Get(model.MetricNameLabel)
|
||||||
switch p.mtype {
|
switch p.mtype {
|
||||||
case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram:
|
case model.MetricTypeCounter, model.MetricTypeSummary, model.MetricTypeHistogram:
|
||||||
if strings.HasSuffix(name, "_created") {
|
if strings.HasSuffix(name, "_created") {
|
||||||
return p.Next()
|
return true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return EntrySeries, nil
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseMetricSuffix parses the end of the line after the metric name and
|
// parseMetricSuffix parses the end of the line after the metric name and
|
||||||
|
|
Loading…
Reference in a new issue