code refactor

This commit is contained in:
Ulric Qin 2022-06-17 20:24:29 +08:00
parent cb3b4050a0
commit b20a87677b
1 changed files with 3 additions and 5 deletions

View File

@ -9,6 +9,8 @@ import (
"github.com/prometheus/prometheus/prompb"
)
var labelReplacer = strings.NewReplacer("-", "_", ".", "_", " ", "_", "/", "_")
func convert(item *types.Sample) *prompb.TimeSeries {
pt := &prompb.TimeSeries{}
@ -30,12 +32,8 @@ func convert(item *types.Sample) *prompb.TimeSeries {
// add other labels
for k, v := range item.Labels {
k = strings.Replace(k, "/", "_", -1)
k = strings.Replace(k, ".", "_", -1)
k = strings.Replace(k, "-", "_", -1)
k = strings.Replace(k, " ", "_", -1)
pt.Labels = append(pt.Labels, &prompb.Label{
Name: k,
Name: labelReplacer.Replace(k),
Value: v,
})
}