Reputation: 361
Here alerts_enabled is a variable that has 1. If it is 1 then it should be run, if it has 0 then not. I am trying to achieve it this way but it is not working.
- alert: log_requests_missing
expr: sum(increase(log_request_duration_seconds_count[1m])) == 0 and [[alerts_enabled]]
for: 8m
labels:
severity: warning
annotations:
summary: 'test'
description: 'Test description'
Can someone please help me to fix it? What is wrong I am doing here?
Upvotes: 1
Views: 2848
Reputation: 2365
Prometheus alert are raised when the expr
produced at least one values.
using the and
operator is the right approach, you just need a virtual metric that has the value of your variable. That can be done with vector()
:
expr: sum(increase(log_request_duration_seconds_count[1m])) == 0 and vector([[alerts_enabled]]) == 1
That would solve your problem, but I doubt that is the best way to disable alerts. Since you are usint prometheus operator you could simply disabling your alerts by deleting the Kubernetes resource that defines this alerts. This would remove the second half of the expression, which makes it more readable and the Promehteus server has less to execute in order to evaluate the expression.
Upvotes: 2