MCPcopy
hub / github.com/google/mtail / formatLabels

Function formatLabels

internal/exporter/export.go:161–178  ·  view source on GitHub ↗

formatLabels converts a metric name and key-value map of labels to a single string for exporting to the correct output format for each export target. ksep and sep mark what to use for key/val separator, and between label separators respoectively. If not empty, rep is used to replace cases of ksep an

(name string, m map[string]string, ksep, sep, rep string)

Source from the content-addressed store, hash-verified

159// ksep and sep mark what to use for key/val separator, and between label separators respoectively.
160// If not empty, rep is used to replace cases of ksep and sep in the original strings.
161func formatLabels(name string, m map[string]string, ksep, sep, rep string) string {
162 r := name
163 if len(m) > 0 {
164 var keys []string
165 for k := range m {
166 keys = append(keys, k)
167 }
168 sort.Strings(keys)
169 var s []string
170 for _, k := range keys {
171 k1 := strings.ReplaceAll(strings.ReplaceAll(k, ksep, rep), sep, rep)
172 v1 := strings.ReplaceAll(strings.ReplaceAll(m[k], ksep, rep), sep, rep)
173 s = append(s, fmt.Sprintf("%s%s%s", k1, ksep, v1))
174 }
175 return r + sep + strings.Join(s, sep)
176 }
177 return r
178}
179
180// Format a LabelSet into a string to be written to one of the timeseries
181// sockets.

Callers 3

metricToStatsdFunction · 0.85
metricToCollectdFunction · 0.85
metricToGraphiteFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected