InfluxDB: fix numeric aliases in queries (#41531)

* influxdb: alerting: handle out-of-range numeric aliases

* influxdb: updated documentation
This commit is contained in:
Gábor Farkas 2021-11-11 09:18:06 +01:00 committed by GitHub
parent dbe78e47b1
commit eb47a58029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -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`.

View File

@ -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])
}

View File

@ -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"]