InfluxDB问题汇总

最近在试用InfluxDB,遇到一些问题,这里汇总一下:

Continuous Query 时间偏移问题

背景

公司业务系统需要使用东八区的时间进行业务查询,所以最初保存influx point的时候,做了时间处理,后来因为需要对大量的数据进行重采样,自然而然想到CQ这个功能,遇到了这个time offset不生效的问题。

重现

假设已经生成性能日志表perflogtemp为所在数据库,构建如下的CQ:

1
2
3
4
5
6
CREATE CONTINUOUS QUERY cq_2m ON temp 
BEGIN
SELECT mean(rate) AS rate INTO temp.autogen.cq_2m
FROM temp.autogen.perflog
GROUP BY time(2m,8h) fill(0)
END

其中,GROUP BY time(2m,8h)表示,每两分钟记录一次rate字段的平均值,存储到表cq_2m中,执行时间偏移八小时,这个语法在influx官方文档Example 4中有提到:

Use an offset interval in the GROUP BY time() clause to alter both the CQ’s default execution time and preset time boundaries.

然而,这个8h的参数只偏移了执行时间,并没有作用到where条件的时间区间,测试日志如下:

1
2
2019-03-27T07:04:00.029446Z info Executing continuous query {"log_id": "0ERSB7o0000", "service": "continuous_querier", "trace_id": "0ERVFR7G000", "op_name": "continuous_querier_execute", "name": "cq_2m", "db_instance": "temp", "start": "2019-03-27T07:02:00.000000Z", "end": "2019-03-27T07:04:00.000000Z"}
2019-03-27T07:04:00.030061Z info Executing query {"log_id": "0ERSB7o0000", "service": "query", "query": "SELECT mean(rate) AS rate INTO temp.autogen.cq_2m FROM temp.autogen.perflog WHERE time >= '2019-03-27T07:02:00Z' AND time < '2019-03-27T07:04:00Z' GROUP BY time(2m,8h) fill(0)"}

当时是北京时间15:04:00,但是where time的区间还是提前了八个小时,就是取自influx自带的now()函数,这个函数使用的是UTC时间。

解决

提了issue,并没有满意的答复,只能曲线救国。

思路有两种:

  1. 统一坐标系
  2. quartz代替CQ进行重采样

因为2比较简单,工作量比1小,就选了2。:sweat_smile: