MCPcopy
hub / github.com/prometheus/prometheus / Labels

Method Labels

model/textparse/promparse.go:232–268  ·  view source on GitHub ↗

Labels writes the labels of the current sample into the passed labels.

(l *labels.Labels)

Source from the content-addressed store, hash-verified

230
231// Labels writes the labels of the current sample into the passed labels.
232func (p *PromParser) Labels(l *labels.Labels) {
233 // Defensive copy in case the following keeps a reference.
234 // See https://github.com/prometheus/prometheus/issues/16490
235 s := string(p.series)
236 p.builder.Reset()
237 metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start])
238
239 m := schema.Metadata{
240 Name: metricName,
241 // NOTE(bwplotka): There is a known case where the type is wrong on a broken exposition
242 // (see the TestPromParse windspeed metric). Fixing it would require extra
243 // allocs and benchmarks. Since it was always broken, don't fix for now.
244 Type: p.mtype,
245 }
246
247 if p.enableTypeAndUnitLabels {
248 m.AddToLabels(&p.builder)
249 } else {
250 p.builder.Add(labels.MetricName, metricName)
251 }
252 for i := 2; i < len(p.offsets); i += 4 {
253 a := p.offsets[i] - p.start
254 b := p.offsets[i+1] - p.start
255 label := unreplace(s[a:b])
256 if p.enableTypeAndUnitLabels && !m.IsEmptyFor(label) {
257 // Dropping user provided metadata labels, if found in the OM metadata.
258 continue
259 }
260 c := p.offsets[i+2] - p.start
261 d := p.offsets[i+3] - p.start
262 value := normalizeFloatsInLabelValues(p.mtype, label, unreplace(s[c:d]))
263 p.builder.Add(label, value)
264 }
265
266 p.builder.Sort()
267 *l = p.builder.Labels()
268}
269
270// Exemplar implements the Parser interface. However, since the classic
271// Prometheus text format does not support exemplars, this implementation simply

Callers 1

Calls 8

AddToLabelsMethod · 0.95
IsEmptyForMethod · 0.95
unreplaceFunction · 0.85
ResetMethod · 0.65
AddMethod · 0.65
LabelsMethod · 0.65
SortMethod · 0.45

Tested by 1