MCPcopy Create free account
hub / github.com/prometheus/common / startLabelName

Method startLabelName

expfmt/text_parse.go:273–320  ·  view source on GitHub ↗

startLabelName represents the state where the next byte read from p.buf is the start of a label name (or whitespace leading up to it).

()

Source from the content-addressed store, hash-verified

271// startLabelName represents the state where the next byte read from p.buf is
272// the start of a label name (or whitespace leading up to it).
273func (p *TextParser) startLabelName() stateFn {
274 if p.skipBlankTab(); p.err != nil {
275 return nil // Unexpected end of input.
276 }
277 if p.currentByte == '}' {
278 if p.skipBlankTab(); p.err != nil {
279 return nil // Unexpected end of input.
280 }
281 return p.readingValue
282 }
283 if p.readTokenAsLabelName(); p.err != nil {
284 return nil // Unexpected end of input.
285 }
286 if p.currentToken.Len() == 0 {
287 p.parseError(fmt.Sprintf("invalid label name for metric %q", p.currentMF.GetName()))
288 return nil
289 }
290 p.currentLabelPair = &dto.LabelPair{Name: proto.String(p.currentToken.String())}
291 if p.currentLabelPair.GetName() == string(model.MetricNameLabel) {
292 p.parseError(fmt.Sprintf("label name %q is reserved", model.MetricNameLabel))
293 return nil
294 }
295 // Special summary/histogram treatment. Don't add 'quantile' and 'le'
296 // labels to 'real' labels.
297 if !(p.currentMF.GetType() == dto.MetricType_SUMMARY && p.currentLabelPair.GetName() == model.QuantileLabel) &&
298 !(p.currentMF.GetType() == dto.MetricType_HISTOGRAM && p.currentLabelPair.GetName() == model.BucketLabel) {
299 p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPair)
300 }
301 if p.skipBlankTabIfCurrentBlankTab(); p.err != nil {
302 return nil // Unexpected end of input.
303 }
304 if p.currentByte != '=' {
305 p.parseError(fmt.Sprintf("expected '=' after label name, found %q", p.currentByte))
306 return nil
307 }
308 // Check for duplicate label names.
309 labels := make(map[string]struct{})
310 for _, l := range p.currentMetric.Label {
311 lName := l.GetName()
312 if _, exists := labels[lName]; !exists {
313 labels[lName] = struct{}{}
314 } else {
315 p.parseError(fmt.Sprintf("duplicate label names for metric %q", p.currentMF.GetName()))
316 return nil
317 }
318 }
319 return p.startLabelValue
320}
321
322// startLabelValue represents the state where the next byte read from p.buf is
323// the start of a (quoted) label value (or whitespace leading up to it).

Callers

nothing calls this directly

Calls 6

skipBlankTabMethod · 0.95
readTokenAsLabelNameMethod · 0.95
parseErrorMethod · 0.95
StringMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected