Correction:

*I suspect that*
*foo and on() bar or baz*
*will be parsed as*
*(foo and on() bar) or baz*
*which is not what you require.*

On Thursday, 5 August 2021 at 09:34:22 UTC+1 Brian Candler wrote:

> Please don't just say "it doesn't work".  Say what happened.  Did you see 
> an error message?  Did the alert fire when you were not expecting it, or 
> not fire when you were expecting it?
>
> Adding "if: ..." to an alerting rule shouldn't work - I cannot see that 
> syntax anywhere in the documentation 
> <https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/>.
>   
> You need to put the logic into the expr: and you can debug your expr using 
> the prometheus query GUI (*).
>
> Adding parentheses might help.  I suspect that
> foo and on() bar or baz
> will be parsed as
> (foo and (on() bar)) or baz
> which is not what you require.
>
> Because you're using on() I think you're already aware that "and", "or" 
> and "==" don't work the way that newcomers expect.  To summarize:
>
> Comparison operators 
> <https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators>
> foo : is a set of timeseries.
> foo{bar="baz"} : is the same set of timeseries, filtered down to only 
> those with label bar="baz".
> foo{bar="baz"} == 1 : is the same set of timeseries, filtered down to only 
> those with label bar="baz" and whose value is 1.
>
> Logical operators 
> <https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators>
> foo and bar : is the set of timeseries from foo, filtered to only those 
> where bar exists with the exact same set of labels (but any value). Given 
> that *day_of_week() == 6* is a scalar value (6) it has no labels.
>
> (*) You can test your expression in the PromQL browser like this: try 
> selecting the graph view and scrolling out so you display 2 weeks.
>
> up == 1  # ok
> up == 1 and day_of_week() == 4  # no results
> up == 1 and on() day_of_week() == 4  # works
> up == 1 and on () day_of_week() == 4 or day_of_week() == 5  # unexpected: 
> gives value 1 or value 5
> up == 1 and on () (day_of_week() == 4 or day_of_week() == 5)  # correct
>
> I think this confirms that your problem is lack of parentheses.
>
> On Thursday, 5 August 2021 at 05:22:47 UTC+1 [email protected] wrote:
>
>> Hello All,
>>
>> I want to set up an alert monitoring for a job/service which is running 
>> only on weekends.
>> Alerts should trigger during weekend if the service is not running or 
>> goes down.
>>
>> Tried with below query (just for testing, in actual query value would be 
>> 0). PFA
>>
>> *d********_status{job="targets",name="d*-*******ise-*****re-coord"} == 1 
>> and on() day_of_week() == 6 or day_of_week() == 0* 
>>
>> Also in alert rules applied if condition
>>       - alert: "[EMR]: Java coordinator is down"
>>         *if: day_of_week() == 0 OR day_of_week() == 6*
>>
>> But neither of them working*.*
>>
>> Thanks,
>> Kishore
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/8209afab-919a-4434-9e37-a69e14b6d9bfn%40googlegroups.com.

Reply via email to