Migrate continuous queries to tasks
InfluxDB OSS 2.0 replaces 1.x continuous queries (CQs) with InfluxDB tasks. To migrate continuous queries to InfluxDB 2.0 tasks, do the following:
- Output all InfluxDB 1.x continuous queries
- Convert continuous queries to Flux queries
- Create new InfluxDB tasks
Output all InfluxDB 1.x continuous queries
To output and save all continuous queries that exist in your InfluxDB 1.x instance, do the following:
Use the InfluxDB 1.x
influx
interactive shell to runshow continuous queries
:$ influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> show continuous queries
Copy and save the displayed continuous queries.
Convert continuous queries to Flux queries
To migrate InfluxDB 1.x continuous queries to InfluxDB 2.0 tasks, convert the InfluxQL query syntax to Flux. The majority of continuous queries are simple downsampling queries and can be converted quickly using the aggregateWindow()
function. For example:
Example continuous query
CREATE CONTINUOUS QUERY "downsample-daily" ON "my-db"
BEGIN
SELECT mean("example-field")
INTO "average-example-measurement"
FROM "example-measurement"
GROUP BY time(1h)
END
Equivalent Flux query
from(bucket: "my-db/")
|> range(start: -1d)
|> filter(fn: (r) => r._measurement == "example-measurement")
|> filter(fn: (r) => r._field == "example-field")
|> aggregateWindow(every: 1h, fn: mean)
|> set(key: "_measurement", as: "average-example-measurement")
|> to(
org: "example-org",
bucket: "my-db/downsample-daily"
)
Create new InfluxDB tasks
After converting your continuous query to Flux, use the Flux query to create a new task.
Other helpful resources
The following resources are available and may be helpful when converting continuous queries to Flux tasks.
Documentation
Community
- Post in the InfluxData Community
- Ask in the InfluxDB Community Slack