grafana / influxdb-flux-datasource

Grafana datasource plugin for Flux (InfluxDB)
Apache License 2.0
51 stars 21 forks source link

Range, Interval and variable interpolation aren't supported anymore #106

Closed alex88 closed 4 years ago

alex88 commented 4 years ago

After upgrading to grafana 7 and plugin version 7 our queries:

import "regexp"

from(bucket: "my-bucket")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "metric" ... other conditions
  )
  |> aggregateWindow(every: $__interval, fn: mean)

don't work anymore because the $range and $__interval variables aren't replaced anymore so the query fails with:

invalid: compilation failed: loc 4:12-4:18: unexpected token for property key: ILLEGAL ("$")`

alex88 commented 4 years ago

I've also seen that before a condition like this:

regexp.matchRegexpString(r: /^($some_variable)$/, v: r._field)

where some_variable has multiple selections would be converted properly to a regex (e.g. (value1|value2) as per https://grafana.com/docs/grafana/latest/variables/templates-and-variables/#formatting-multiple-values) but now it just stays as {value1,value2} so the regex doesn't work anymore

alex88 commented 4 years ago

For anyone having the same issue the workaround is this:

import "regexp"

from(bucket: "my-bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) =>
    r._measurement == "metric"
    and r.machine == "$machine"
    and regexp.matchRegexpString(r: /^${variable_1:regex}$/, v: r._field)
  )
  |> aggregateWindow(every: v.windowPeriod, fn: mean)
srclosson commented 4 years ago

@alex88, Thanks for reporting this! Yes, this was intentional, although it makes sense to have things backward compatible, the idea was to be able to copy and paste from the influx query editor, and have the queries work.

Would you like to see the "$range" variable return? Or is the workaround you have found reasonable for your use case?

alex88 commented 4 years ago

@srclosson oh sorry I didn't know this was the intended direction, I've read about the fact that you can copy paste from the editor in the changelog and that's where I've found the workaround. Since the workaround works and I haven't found any other blocking issue I think there's no reason to support the old variables as long as it's documented and there is a proper way to handle the old use cases (e.g. the variable regex interpolation). I'll close this issue for now but if you think something still needs to be done please reopen it. Also I'd like to point out that the sample queries return some syntax errors