In azure workbook, how to handle an unset parameter so that it doesnt lead to syntax errors in subsequent query in the dasboard

Anjali Gobari 0 Reputation points
2025-01-02T11:55:11.26+00:00

The query for displaying the table in azure workbook works fine if a parameter {ServiceName} is set, however it displays an error if the parameter is unset (because of dependency on another parameter value which doesn't fetch data) and passed as an empty value. the query throws a syntax error

"Query could not be parsed at ')' on line [10,22] Token: ')' Line: 10 Postion: 22"

, please suggest a way in which the empty/unset parameter can be handled and a default message can be displayed instead of an error

let endDateTime = {timeRange:end};
let startDateTime = {timeRange:start};
KubeEvents
| where TimeGenerated >= startDateTime
| where TimeGenerated < endDateTime
|extend ServiceName = split(Name, "-")[0]
|where ServiceName in ({ServiceName})
|extend PodName=Name
|where Namespace in ({Namespace})
|where ObjectKind in ('Pod')
|project TimeGenerated, ObjectKind,Namespace,ClusterName, ServiceName,PodName, Reason,Message,FirstSeen,LastSeen,Count
| summarize arg_max(TimeGenerated, *) by PodName
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,402 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 25,326 Reputation points MVP
    2025-01-03T08:36:35.53+00:00

    Hi, Basically you can use KQL to check if the parameter is empty or not and have different condition based on that. I do not have the full details of your workbook nor your data from Log Analytics but the query should look something like the one below where only one line is modified. You may need some small editing if it does not work right away in your case.

    let endDateTime = {timeRange:end};
    let startDateTime = {timeRange:start};
    KubeEvents
    | where TimeGenerated >= startDateTime
    | where TimeGenerated < endDateTime
    |extend ServiceName = split(Name, "-")[0]
    | where isempty('{ServiceName}') or (ServiceName in ('{ServiceName}'))
    |extend PodName=Name
    |where Namespace in ({Namespace})
    |where ObjectKind in ('Pod')
    |project TimeGenerated, ObjectKind,Namespace,ClusterName, ServiceName,PodName, Reason,Message,FirstSeen,LastSeen,Count
    | summarize arg_max(TimeGenerated, *) by PodName
    

    Update Option 2:

    Make the parameter required.

    On the section for your query Configure advanced settings by checking Make this item conditionally visible with the name of the parameter (Test1 in the screenshot) is not equal to empty value.

    User's image

    Add another section of type Text. Set text style to Error and enter the message you want to appear: User's image

    Configure advanced settings and check make this item conditionally visible with the name of the parameter (Test1 in the screenshot) equals to empty value.

    User's image

    That way you will have one section displaying error when the parameter is not configured and another one when it is configured.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.