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

Method setOrCreateCurrentMF

expfmt/text_parse.go:903–944  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

901}
902
903func (p *TextParser) setOrCreateCurrentMF() {
904 p.currentIsSummaryCount = false
905 p.currentIsSummarySum = false
906 p.currentIsHistogramCount = false
907 p.currentIsHistogramSum = false
908 name := p.currentToken.String()
909 if !p.scheme.IsValidMetricName(name) {
910 p.parseError(fmt.Sprintf("invalid metric name %q", name))
911 return
912 }
913 if p.currentMF = p.metricFamiliesByName[name]; p.currentMF != nil {
914 return
915 }
916 // Try out if this is a _sum or _count for a summary/histogram.
917 summaryName := summaryMetricName(name)
918 if p.currentMF = p.metricFamiliesByName[summaryName]; p.currentMF != nil {
919 if p.currentMF.GetType() == dto.MetricType_SUMMARY {
920 if isCount(name) {
921 p.currentIsSummaryCount = true
922 }
923 if isSum(name) {
924 p.currentIsSummarySum = true
925 }
926 return
927 }
928 }
929 histogramName := histogramMetricName(name)
930 if p.currentMF = p.metricFamiliesByName[histogramName]; p.currentMF != nil {
931 if p.currentMF.GetType() == dto.MetricType_HISTOGRAM ||
932 p.currentMF.GetType() == dto.MetricType_GAUGE_HISTOGRAM {
933 if isCount(name) {
934 p.currentIsHistogramCount = true
935 }
936 if isSum(name) {
937 p.currentIsHistogramSum = true
938 }
939 return
940 }
941 }
942 p.currentMF = &dto.MetricFamily{Name: proto.String(name)}
943 p.metricFamiliesByName[name] = p.currentMF
944}
945
946func isValidLabelNameStart(b byte) bool {
947 return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || b == '"'

Callers 3

startCommentMethod · 0.95
readingMetricNameMethod · 0.95
startLabelNameMethod · 0.95

Calls 7

parseErrorMethod · 0.95
summaryMetricNameFunction · 0.85
isCountFunction · 0.85
isSumFunction · 0.85
histogramMetricNameFunction · 0.85
IsValidMetricNameMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected