Hi I am trying to do a simple success rate calculation between metrics. By dividing the number of successful requests by the number of attempts. The problem is some intervals are empty where both metrics are 0. When I write the query I get the below “cannot divide by zero” runtime error. In SQL there a NULLIF
function to avoid this. Is there something similar in flux or is there an alternate method to avoid division by zero?
Error: runtime error @7:6-7:90: map: failed to evaluate map function: cannot divide by zero
My Sample Query:
from(bucket: "my_db")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "HTTPRequests")
|> filter(fn: (r) => r["_field"] == "RequestAttempt" or r["_field"] == "RequestSuccess_E")
|> filter(fn: (r) => r["host"] == "host-a")
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({ r with Request_SR: r.RequestSuccess_E/r.RequestAttempt }))
Thanks in advance.