0
votes

I am trying to use the following query fragment to allow for variable regex filter inputs.

| where isempty("[[HttpStatusCode]]") or tostring(httpStatus_d) matches regex "[[HttpStatusCode]]"

The query is being executed in Azure Log Analytics from within Grafana. I have variables on the Grafana dashboard that allow the user to input a regex expression that feeds into the query. When the filter is empty, I expect no filtering to be applied. I was thinking the Kusto queries may support short-circuiting and when isempty(..) evaluated as true, then the remainder of the expression would be ignored and the matches regex portion would not execute nor throw an error.

The error message I get when the string is empty is "Relop semantic error: 'matches regex' has the following semantic error: SEM0031: matches regex: argument 2 must be a constant non empty string value."

1

1 Answers

1
votes

Kusto does not have the short-circuit feature. But you can try the workaround below.

First, you need to check if [[HttpStatusCode]] is empty or not. If it's empty, you can assign a dummy value to it(Note, please make sure the dummy value cannot be matched by matches regex operator in the where cluase). As a result, it will not throw any error when input an empty value.

Sample query:

table_name 
| extend tempvalue= iff(isempty("[[HttpStatusCode]]"),"a dummy value","[[HttpStatusCode]]")
| where isempty("[[HttpStatusCode]]") or tostring(httpStatus_d) matches regex tempvalue