My Grafana instance is deployed to an aks cluster. Within the deployment, I configured an environment variable LAW_ENVIRONMENT that is basically just specifying which environment will be looked at inside the queries. For example, LAW_ENVIRONMENT can have the value "dev". The query I am trying to configure is the following:
ContainerLogV2
| where TimeGenerated > ago(1d)
| join kind=leftouter (KubePodInventory
| project ContainerID, PodLabel, ClusterName
) on $left.ContainerId == $right.ContainerID
| extend PodLabelJson = parse_json(PodLabel)
| extend AppName = tostring(PodLabelJson[0]["app.kubernetes.io/name"])
| where ClusterName contains "$LAW_ENVIRONMENT"
| where LogMessage contains "\"level\":\"SEVERE\"" or LogMessage contains "error" or LogMessage contains "exception"
If I write the following instead of line 8, I get results:
| where ClusterName contains "dev"
But when I use the environment variable I get no data returned. It looks like that the environment variable isn't even being read when the query is being sent to the Azure Monitor Datasource, which is the Log Analytics Workspace. I also tried the following syntax which can be found in the documentation: ${LAW_ENVIRONMENT}, but that also doesn't work. I took a look inside the pod where the Grafana container is running and I made sure that the environment variable exists and that it has the correct value. Is there any way to make use of the environment variable or will I have to duplicate my code for every environment or use the "sed" command while deploying it?