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

Function SignatureForLabels

model/signature.go:98–113  ·  view source on GitHub ↗

SignatureForLabels works like LabelsToSignature but takes a Metric as parameter (rather than a label map) and only includes the labels with the specified LabelNames into the signature calculation. The labels passed in will be sorted by this function.

(m Metric, labels ...LabelName)

Source from the content-addressed store, hash-verified

96// specified LabelNames into the signature calculation. The labels passed in
97// will be sorted by this function.
98func SignatureForLabels(m Metric, labels ...LabelName) uint64 {
99 if len(labels) == 0 {
100 return emptyLabelSignature
101 }
102
103 slices.Sort(labels)
104
105 sum := hashNew()
106 for _, label := range labels {
107 sum = hashAdd(sum, string(label))
108 sum = hashAddByte(sum, SeparatorByte)
109 sum = hashAdd(sum, string(m[label]))
110 sum = hashAddByte(sum, SeparatorByte)
111 }
112 return sum
113}
114
115// SignatureWithoutLabels works like LabelsToSignature but takes a Metric as
116// parameter (rather than a label map) and excludes the labels with any of the

Callers 1

TestSignatureForLabelsFunction · 0.85

Calls 3

hashNewFunction · 0.85
hashAddFunction · 0.85
hashAddByteFunction · 0.85

Tested by 1

TestSignatureForLabelsFunction · 0.68