0

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?

3
  • Syntax you've been using is a syntax for including dashboard variables into queries. I'm not sure if you can use environment variables in Grafana queries. Commented Feb 2, 2024 at 16:08
  • @markalex But if we look at the docs, it should be used the same way for Azure Monitor queries: grafana.com/docs/grafana/latest/datasources/azure-monitor/… Commented Feb 2, 2024 at 20:48
  • 1
    Nothing at provided documentation seems to be about environment variables. Commented Feb 3, 2024 at 2:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.