英文:
How to write an IF in LogQL query?
问题
在Grafana中,我向仪表板添加了一个排除参数。如果排除字段为空,我希望它不执行任何操作,否则排除包含在排除字段中的正则表达式的行。
我想要编写类似以下的内容:
{label="this"} ( if "$Exclude" != "" then !~ "$Exclude" else <do nothing> fi )
我该如何在LogQL中编写这个?我尝试阅读文档,但没有成功。目前,我只是将排除的默认值设置为唯一的UUID,但希望它为空。
英文:
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.
答案1
得分: 2
{k8s_container_name="SOME_CONTAINER_NAME"} |
label_format custom_label = {{ if contains "GET" .httpMethod}} GET URL {{ else if contains "POST" .httpMethod}} POST URL {{end}}
英文:
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}}`
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论