What’s looks like a simple math (A+B) is not so simple.
Start simple math:
10 (result from query A)
+
10 (result from query B)
=
20 (expected result from math expression $A+$B)
Actually, result from query is timeseries (see query config Format as: Time series
) - there is list of values and each value represent some value in time, so it can be:
10 (result from query A at 2024-01-01 00:00:00)
+
10 (result from query B at 2024-01-01 00:00:00)
=
20 (expected result from math expression $A+$B at 2024-01-01 00:00:00)
But what if those values are from different times - what should be result of math expression - I would say this is undefined behaviour, because it is not possible to do a math:
10 (result from query A at 2023-01-01 00:00:00)
+
10 (result from query B at 2024-01-01 00:00:00)
=
???
There is link to Grafana doc, which is good to read:
With binary operations, such as
$A + $B
or$A || $B
, the operator is applied in the following ways depending on the type of data:If both
$A
and$B
are time series data, then the operation between each value in the two series is performed for each time stamp that exists in both$A
and$B
. The Resample operation can be used to line up time stamps. (Note: in the future, we plan to add options to the Math operation for different behaviors).
I highlight it: If both $A
and $B
are time series data, then the operation between each value in the two series is performed for each time stamp that exists in both $A
and $B
.
Editor has feature Table view
feature:
Use it and inspect/debug time series for each query and make sure you have values with right time stamps, when you want to perform math.
But I would say just don’t generate time series and it will be simple math as you expect.