InfluxDB: Flux - Create an Array Variable and use this to filter
What I want
I have a measurement "MY_ASSET_MEASUREMENT" with some asset information about VMs and I have a second measurement "MY_METRIC_MEASUREMENT" that have the metric data about the VMs.
I want to show only the metric data of one customer. Because I have no customer data in the measurement "MY_METRIC_MEASUREMENT" I have to create an array of the VM names from measurement "MY_ASSET_MEASUREMENT" and use this to filter the measurement "MY_METRIC_MEASUREMENT".
-> This would be alot easier if I create a Grafana template variable. But Grafana template variables is limited to 1000 items and I have more then 1000 VMs. That's why I can't use Grafana's template variable for this.
//define variables bucket = "<YOUR_BUCKET>" vms = from(bucket: bucket) |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == "<MY_ASSET_MEASUREMENT>" and r.customer == "<MY_CUSTOMER>" ) |> keep(columns: ["vmname"]) |> group() |> distinct(column: "vmname") |> findColumn(fn: (key) => true, column: "_value") from(bucket: bucket) |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._measurement == "<MY_METRIC_MEASUREMENT>" and r._field == "<MY_FIELD>" ) |> highestAverage(n:10000, column: "_value", groupColumns: ["VMName"]) |> filter(fn: (r) => contains(value: r.VMName, set: vms)) |> keep(columns: ["VMName", "_value"])
An internal error has occurred
If you get An internal error has occurred then you maybe forgot findColumn() at the end of the array:
|> findColumn(fn: (key) => true, column: "_value")
-> You only can use the contains() |> filter(fn: (r) => contains(value: r.VMName, set: vms)) function with findColumn().