mirrord icon indicating copy to clipboard operation
mirrord copied to clipboard

Provide feedback while the agent is initializing

Open tamasfe opened this issue 2 years ago • 13 comments

The CLI currently silently waits for the agent to be up and running, since it can take a while it would be nice to show some minimal progress.

tamasfe avatar Sep 11 '22 17:09 tamasfe

Thanks for the suggestion! This should be easily done by adding prints in the relevant places.

aviramha avatar Sep 12 '22 06:09 aviramha

@aviramha you can assign this one to me.

Since it's a user-facing tool, I thought of using spinoff without colors for this to log the agent stages. Do you think it's worth the extra effort over just plain messages? Those have to be implemented for dumb terminals anyway.

tamasfe avatar Sep 13 '22 10:09 tamasfe

@aviramha you can assign this one to me.

Since it's a user-facing tool, I thought of using spinoff without colors for this to log the agent stages. Do you think it's worth the extra effort over just plain messages? Those have to be implemented for dumb terminals anyway.

Done! If you think spinoff is cool then yeah go ahead. One thing to notice is I thing that the prints/spinner should be enabled only when using the cli, as when it runs in extension/other mode it might trigger weird behavior (for example if the IDE debugger expects a debugee to have certain output and we'll start printing to stdout) I'd expect it to be enabled by an env var in the mirrord-layer part which the cli sets.

aviramha avatar Sep 13 '22 11:09 aviramha

I thought of just logging to stderr, so anything that expects output via stdout is unaffected.

tamasfe avatar Sep 13 '22 11:09 tamasfe

I thought of just logging to stderr, so anything that expects output via stdout is unaffected.

Hmm I'm worried it might be too much magic for some (abusing stderr). @eyalb181 wdyt?

aviramha avatar Sep 13 '22 12:09 aviramha

Thinking about it a bit more - in our tests with layer we assert stderr is empty for example..

aviramha avatar Sep 13 '22 12:09 aviramha

I typically emit all user-facing logs to stderr in my applications so things that might consume stdout are unaffected by them (cargo does the same for compilation progress messages).

It's entirely possible to disable logs for dumb terminals as well of course like you suggest.

tamasfe avatar Sep 13 '22 12:09 tamasfe

For me, stdout makes more sense here. We'd like to keep it enabled in dumb terminals too though, so we could use it to show progress in our IDE extensions.

eyalb181 avatar Sep 13 '22 15:09 eyalb181

Don't hate me but I think we should have different implementations based on flags. MIRRORD_ENABLE_PROGRESS=std -> will have implementation of just printing lines/using spinners MIRRORD_ENABLE_PROGRESS=ext -> will print jsons/other API friendly output and by default it'd be off..

aviramha avatar Sep 13 '22 15:09 aviramha

By default MIRRORD_ENABLE_PROGRESS would be off? Not std?

eyalb181 avatar Sep 13 '22 16:09 eyalb181

By default MIRRORD_ENABLE_PROGRESS would be off? Not std?

default of layer, cli will have it on by default.

aviramha avatar Sep 13 '22 16:09 aviramha

Alright, so to summarize I'm thinking of 4 modes:

  • fancy mode progress with spinner and whatnot, potentially with colors (windows is my concern regarding colors)
  • less fancy but still user-readable (dumb) mode if the terminal is dumb or not a tty
  • JSON mode for IDE integrations
  • quiet/off, no output

All of them go to stdout, this means that user-readable output and JSON cannot coexist. The default is fancy for the CLI, which automagically turns into dumb, quiet for the layer, but if the layer is initialized via the CLI, it should set the env var for it anyway.

I would not implement JSON output with my PR as it needs to be properly specified as other software will depend on it.

I'd add a CLI option for --quiet for users as well outside the environment variables.

Next I'm thinking of how to collect this information, I believe we could just use tracing spans to track progress, this way we don't need to wire the progress tracking all the way in the code, just add spans and a subscriber layer that is configured in one of the above modes.

tamasfe avatar Sep 14 '22 09:09 tamasfe

That sounds good (spans and subscriber layer)

aviramha avatar Sep 14 '22 13:09 aviramha

closing this since #537 is merged

infiniteregrets avatar Oct 13 '22 00:10 infiniteregrets