API removing brackets from flux - breaking operator precedence

Hi everyone,

I am having an issue with the checks API in InfluxDb OSS 2.5.1. I am trying to make a builder in javascript that converts users’ UI inputs into flux that I send to the checks API to create a check. The users will be able to specify complex thresholds that need to support operator precedence. Currently, I am generating the following flux.

...
crit = (r) => ((r["f1"] >= 22 and r["f2"] >= 40) or (r["f1"] <= 0 and r["f2"] <= 10) or r["f3"] == 0)
...

When I send it to the checks API it seems to remove the brackets, meaning that the ‘and’ and ‘or’ operators won’t work together. Is there something I can do about this?

crit = (r) =>
    r["f1"] >= 22
        and
        r["f2"] >= 40
        or
        r["f1"] <= 0
            and
            r["f2"] <= 10
        or
        r["f3"] == 0

Cheers,
Moses

Hello @Moses_Wescombe,
Hmm I’m not sure. But perhaps as a workaround you can conditionally transform the levels and then alert on those levels where the levels meet your conditions?

@scott have you seen this?

@Moses_Wescombe Ah, yes. I have seen this before. It’s a bug with the Flux formatter (Order of operations or formatting problem · Issue #5298 · influxdata/flux · GitHub). I thought it had been fixed, but I guess not. You may be able to get around it with something like this:

crit = (r) => {
    cond1 = r["f1"] >= 22 and r["f2"] >= 40
    cond2 = r["f1"] <= 0 and r["f2"] <= 10
    cond3 = r["f3"] == 0

    return cond1 or cond2 or cond3
}

Awesome, thank you. I temporarily changed it to work with variables as you mention @scott. This should work fine for our needs.

Cheers,
Moses