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

Method startLabelValue

expfmt/text_parse.go:324–382  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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).
324func (p *TextParser) startLabelValue() stateFn {
325 if p.skipBlankTab(); p.err != nil {
326 return nil // Unexpected end of input.
327 }
328 if p.currentByte != '"' {
329 p.parseError(fmt.Sprintf("expected '\"' at start of label value, found %q", p.currentByte))
330 return nil
331 }
332 if p.readTokenAsLabelValue(); p.err != nil {
333 return nil
334 }
335 if !model.LabelValue(p.currentToken.String()).IsValid() {
336 p.parseError(fmt.Sprintf("invalid label value %q", p.currentToken.String()))
337 return nil
338 }
339 p.currentLabelPair.Value = proto.String(p.currentToken.String())
340 // Special treatment of summaries:
341 // - Quantile labels are special, will result in dto.Quantile later.
342 // - Other labels have to be added to currentLabels for signature calculation.
343 if p.currentMF.GetType() == dto.MetricType_SUMMARY {
344 if p.currentLabelPair.GetName() == model.QuantileLabel {
345 if p.currentQuantile, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
346 // Create a more helpful error message.
347 p.parseError(fmt.Sprintf("expected float as value for 'quantile' label, got %q", p.currentLabelPair.GetValue()))
348 return nil
349 }
350 } else {
351 p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue()
352 }
353 }
354 // Similar special treatment of histograms.
355 if p.currentMF.GetType() == dto.MetricType_HISTOGRAM {
356 if p.currentLabelPair.GetName() == model.BucketLabel {
357 if p.currentBucket, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
358 // Create a more helpful error message.
359 p.parseError(fmt.Sprintf("expected float as value for 'le' label, got %q", p.currentLabelPair.GetValue()))
360 return nil
361 }
362 } else {
363 p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue()
364 }
365 }
366 if p.skipBlankTab(); p.err != nil {
367 return nil // Unexpected end of input.
368 }
369 switch p.currentByte {
370 case ',':
371 return p.startLabelName
372
373 case '}':
374 if p.skipBlankTab(); p.err != nil {
375 return nil // Unexpected end of input.
376 }
377 return p.readingValue
378 default:
379 p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.GetValue()))
380 return nil
381 }

Callers

nothing calls this directly

Calls 7

skipBlankTabMethod · 0.95
parseErrorMethod · 0.95
readTokenAsLabelValueMethod · 0.95
LabelValueTypeAlias · 0.92
parseFloatFunction · 0.85
StringMethod · 0.65
IsValidMethod · 0.45

Tested by

no test coverage detected