influxdata / influxdata/kapacitor
Document Kapacitor-idiomatic way for running advanced-syntax InfluxQL functions
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
There are known issues (https://github.com/influxdata/kapacitor/issues/1978) when trying to execute a batch query written in InfluxQL that uses functions to compute the `difference`, `derivative`, etc. on an aggregate.
For example:
```
SELECT DERIVATIVE(MEAN("water_level"))
FROM "h2o_feet"
WHERE "location" = 'santa_monica'
AND time >= '2015-08-18T00:00:00Z'
AND time <= '2015-08-18T00:30:00Z'
GROUP BY time(12m)
```
As the [documentation](https://docs.influxdata.com/kapacitor/v1.5/nodes/query_node/) says, you cannot put any `group by` or `where time...` in the `QueryNode`, because they will be overwritten by Kapacitor when you add `.groupBy(...).period(...)...`. However, the advanced syntax for those functions __requires__ `group by time(...)`.
I propose that the documentation explicits an example to compute the `non_negative_difference` (one for all those functions) in Kapacitor-idiomatic way.
The solution is to let Kapacitor compute the non negative difference outside of the query node:
```
batch
|query('''
SELECT mean("value")
FROM "telegraf"."default".cpu_usage_idle
WHERE "host" = 'serverA'
''')
.period(1m)
.every(20s)
.groupBy(time(10s), 'cpu')
| difference('max_usage')
| where(lambda: "difference" >= 0)
```
Contributor guide
Research direction
Start with the linked Kapacitor QueryNode documentation and compare it with the issue's batch-query example. Document the Kapacitor-idiomatic approach for non_negative_difference, including how to use the difference and where nodes outside the query; done means a newcomer can follow the example without relying on advanced InfluxQL syntax.
Written by the indexing model from the issue text.
Assessment
- Domain
- data, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100