mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
35 lines
791 B
Go
35 lines
791 B
Go
package datastoreprometheus
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
"github.com/hanzoai/o11y/pkg/prometheus"
|
|
"github.com/prometheus/prometheus/prompb"
|
|
)
|
|
|
|
// Unmarshals JSON into Prometheus labels. It does not preserve order.
|
|
func unmarshalLabels(s string, fingerprint uint64) ([]prompb.Label, string, error) {
|
|
var metricName string
|
|
m := make(map[string]string)
|
|
if err := json.Unmarshal([]byte(s), &m); err != nil {
|
|
return nil, metricName, err
|
|
}
|
|
res := make([]prompb.Label, 0, len(m))
|
|
for n, v := range m {
|
|
if n == "__name__" {
|
|
metricName = v
|
|
}
|
|
|
|
res = append(res, prompb.Label{
|
|
Name: n,
|
|
Value: v,
|
|
})
|
|
}
|
|
res = append(res, prompb.Label{
|
|
Name: prometheus.FingerprintAsPromLabelName,
|
|
Value: strconv.FormatUint(fingerprint, 10),
|
|
})
|
|
return res, metricName, nil
|
|
}
|