MCPcopy Create free account
hub / github.com/netdata/netdata / parseToSeries

Method parseToSeries

src/go/pkg/prometheus/parse.go:50–84  ·  view source on GitHub ↗
(text []byte)

Source from the content-addressed store, hash-verified

48}
49
50func (p *promTextParser) parseToSeries(text []byte) (Series, error) {
51 p.series.Reset()
52
53 parser := textparse.NewPromParser(text, labels.NewSymbolTable())
54 for {
55 entry, err := parser.Next()
56 if err != nil {
57 if errors.Is(err, io.EOF) {
58 break
59 }
60 if entry == textparse.EntryInvalid && strings.HasPrefix(err.Error(), "invalid metric type") {
61 continue
62 }
63 return nil, fmt.Errorf("failed to parse prometheus metrics: %v", err)
64 }
65
66 switch entry {
67 case textparse.EntrySeries:
68 p.currSeries = p.currSeries[:0]
69
70 parser.Metric(&p.currSeries)
71
72 if p.sr != nil && !p.sr.Matches(p.currSeries) {
73 continue
74 }
75
76 _, _, val := parser.Series()
77 p.series.Add(SeriesSample{Labels: copyLabels(p.currSeries), Value: val})
78 }
79 }
80
81 p.series.Sort()
82
83 return p.series, nil
84}
85
86var reSpace = regexp.MustCompile(`\s+`)
87

Calls 9

IsMethod · 0.80
SortMethod · 0.80
copyLabelsFunction · 0.70
ResetMethod · 0.65
NextMethod · 0.65
ErrorfMethod · 0.65
MatchesMethod · 0.65
AddMethod · 0.65
ErrorMethod · 0.45