MCPcopy
hub / github.com/prometheus/pushgateway / groupingKeyFor

Function groupingKeyFor

storage/diskmetricstore.go:462–483  ·  view source on GitHub ↗

groupingKeyFor creates a grouping key from the provided map of grouping labels. The grouping key is created by joining all label names and values together with model.SeparatorByte as a separator. The label names are sorted lexicographically before joining. In that way, the grouping key is both repro

(labels map[string]string)

Source from the content-addressed store, hash-verified

460// lexicographically before joining. In that way, the grouping key is both
461// reproducible and unique.
462func groupingKeyFor(labels map[string]string) string {
463 if len(labels) == 0 { // Super fast path.
464 return ""
465 }
466
467 labelNames := make([]string, 0, len(labels))
468 for labelName := range labels {
469 labelNames = append(labelNames, labelName)
470 }
471 sort.Strings(labelNames)
472
473 sb := strings.Builder{}
474 for i, labelName := range labelNames {
475 sb.WriteString(labelName)
476 sb.WriteByte(model.SeparatorByte)
477 sb.WriteString(labels[labelName])
478 if i+1 < len(labels) { // No separator at the end.
479 sb.WriteByte(model.SeparatorByte)
480 }
481 }
482 return sb.String()
483}
484
485// extractPredefinedHelpStrings extracts all the HELP strings from the provided
486// gatherer so that the DiskMetricStore can fix deviations in pushed metrics.

Callers 6

processWriteRequestMethod · 0.85
addGroupFunction · 0.85
TestGetMetricFamiliesMapFunction · 0.85
TestGroupingKeyForLabelsFunction · 0.85

Calls

no outgoing calls

Tested by 4

addGroupFunction · 0.68
TestGetMetricFamiliesMapFunction · 0.68
TestGroupingKeyForLabelsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…