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

Method startLabelValue

expfmt/text_parse.go:447–513  ·  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

445// startLabelValue represents the state where the next byte read from p.buf is
446// the start of a (quoted) label value (or whitespace leading up to it).
447func (p *TextParser) startLabelValue() stateFn {
448 if p.skipBlankTab(); p.err != nil {
449 return nil // Unexpected end of input.
450 }
451 if p.currentByte != '"' {
452 p.parseError(fmt.Sprintf("expected '\"' at start of label value, found %q", p.currentByte))
453 return nil
454 }
455 if p.readTokenAsLabelValue(); p.err != nil {
456 return nil
457 }
458 if !model.LabelValue(p.currentToken.String()).IsValid() {
459 p.parseError(fmt.Sprintf("invalid label value %q", p.currentToken.String()))
460 return nil
461 }
462 p.currentLabelPair.Value = proto.String(p.currentToken.String())
463 // Special treatment of summaries:
464 // - Quantile labels are special, will result in dto.Quantile later.
465 // - Other labels have to be added to currentLabels for signature calculation.
466 if p.currentMF.GetType() == dto.MetricType_SUMMARY {
467 if p.currentLabelPair.GetName() == model.QuantileLabel {
468 if p.currentQuantile, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
469 // Create a more helpful error message.
470 p.parseError(fmt.Sprintf("expected float as value for 'quantile' label, got %q", p.currentLabelPair.GetValue()))
471 p.currentLabelPairs = nil
472 return nil
473 }
474 } else {
475 p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue()
476 }
477 }
478 // Similar special treatment of histograms.
479 if p.currentMF.GetType() == dto.MetricType_HISTOGRAM || p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
480 if p.currentLabelPair.GetName() == model.BucketLabel {
481 if p.currentBucket, p.err = parseFloat(p.currentLabelPair.GetValue()); p.err != nil {
482 // Create a more helpful error message.
483 p.parseError(fmt.Sprintf("expected float as value for 'le' label, got %q", p.currentLabelPair.GetValue()))
484 return nil
485 }
486 } else {
487 p.currentLabels[p.currentLabelPair.GetName()] = p.currentLabelPair.GetValue()
488 }
489 }
490 if p.skipBlankTab(); p.err != nil {
491 return nil // Unexpected end of input.
492 }
493 switch p.currentByte {
494 case ',':
495 return p.startLabelName
496
497 case '}':
498 if p.currentMF == nil {
499 p.parseError("invalid metric name")
500 return nil
501 }
502 p.currentMetric.Label = append(p.currentMetric.Label, p.currentLabelPairs...)
503 p.currentLabelPairs = nil
504 if p.skipBlankTab(); p.err != nil {

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