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]))