MCPcopy Index your code
hub / github.com/prometheus/pushgateway / splitLabels

Function splitLabels

handler/push.go:181–210  ·  view source on GitHub ↗

splitLabels splits a labels string into a label map mapping names to values.

(labels string)

Source from the content-addressed store, hash-verified

179
180// splitLabels splits a labels string into a label map mapping names to values.
181func splitLabels(labels string) (map[string]string, error) {
182 result := map[string]string{}
183 if len(labels) <= 1 {
184 return result, nil
185 }
186 components := strings.Split(labels[1:], "/")
187 if len(components)%2 != 0 {
188 return nil, fmt.Errorf("odd number of components in label string %q", labels)
189 }
190
191 for i := 0; i < len(components)-1; i += 2 {
192 name, value := components[i], components[i+1]
193 trimmedName := strings.TrimSuffix(name, Base64Suffix)
194 unescapedName := model.UnescapeName(trimmedName, EscapingScheme)
195 if !ValidationScheme.IsValidLabelName(unescapedName) ||
196 strings.HasPrefix(trimmedName, model.ReservedLabelPrefix) {
197 return nil, fmt.Errorf("improper label name %q", trimmedName)
198 }
199 if name == trimmedName {
200 result[unescapedName] = value
201 continue
202 }
203 decodedValue, err := decodeBase64(value)
204 if err != nil {
205 return nil, fmt.Errorf("invalid base64 encoding for label %s=%q: %v", trimmedName, value, err)
206 }
207 result[unescapedName] = decodedValue
208 }
209 return result, nil
210}

Callers 4

PushFunction · 0.85
DeleteFunction · 0.85
TestSplitLabelsFunction · 0.85
TestSplitLabelsUTF8Function · 0.85

Calls 1

decodeBase64Function · 0.85

Tested by 2

TestSplitLabelsFunction · 0.68
TestSplitLabelsUTF8Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…