grafana-loki

Grafana Loki QL how to create nested IF statements?


I am new to Grafana and Loki and have a scenario where I need to do a calculation based on conditional scenarios in Loki QL. the scenario goes like this:

if (take each digit in number and multiply by 2 and if it is greater than 10 then use first digit else keep it as is as it would be a single digit ) eq 0 then show the details in the Grafana dashboard.

I am not able to put up the if condition inside the if condition (nested-if). I was looking something like this but it isnt working :

| line_format `{{if eq {{if eq (div (mul (.somelabel | substr 0 1) 2) 10) 1}}{{(mul (.somelabel | substr 0 1) 2)}}{{else}}(.somelabel | substr 0 1){{end}}) 0}}{{.somelabel}}{{end}}

cant think of any alternate way! Thanks !!!


Solution

  • I finally got the answer. We may use label_filter to create a variable for one of the if condition and then use it in other if condition.