MCPcopy
hub / github.com/prometheus/client_golang / MakeLabelPairs

Function MakeLabelPairs

prometheus/value.go:217–237  ·  view source on GitHub ↗

MakeLabelPairs is a helper function to create protobuf LabelPairs from the variable and constant labels in the provided Desc. The values for the variable labels are defined by the labelValues slice, which must be in the same order as the corresponding variable labels in the Desc. This function is o

(desc *Desc, labelValues []string)

Source from the content-addressed store, hash-verified

215// This function is only needed for custom Metric implementations. See MetricVec
216// example.
217func MakeLabelPairs(desc *Desc, labelValues []string) []*dto.LabelPair {
218 totalLen := len(desc.variableLabels.names) + len(desc.constLabelPairs)
219 if totalLen == 0 {
220 // Super fast path.
221 return nil
222 }
223 if len(desc.variableLabels.names) == 0 {
224 // Moderately fast path.
225 return desc.constLabelPairs
226 }
227 labelPairs := make([]*dto.LabelPair, 0, totalLen)
228 for i, l := range desc.variableLabels.names {
229 labelPairs = append(labelPairs, &dto.LabelPair{
230 Name: proto.String(l),
231 Value: proto.String(labelValues[i]),
232 })
233 }
234 labelPairs = append(labelPairs, desc.constLabelPairs...)
235 sort.Sort(internal.LabelPairSorter(labelPairs))
236 return labelPairs
237}
238
239// ExemplarMaxRunes is the max total number of runes allowed in exemplar labels.
240const ExemplarMaxRunes = 128

Callers 14

NewInfoVecFunction · 0.92
newValueFuncFunction · 0.85
NewConstMetricFunction · 0.85
NewCounterVecMethod · 0.85
newHistogramFunction · 0.85
NewConstHistogramFunction · 0.85
NewConstNativeHistogramFunction · 0.85
newSummaryFunction · 0.85
NewConstSummaryFunction · 0.85

Calls 2

LabelPairSorterTypeAlias · 0.92
StringMethod · 0.45

Tested by 2

NewInfoVecFunction · 0.74