chronograf icon indicating copy to clipboard operation
chronograf copied to clipboard

Warn user about using GROUP BY with graph type of SingleStat or Line+Stat

Open jaredscheib opened this issue 9 years ago • 5 comments

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.

jaredscheib avatar May 17 '17 00:05 jaredscheib

I wonder if this might be resolved by #1530.

EDIT: nope, it's not.

jaredscheib avatar May 23 '17 00:05 jaredscheib

Upon inspection, this appears to be happening under two circumstances:

  1. The last item of the array of time series data returned by proxy and passed into <SingleStat> is sometimes null (or whatever value is passed in via the optional InfluxQL fill function), even though all preceding values are not 0. Thus, when a SingleStat displays the lastValue of a time series, it displays 0 because a lastValue of null passed into const roundedValue = Math.round(+lastValue * precision) / precision yields 0. Maybe this is a windowing issue in InfluxQL?
    • a last value of null seems to happen only sometimes, and for any query
  2. There are no results in the array of time series data returned by proxy, and thus roundedValue is 0.
    • this can be generated via any valid query that returns no results

jaredscheib avatar May 24 '17 01:05 jaredscheib

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)

jaredscheib avatar May 24 '17 20:05 jaredscheib

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.

jaredscheib avatar May 24 '17 20:05 jaredscheib

Fixed by #1881

nhaugo avatar Aug 23 '17 16:08 nhaugo