Warn user about using GROUP BY with graph type of SingleStat or Line+Stat
Sometimes a stat (from SingleStat or Line+Stat) will display a 0 temporarily, which can be very concerning. The problem has been diagnosed below as being related to using a GROUP BY in a query. As mentioned below, it would be good to provide a warning to the user via the Query Editor warning display when they're trying to use a GROUP BY with a SingleStat or Line+Stat, per the below.
I wonder if this might be resolved by #1530.
EDIT: nope, it's not.
Upon inspection, this appears to be happening under two circumstances:
- The last item of the array of time series data returned by
proxyand passed into<SingleStat>is sometimesnull(or whatever value is passed in via the optional InfluxQLfillfunction), even though all preceding values are not0. Thus, when aSingleStatdisplays thelastValueof a time series, it displays0because alastValueofnullpassed intoconst roundedValue = Math.round(+lastValue * precision) / precisionyields0. Maybe this is a windowing issue in InfluxQL?- a last value of
nullseems to happen only sometimes, and for any query
- a last value of
- There are no results in the array of time series data returned by
proxy, and thusroundedValueis0.- this can be generated via any valid query that returns no results
It turns out that the issue was in the InfluxQL queries. Solutions to avoid SingleStat from displaying a 0 "accidentally", due to a last value of null, are as follows. These solutions use the sample query SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > :dashboardTime: and cluster_id = :Cluster_Id: and host =~ /.data./ GROUP BY time(120s), which would cause SingleStat to display 0 sometimes due to returning a last value of null.
- use FILL(previous), ex:
SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > :dashboardTime: and cluster_id = :Cluster_Id: and host =~ /.data./ GROUP BY time(120s) FILL(previous)
- use FILL(none), ex:
SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > :dashboardTime: and cluster_id = :Cluster_Id: and host =~ /.data./ GROUP BY time(120s) FILL(none)
- use a subquery, ex. SELECT last("max") FROM (sample query), ex:
SELECT last("max") FROM (SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > :dashboardTime: and cluster_id = :Cluster_Id: and host =~ /.data./) GROUP BY time(120s))
- don't use a GROUP BY, and instead use :dashboardTime:, ex:
SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > :dashboardTime: and cluster_id = :Cluster_Id: and host =~ /.data./
- don't use a GROUP BY, and instead use the time interval as the WHERE:
SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > now() - 120s and cluster_id = :Cluster_Id: and host =~ /.data./
- dynamically calculate an offset (second argument passed to GROUP BY) and use an absolute time range to ensure that the number of buckets match the number of expected groups, so as to yield, ex:
SELECT max("total")/1073741824 FROM "telegraf"."default"."disk" WHERE time > "06:00:10" AND time < "06:15:10" and cluster_id = :Cluster_Id: and host =~ /.data./ GROUP BY time(1m,10s)
In the meantime, what would be excellent is to warn the user if they are trying to use a SingleStat or Line+Stat with a GROUP BY, so that they don't experience the same 0 result and panic that their cluster has crashed, or whatever other metrics they're watching have collapsed.
Fixed by #1881