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)
| 215 | // This function is only needed for custom Metric implementations. See MetricVec |
| 216 | // example. |
| 217 | func 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. |
| 240 | const ExemplarMaxRunes = 128 |