influx-cli
influx-cli copied to clipboard
Add back the Flux REPL to the influx CLI
Previously, we had a flux REPL in the CLI.
It was removed due to various concerns.
The following concerns we believe we can fix:
- The flux version in the CLI was out of date: https://github.com/influxdata/influxdb/issues/18676
- Startup time for the CLI was long and impacting other CLI commands negatively (hopefully this can be mitigated by not starting the flux engine unless we actually want the REPL).
- filter commands were broken for some use cases: https://github.com/influxdata/influxdb/issues/15974 , https://github.com/influxdata/influxdb/issues/18210
This concern is more difficult:
- multi-line execution didn't really work well (it should work like executing steps of a script, but e.g. if you import and then run a command in separate REPL executions it didn't work): https://github.com/influxdata/influxdb/issues/19014
This issue is for the MVP of authoring flux queries on the command line with good code completion.
Open question: How do we handle multiline queries?
> import "prometheus"
> query1 = prometheus.scrape()
|> filter(...)
|> yield()
> query2 = query1 |> last()
Should the import affect query1? Should we keep the results of query1 in memory in order to run query2?
Proposed answer (needs input from flux team!)
For the MVP, don't handle multi-line. Leave https://github.com/influxdata/influxdb/issues/19014 as an open issue for now (unless the flux team is willing to take this on) and focus on providing a way to author flux queries on the command line ergonomically (no awful shell quoting around flux quotes, nice completions potentially via an LSP).
- Potentially give a warning that this is under construction for users that were hoping for something more REPL-like.
- Potentially support imports as a special case
Prior art:
https://github.com/influxdata/flux/tree/master/cmd/flux
@nathanielc I would like your team's input on this
@rockstar Do you have any specific thoughts?
My general plan (although its not well thought out yet) is to do a complete rewrite of the REPL as its exists in the Flux repo today. I want to address some of the above points you mention as well as rethink what a REPL means for Flux. REPLs provide an iterative experience in working with code. What does that development iteration look like for Flux? That is the core of the multiline issue above.
Perhaps we should find a time to meet and sketch out an MVP of REPL from the ground up?
See also https://github.com/influxdata/influx-cli/issues/329 - if we rule this issue out of the next release, we should at least tidy up the CLI to say something like "flux repl under construction" and push people toward authoring flux queries in the UI or with VSCode (with docs links) instead of giving no help.
Does the CLI currently allow for a query to be executed without the REPL? To me the REPL is an experience above and beyond running a simple query. I don't think we need to push users to the UI or VSCode to run queries. Running influx query ....
repeatedly from their shell is the MVP REPL we can offer now.
I suspect we lose on time-to-awesome here - code completion (which used to work in the influx CLI, before we ripped out the repl) would help a lot getting the first data back from flux.
Having to get all of something like:
influx query 'from(bucket: "mybucket") |> range(start: -10m) |> filter(fn: (r) => r._measurement == "cpu")
leaves a lot more places to fail for a first time user than something like:
select * from cpu
(I include the range in flux but not InfluxQL because flux errors without it).
And maybe we just need better exploratory functions - it would be cool if I could write (and tutorials suggested):
influx query 'head("mybucket")'
that gave some useful window on my data.
But overall I think people are just going to have a way better time if their first experience with flux is in the UI that can build their first query for them.