Opentsdb: Add tag values into the opentsdb response (#48672)

Adds tags to the opentsdb response. This means the tags propagate to alert messages to quickly understand the source of the alert.

Fixes: https://github.com/grafana/grafana/issues/47092

Co-authored-by: SLAMA <36870081+xy-man@users.noreply.github.com>
This commit is contained in:
SLAMA
2022-06-20 11:12:43 +09:00
committed by GitHub
parent bd30e85031
commit 81b5ecac34
3 changed files with 8 additions and 2 deletions
+2 -1
View File
@@ -157,6 +157,7 @@ func (s *Service) parseResponse(res *http.Response) (*backend.QueryDataResponse,
timeVector := make([]time.Time, 0, len(val.DataPoints))
values := make([]float64, 0, len(val.DataPoints))
name := val.Metric
tags := val.Tags
for timeString, value := range val.DataPoints {
timestamp, err := strconv.ParseInt(timeString, 10, 64)
@@ -169,7 +170,7 @@ func (s *Service) parseResponse(res *http.Response) (*backend.QueryDataResponse,
}
frames = append(frames, data.NewFrame(name,
data.NewField("time", nil, timeVector),
data.NewField("value", nil, values)))
data.NewField("value", tags, values)))
}
result := resp.Responses["A"]
result.Frames = frames
+5 -1
View File
@@ -49,6 +49,10 @@ func TestOpenTsdbExecutor(t *testing.T) {
"metric": "test",
"dps": {
"1405544146": 50.0
},
"tags" : {
"env": "prod",
"app": "grafana"
}
}
]`
@@ -57,7 +61,7 @@ func TestOpenTsdbExecutor(t *testing.T) {
data.NewField("time", nil, []time.Time{
time.Date(2014, 7, 16, 20, 55, 46, 0, time.UTC),
}),
data.NewField("value", nil, []float64{
data.NewField("value", map[string]string{"env": "prod", "app": "grafana"}, []float64{
50}),
)
+1
View File
@@ -8,5 +8,6 @@ type OpenTsdbQuery struct {
type OpenTsdbResponse struct {
Metric string `json:"metric"`
Tags map[string]string `json:"tags"`
DataPoints map[string]float64 `json:"dps"`
}