1

In Grafana I added an Exclude parameter to the Dashboard. If the Exclude field is empty, I would want it to do nothing, otherwise exclude lines that contain the regex in Exclude field.

I would want to write something like:

{label="this"} ( if "$Exclude" != "" then !~ "$Exclude" else <do nothing> fi )

How could I write this in LogQL? I tried reading documentation, but to no avail. Currently, I just set the default value of Exclude to a unique UUID, however would be nice for it to be empty.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111

1 Answers1

2

You can try something like this:

{k8s_container_name="SOME_CONTAINER_NAME"} |
label_format custom_label =  `
{{ if contains "GET" .httpMethod}} GET URL
{{ else if contains "POST" .httpMethod}} POST URL {{end}}`
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • This does not allow applying `!~` operators conditionally. This does allow however to do ```|~ `{{ if $Exclude" == "" }}a very unique string that is never in input{{ else }}$Exclude{{ end }}` ``` – KamilCuk Apr 06 '23 at 11:15