diff --git a/docs/sources/datasources/influxdb/_index.md b/docs/sources/datasources/influxdb/_index.md index 5a11458f3be..83187fe2b27 100644 --- a/docs/sources/datasources/influxdb/_index.md +++ b/docs/sources/datasources/influxdb/_index.md @@ -120,6 +120,7 @@ You can switch to raw query mode by clicking hamburger icon and then `Switch edi - $m = replaced with measurement name - $measurement = replaced with measurement name +- $1 - $9 = replaced with part of measurement name (if you separate your measurement name with dots) - $col = replaced with column name - $tag_exampletag = replaced with the value of the `exampletag` tag. The syntax is `$tag*yourTagName`(must start with`$tag*`). To use your tag as an alias in the ALIAS BY field then the tag must be used to group by in the query. - You can also use [[tag_hostname]] pattern replacement syntax. For example, in the ALIAS BY field using this text `Host: [[tag_hostname]]` would substitute in the `hostname` tag value for each legend value and an example legend value would be: `Host: server1`. diff --git a/pkg/tsdb/influxdb/response_parser.go b/pkg/tsdb/influxdb/response_parser.go index d0dfdaa2e8a..7681be63e63 100644 --- a/pkg/tsdb/influxdb/response_parser.go +++ b/pkg/tsdb/influxdb/response_parser.go @@ -113,7 +113,7 @@ func formatFrameName(row Row, column string, query *Query) string { } pos, err := strconv.Atoi(aliasFormat) - if err == nil && len(nameSegment) >= pos { + if err == nil && len(nameSegment) > pos { return []byte(nameSegment[pos]) } diff --git a/pkg/tsdb/influxdb/response_parser_test.go b/pkg/tsdb/influxdb/response_parser_test.go index 5ad6f546846..c488bf2c7d4 100644 --- a/pkg/tsdb/influxdb/response_parser_test.go +++ b/pkg/tsdb/influxdb/response_parser_test.go @@ -293,6 +293,16 @@ func TestInfluxdbResponseParser(t *testing.T) { t.Errorf("Result mismatch (-want +got):\n%s", diff) } + query = &Query{Alias: "alias $0 $1 $2 $3 $4"} + result = parser.Parse(prepare(response), query) + frame = result.Responses["A"] + name = "alias cpu upc $2 $3 $4" + testFrame.Name = name + testFrame.Fields[1].Config.DisplayNameFromDS = name + if diff := cmp.Diff(testFrame, frame.Frames[0], data.FrameTestCompareOptions()...); diff != "" { + t.Errorf("Result mismatch (-want +got):\n%s", diff) + } + query = &Query{Alias: "alias $1"} result = parser.Parse(prepare(response), query) frame = result.Responses["A"]