grafana-json-datasource icon indicating copy to clipboard operation
grafana-json-datasource copied to clipboard

JSONata - Issue reading multiple Dashboard Variables

Open jan-deulofeu opened this issue 3 years ago • 3 comments

Hi,

We are having this a global variable (multi value variable), and we are not able to read the actual position of the variable. We are been forced to set the index of the array statically:

Panel Url request: http://localhost:3000/d/h5tWCggVz/app?orgId=1&var-cluster_zone=k8&var-environment_value=int&var-environment_value=nft&editview=templating

Multivalued variable-> environment_value with values (int, nft)

In the JSONata field we can only access to the the values using the array index ($environment_value[0] or $environment_value[1]). We should be able to access to the current value using ${environment_value} or $environment_value.

Do you have any suggestion about how to access to the actual parameter without the need to set the index in the array?

`( $searchEnvironment := function($cluster, $envirovement) {( $status := $lookup($.teamDashboards, $cluster).applications[*].environments[name = $envirovement]; )};

$r := $searchEnvironment($cluster_zone[0], $environment_value[0]).canaryStatus ; )`

Screenshot 2022-07-21 at 09 02 19

Quoting the documentation Dashboard variables are available as JSONata variables, e.g. $instanceName. Since dashboard variables can have multiple values, the JSONata variable is always an array. If your variable contains a single value, you can use $instanceName[0] to index the first value in the array.

Given Dashboards variables are an array, if we are using the variable in a Dashboard Row to loop over the values of a variables, how can we know which index of the array we are in? can we access to the actual iterator? or can we just use the actuakl value accessing to the variables (as in JsonPath) using the variable reference like: ${environment_value}

jan-deulofeu avatar Jul 21 '22 08:07 jan-deulofeu

I am also facing same issue.

ashishamway avatar Sep 29 '22 16:09 ashishamway

I put a comment with the same problem in another issue. However, this one is exactly my issue.

paulinaptf avatar Apr 26 '23 14:04 paulinaptf