Binary operation field summing when one field is null

  • What Grafana version and what operating system are you using?
    OS: Windows
    Grafana Version: 11.2
  • What are you trying to achieve?
    Display a failure rate graph superimposed on a total logs graph. Failure rate is success logs / (success + failure logs); total logs is (success + failure)
  • How are you trying to achieve it?
    Extract success / failure into a field with the following (range, not instant) query:
    sum by(result) (count_over_time({application_acronym="moveau", environment="training"} |= `Logging end of task` != `No xfers` | regexp `Logging end of task (?P<taskName>.*): (?P<result>.*)\r` [$__auto]))

Transform:
Binary operation: {Result=“Failure”} + {Result=“Success”}, alias Total
Graph properties: Replace nulls with 0’s.

  • What happened?
    The graph of failures and successes is smooth. However, the failure rate and total throughput (defined with the binary operation transform) have gaps unless both the successes and failures have a point at that timestamp.

  • What did you expect to happen?
    Nulls replaced with 0s and the calculations to proceed, displaying a 0 error rate and throughput if there were no values.

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

try an add field from calculation transformation, and multiply your field by 0, these will convert the nulls to 0’s…

How do I conditionally multiply them by 0 only if they’re null? If I multiply them by 0 then my total and failurerate would always be 0 :).

On a side note, if I just set up a binary operation where operation is:
{ result=“Failure”} * 0 => alias f
that graph itself only shows dots where the value was non-null. So that’s a simpler repo than doing the math.

1 Like

sorry I meant add 0, not multiply zero

Ah, I should’ve known what you meant…but same thing is multiplying. I only get points on the graph when there was data.

Query: Type Range:
sum by(result) (count_over_time({mylabels} |= {myquery} | regexp Logging end of task (?P<taskName>.*): (?P<result>.*)\r [$__auto]))

It’s still not working, but I did get two suggestions on the grafana slack channel from the AI bot that there was a transform available to convert field type to number. So I first converted labels to fields with a transform and did that. Now I only get gaps where data on the initial success / failure count seem to be both missing (but there shouldn’t be gaps with multiple places showing that nulls are 0.

New attempt:

Result:

AI bot also gave a suggestion to use a reduce expression to eliminate the non-nulls at the source, but I couldn’t figure out how to hook it up properly. When trying this I didn’t get any total or failure rate, just successes and failures (but it did seem to put a 0 in one of the points where failure was missing above.

Any other suggestions?