InfluxDB v2.7.0 OSS
Server: 85f725f
Frontend: 0c844dc
What I’m trying to do:
I’m trying to write a task in the InfluxDB GUI, export it, and then use source control / bash scripts to deploy during instance startup.
Steps:
1.) Using the GUI, define a task and confirm it works as expected. (it does)
2.) Export the task definition, and the resulting JSON file looks like this:
[
{
"apiVersion": "influxdata.com/v2alpha1",
"kind": "Task",
"metadata": {
"name": "noshing-lumiere-9f2001"
},
"spec": {
"every": "10m",
"name": "john1",
"offset": "5m0s",
"query": "from(bucket: \"metrics\")\n |> range(start: -10m)\n |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\")\n |> filter(fn: (r) => r[\"_field\"] == \"usage_user\")\n |> filter(fn: (r) => r[\"cpu\"] == \"cpu-total\")\n |> aggregateWindow(every: 1m, fn: mean, createEmpty: false)\n |> to(bucket: \"test\")"
}
}
]
3.) Add the JSON definition as the payload of a POST method to the /api/v2/tasks/ API endpoint. The POST fails, complaining of a missing “flux” field.
4.) The InfluxDB Postman collection suggests this is the “shape” of the payload, which contains similar data:
{
"orgID": "{{orgID}}",
"status": "inactive",
"flux": "option task = {name: \"mytask\", every: 10m, offset: 1m}\n from(bucket: \"system\")\n |> range(start: -task.every)\n |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\")\n |> filter(fn: (r) => r[\"_field\"] == \"usage_user\")\n |> filter(fn: (r) => r[\"cpu\"] == \"cpu-total\")\n |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)\n |> to(bucket: \"test\")\n",
"description": "downsamples total cpu usage_user data into 5m averages every 10m"
}
5.) Observe that the shape of the exported JSON and the working POST payload are quite different. (the queries in my example are a bit different.)
QUESTIONS:
1.) Am I wrong to expect that a JSON payload exported from the GUI can be POSTed back to API?
2.) What endpoint should I use to POST a task exported from the InfluxDB UI?
3.) Does anyone have general advice regarding bulk formatting/managing many tasks deployed from source code?
For example, the flux command seems to need to be rewritten using “backslash-n” and “backslash-t” rather than allowing clear text formatting: the result is quite obscure.