Graphite: Convert tag values returned as numbers to strings (#37882)

* Convert tag values returned as numbers to string

This is a bug in Graphite <= 1.1.7. Since 1.1.8 all values are converted to strings.

* Simplify type conversions

* Fix linting errors
This commit is contained in:
Piotr Jamróz
2021-08-19 08:40:13 -07:00
committed by GitHub
parent 76b891b001
commit f7501ff77f
3 changed files with 46 additions and 5 deletions
+13 -2
View File
@@ -10,6 +10,7 @@ import (
"net/url"
"path"
"regexp"
"strconv"
"strings"
"time"
@@ -248,15 +249,25 @@ func (s *Service) toDataFrames(response *http.Response) (frames data.Frames, err
values = append(values, value)
}
tags := make(map[string]string)
for name, value := range series.Tags {
switch value := value.(type) {
case string:
tags[name] = value
case float64:
tags[name] = strconv.FormatFloat(value, 'f', -1, 64)
}
}
frames = append(frames, data.NewFrame(name,
data.NewField("time", nil, timeVector),
data.NewField("value", series.Tags, values).SetConfig(&data.FieldConfig{DisplayNameFromDS: name})))
data.NewField("value", tags, values).SetConfig(&data.FieldConfig{DisplayNameFromDS: name})))
if setting.Env == setting.Dev {
s.logger.Debug("Graphite response", "target", series.Target, "datapoints", len(series.DataPoints))
}
}
return
return frames, nil
}
func (s *Service) createRequest(dsInfo *datasourceInfo, data url.Values) (*http.Request, error) {