influx query: Run Flux Queries in CI
influx query runs a Flux query against InfluxDB 2.x and prints the result table, using the CLI's configured org and token.
After seeding data you often assert on it. influx query runs Flux inline or from a file so a test step can read back what was written.
What it does
influx query sends a Flux script to the server and prints the resulting annotated CSV (or a more readable table). Flux replaced InfluxQL as the default language in 2.x. The query needs an org, supplied by flag or config profile, and a token.
Common usage
influx query --org acme \
'from(bucket:"app") |> range(start:-1h) |> count()'
# from a file, raw annotated CSV for parsing
influx query --org acme --file ./checks/recent.flux --rawOptions
| Flag | What it does |
|---|---|
| -o, --org <name> | Organization to query against |
| -f, --file <path> | Read the Flux query from a file |
| -r, --raw | Output raw annotated CSV (good for parsing) |
| -t, --token <token> | API token (or set via influx config) |
| --host <url> | Server URL, e.g. http://localhost:8086 |
In CI
Use --raw when a later step parses the result, since the default pretty output is for humans. Keep nontrivial Flux in a .flux file and run it with --file so it is reviewable and reusable. A query against an empty bucket returns no tables, not an error, so assert on the row count rather than exit status.
Common errors in CI
"Error: failed to execute query: 401 Unauthorized" is a token problem. "could not find bucket \"app\"" means the bucket name is wrong or unset. A Flux "error @L:C: undefined identifier" points at a typo in the script. Querying with InfluxQL syntax fails because the CLI expects Flux unless the v1 compatibility API is used.