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

Method readingType

expfmt/text_parse.go:661–685  ·  view source on GitHub ↗

readingType represents the state where the last byte read (now in p.currentByte) is the first byte of the type hint after 'HELP'.

()

Source from the content-addressed store, hash-verified

659// readingType represents the state where the last byte read (now in
660// p.currentByte) is the first byte of the type hint after 'HELP'.
661func (p *TextParser) readingType() stateFn {
662 if p.currentMF.Type != nil {
663 p.parseError(fmt.Sprintf("second TYPE line for metric name %q, or TYPE reported after samples", p.currentMF.GetName()))
664 return nil
665 }
666 // Rest of line is the type.
667 if p.readTokenUntilNewline(false); p.err != nil {
668 return nil // Unexpected end of input.
669 }
670 typ := strings.ToUpper(p.currentToken.String()) // Tolerate any combination of upper and lower case.
671 metricType, ok := dto.MetricType_value[typ] // Tolerate "gauge_histogram" (not originally part of the text format).
672 if !ok {
673 // We also want to tolerate "gaugehistogram" to mark a gauge
674 // histogram, because that string is used in OpenMetrics. Note,
675 // however, that gauge histograms do not officially exist in the
676 // classic text format.
677 if typ != "GAUGEHISTOGRAM" {
678 p.parseError(fmt.Sprintf("unknown metric type %q", p.currentToken.String()))
679 return nil
680 }
681 metricType = int32(dto.MetricType_GAUGE_HISTOGRAM)
682 }
683 p.currentMF.Type = dto.MetricType(metricType).Enum()
684 return p.startOfLine
685}
686
687// parseError sets p.err to a ParseError at the current line with the given
688// message.

Callers

nothing calls this directly

Calls 3

parseErrorMethod · 0.95
readTokenUntilNewlineMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected