Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfluxDB: Fix corner case where index is too large in ALIAS field #41562

Merged
merged 1 commit into from
Nov 11, 2021

Conversation

gabor
Copy link
Contributor

@gabor gabor commented Nov 10, 2021

in InfluxDB, when you have a query like this:
SELECT value from "computer.cpu", when the result is drawn on the screen, the time-series will be named "computer.cpu".
you can change this by using the ALIAS field in the query, there are many formats supported by the ALIAS field, but there is one where you use numbers, like $0 or [[1]]. in this case the following will happen:

  • we take the measurement name (in this case computer.cpu)
  • split it into parts by the dot-character, so we get the array ["computer","cpu"]
  • and then use the item from the array at the index specified by the alias (so, in our case, if you use the alias AL $1, the timeseries-name will be AL cpu

there is a problem, if you specify an index that is higher than the length of the array, the series will be named undefined. for example, if your measurement is named computer.cpu and you use the alias AL $7, the series will be named AL undefined.

this pull request changes this so that the series name will become AL $7 in this case. this is consistent with how it happens in the influxdb-alerting-go-code, and also consistent with the approach that when we have a variable that does not exist, we just keep the original text.

how to test:
you need to have measurement with names that contain periods. the simplest way is to manually insert such values into influxdb:

  • make devenv sources=influxdb
  • run docker ps, and find the ID of the influxdb container.
  • run docker exec -it <docker_container_id> influx write -b mybucket -o myorg -t mytoken 'name.with.dots v=40'
  • now go to explore-mode, choose the datasource gdev-influxdb-influxql, and choose the measurement "name.with.dots", choose the field "v", and try out ALIAS values.

@gabor gabor requested review from aocenas, Elfo404 and a team and removed request for a team November 10, 2021 17:10
@gabor gabor added this to the 8.3.0 milestone Nov 10, 2021
Copy link
Contributor

@Elfo404 Elfo404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

do we want to add type/bug and add to changelog labels?

@gabor gabor changed the title InfluxDB: alias: handle corner case where index is too large InfluxDB: alias: fix corner case where index is too large Nov 11, 2021
@gabor gabor merged commit 4f46201 into main Nov 11, 2021
@gabor gabor deleted the gabor/influxdb-alias-no-undef branch November 11, 2021 13:38
@dprokop dprokop changed the title InfluxDB: alias: fix corner case where index is too large InfluxDB: Fix corner case where index is too large in ALIAS field Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants