Skip to content

Commit 87650c1

Browse files
committed
feat(influxdb): add tags to serie names
1 parent b0addbd commit 87650c1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pkg/tsdb/influxdb/response_parser.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ func (rp *ResponseParser) parseResult(result []Row, queryResult *tsdb.QueryResul
4545
}
4646

4747
func (rp *ResponseParser) formatName(row Row, column string) string {
48-
return fmt.Sprintf("%s.%s", row.Name, column)
48+
tags := ""
49+
50+
for k, v := range row.Tags {
51+
tags += k + ": " + v
52+
}
53+
54+
if tags != "" {
55+
tags = fmt.Sprintf(" { %s }", tags)
56+
}
57+
58+
return fmt.Sprintf("%s.%s%s", row.Name, column, tags)
4959
}
5060

5161
func (rp *ResponseParser) parseTimepoint(k []interface{}, valuePosition int) tsdb.TimePoint {

pkg/tsdb/influxdb/response_parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func TestInfluxdbResponseParser(t *testing.T) {
5252
})
5353

5454
Convey("can format serie names", func() {
55-
So(result.Series[0].Name, ShouldEqual, "cpu.mean")
56-
So(result.Series[1].Name, ShouldEqual, "cpu.sum")
55+
So(result.Series[0].Name, ShouldEqual, "cpu.mean { datacenter: America }")
56+
So(result.Series[1].Name, ShouldEqual, "cpu.sum { datacenter: America }")
5757
})
5858
})
5959
}

0 commit comments

Comments
 (0)