influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

[0.10.0] Unexpected behavior for CQs with EVERY

Open rkuchan opened this issue 10 years ago • 3 comments

Unexpectedly, when I just include EVERY in the RESAMPLE clause the CQ doesn't seem to run:

CREATE CONTINUOUS QUERY eight ON telegraf RESAMPLE EVERY 4m BEGIN SELECT count(value) INTO telegraf."default".eight FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' GROUP BY time(2m) END

As expected, when I just include FOR in the RESAMPLE clause the CQ runs every two minutes and has four queries per run:

CREATE CONTINUOUS QUERY seventh ON telegraf RESAMPLE FOR 8m BEGIN SELECT count(value) INTO telegraf."default".seventh FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' GROUP BY time(2m) END

When I add EVERY 4m to the CQ above, I expected it to run every four minutes and have four queries per run:

CREATE CONTINUOUS QUERY fifth ON telegraf RESAMPLE EVERY 4m FOR 8m BEGIN SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' GROUP BY time(2m) END

Logs:

[continuous_querier] 2016/01/06 09:44:00 executing continuous query fifth (2016-01-06 09:40:00 -0800 PST to 2016-01-06 09:42:00 -0800 PST)
[query] 2016/01/06 09:44:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:40:00Z' AND time < '2016-01-06T17:42:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:44:00 executing continuous query fifth (2016-01-06 09:38:00 -0800 PST to 2016-01-06 09:40:00 -0800 PST)
[query] 2016/01/06 09:44:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:38:00Z' AND time < '2016-01-06T17:40:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:44:00 executing continuous query fifth (2016-01-06 09:36:00 -0800 PST to 2016-01-06 09:38:00 -0800 PST)
[query] 2016/01/06 09:44:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:36:00Z' AND time < '2016-01-06T17:38:00Z' GROUP BY time(2m)

[continuous_querier] 2016/01/06 09:48:00 executing continuous query fifth (2016-01-06 09:44:00 -0800 PST to 2016-01-06 09:46:00 -0800 PST)
[query] 2016/01/06 09:48:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:44:00Z' AND time < '2016-01-06T17:46:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:48:00 executing continuous query fifth (2016-01-06 09:42:00 -0800 PST to 2016-01-06 09:44:00 -0800 PST)
[query] 2016/01/06 09:48:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:42:00Z' AND time < '2016-01-06T17:44:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:48:00 executing continuous query fifth (2016-01-06 09:40:00 -0800 PST to 2016-01-06 09:42:00 -0800 PST)
[query] 2016/01/06 09:48:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:40:00Z' AND time < '2016-01-06T17:42:00Z' GROUP BY time(2m)


[continuous_querier] 2016/01/06 09:52:00 executing continuous query fifth (2016-01-06 09:48:00 -0800 PST to 2016-01-06 09:50:00 -0800 PST)
[query] 2016/01/06 09:52:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:48:00Z' AND time < '2016-01-06T17:50:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:52:00 executing continuous query fifth (2016-01-06 09:46:00 -0800 PST to 2016-01-06 09:48:00 -0800 PST)
[query] 2016/01/06 09:52:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:46:00Z' AND time < '2016-01-06T17:48:00Z' GROUP BY time(2m)
[continuous_querier] 2016/01/06 09:52:00 executing continuous query fifth (2016-01-06 09:44:00 -0800 PST to 2016-01-06 09:46:00 -0800 PST)
[query] 2016/01/06 09:52:00 SELECT count(value) INTO telegraf."default".fifth FROM telegraf."default".cpu_usage_idle WHERE cpu = 'cpu-total' AND time >= '2016-01-06T17:44:00Z' AND time < '2016-01-06T17:46:00Z' GROUP BY time(2m)

The CQ runs every four minutes, but I only see three queries per run. Focusing on the first run, the CQ runs at 17:44:00 and executes three queries for the following time ranges:

time >= '2016-01-06T17:40:00Z' AND time < '2016-01-06T17:42:00Z'
time >= '2016-01-06T17:38:00Z' AND time < '2016-01-06T17:40:00Z'
time >= '2016-01-06T17:36:00Z' AND time < '2016-01-06T17:38:00Z'

I'd expect to see one more query with the time range time >= '2016-01-06T17:42:00Z' AND time < '2016-01-06T17:44:00Z'.

rkuchan avatar Jan 06 '16 19:01 rkuchan

@rkuchan is this being run against the beta1?

I also noticed that the interval for your continuous query is 2 minutes, but you use the every clause for 4 minutes. I haven't taken a look yet, but EVERY is usually supposed to be less than the GROUP BY interval. It's just hard to return errors in the current incarnation of the code so it doesn't do that error checking yet.

What's the intention of setting EVERY to a higher value than the GROUP BY interval? Is it so the continuous queries run less often? I'll start taking a look for the exact reason why this is happening, but knowing more about your workflow helps to make sure that I get this right.

jsternberg avatar Jan 15 '16 16:01 jsternberg

Submitted a PR to fix this behavior. The expected behavior for each of the continuous queries listed:

  1. Should perform two queries every 4 minutes. If run at 12:04 PM, it would run queries from 12:00PM-12:02PM and 12:02PM-12:04PM.
  2. 4 queries every 2 minutes (same as before).
  3. 4 queries every 4 minutes.

jsternberg avatar Jan 15 '16 19:01 jsternberg

@jsternberg, I didn't really have a workflow planned out. That was just one of the first cqs I created when I was putting together the documentation.

rkuchan avatar Jan 16 '16 00:01 rkuchan