Skip to content

Add Spinner implementation for longer-running operations.#115

Merged
febbraro merged 11 commits into
developfrom
feature/spinners
Nov 17, 2017
Merged

Add Spinner implementation for longer-running operations.#115
febbraro merged 11 commits into
developfrom
feature/spinners

Conversation

@grayside
Copy link
Copy Markdown
Contributor

@grayside grayside commented Nov 7, 2017

There are a number of operations that rig command execute which can take awhile, which is exacerbated by our use of the --verbose flag to keep some of the inner workings terse. As an example, a rig start can go almost a minute without a single terminal output if --verbose is not used and several retries are needed to get the docker machine up.

This PR adds a new util/spinner.go mechanism which wraps a new library that provides spinner support. If rig is run in verbose mode, it will pass messages sent to the spinner to the logger, if not, it will output the messages in conjunction with a spinner lifecycle to help communicate when rig is managing a longer-running process.

3__thanks_for_flying_vim__zsh_
3__thanks_for_flying_vim__zsh_
3__thanks_for_flying_vim__sudo_
3__thanks_for_flying_vim__zsh_
3__thanks_for_flying_vim__docker_

This PR attempts to cover all the bases, with exceptions in rig project sync and machine.go::WaitForDev, which seemed just as well as follow-ups.

Comment thread util/spinner.go Outdated
// When verbose, we perform basic logging instead of running the spinner.
func (s *RigSpinner) Start(message string) {
if Logger().IsVerbose {
Logger().Info.Println(message)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not liking the output in verbose mode with the "Starting..." and the end state. What do you think about not not showing the start message, just the complete messages on Verbose. Those start messages were not really included in output before during verbose so now it is even MORE verbose, almost....annoyingly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I found without the start message is that the spinner message would sometimes lack context. Let me audit/update the messages to see if there's enough context in verbose mode withotu the start

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when the spinner is in place you should use the start message, but when in verbose mode, just do nothing.

Adam Ross added 2 commits November 10, 2017 17:15
* origin/develop:
  Display executed commands via Verbose Logging (#111)
  Better cross platform builds (#118)
  Fixing Outrigger Dashboard on Linux (#117)
  Fixed bug in libnss-resolver DNS resolution (#116)
  Added rpm to build, well, rpms
  Transitioned to different go base to try to head off problems with dynamically linked go binaries
  tweaking some build flags
  tweaking CGO
  messing with ldflags
  tweaked goreleaser config
Comment thread CONTRIBUTING.md
* Make sure your branch conforms with go fmt standards.
* Manually test your changes.

## User Interactions
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New CONTRIBUTING guide, which includes thoughts on logging that illustrates some of the API that's coming together.

Comment thread CONTRIBUTING.md Outdated
* **Use the correct method to log operational results: (Pick one)**
* `cmd.out.Success("Sauce is Ready.")`
* `cmd.out.Warn("Sauce is burnt on the bottom.")`
* `cmd.out.Oops("Discard this sauce and try again.")`
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops is temporary, there are a number of "refactoring in progress" things going on before all the specific API details are right.

Comment thread commands/stop.go Outdated
}
color.Unset()
cmd.out.Success("Networking cleanup completed")
cmd.out.NoSpin()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to NoSpin() here, it's handled in BaseCommand.Success() no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True.

Comment thread util/logger.go Outdated
Warning: log.New(os.Stdout, color.YellowString("[WARN] "), 0),
Error: log.New(os.Stderr, color.RedString("[ERROR] "), 0),
Verbose: log.New(verboseWriter, "[VERBOSE] ", 0),
Message: log.New(os.Stdout, " - ", 0),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to be used

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i see where it is used. What is the idea behind Message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be pulled if continuing refactor doesn't find a use for it. I wanted to stake some concepts aside from log severity for the channels.

Comment thread util/shell_exec.go
// Log verbosely logs the command.
func (x Executor) Log(tag string) {
color.Set(color.FgYellow)
color.Set(color.FgMagenta)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this was already merged?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that change here, then created a separate branch, and didn't pull it back out. This change made it into v2.

@febbraro
Copy link
Copy Markdown
Member

This is much more along the lines of what I was thinking.

Comment thread CONTRIBUTING.md
* **Command has executed and is successful. We do not want a notification:**
```
cmd.out.Success("Enjoy your dinner.")
return cmd.Success("")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd.out.Success() and cmd.Success() is confusing. Can they be consolidated?, or can we rename one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may also want a SilentSuccess() so we dont need to send in ""?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, or SuccessWithNotification()

I agree the two Success() statements is confusing. I originally had it as Complete(), but complete only made sense in the context of the spinner. Unfortunately this "success" is often the equivalent of an info log. I will look at the API overall and see what can be rejiggered. Now that I know I'm on the right track I can make deeper cuts.

@grayside
Copy link
Copy Markdown
Contributor Author

On the idea that this API has mostly solidified, but is going to have git conflicts if you blow on it, might we merge this and complete polishing the experience as a follow-up?

@febbraro febbraro merged commit e11e398 into develop Nov 17, 2017
@febbraro febbraro deleted the feature/spinners branch November 17, 2017 03:50
@grayside grayside added this to the v2.1 milestone Nov 17, 2017
Comment thread util/logger.go
}

// Verbose allows Verbose logging of more advanced activities/information.
// In practice, if the spinner can be in use verbose is a no-op.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a little trouble wrapping my brain around this comment. Is this saying that if the spinner is running verbose output won't be seen? Is that an indicator that using the --verbose flag indicates that the spinner won't run? That is my intuition but I haven't been able to perceive in the code what makes that the case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run rig --verbose, you get "classic" logging. The text from Spin() is not output in verbose mode.

Comment thread CONTRIBUTING.md
* `cmd.out.Info("Sauce is Ready.")`
* `cmd.out.Warning("Sauce is burnt on the bottom.")`
* `cmd.out.Error("Discard this sauce and try again.")`
* **Going to send some contextual notes to the user**:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this example one where you always want to send a note to the user (or is the info/verbose a distinction on whether it's always versus only if --verbose is set)? If it's an indicator that the spinner needs to be disabled in those cases should we put re-enabling it after sending the message?

I don't see any indications of using NoSpin in the code so far other than in a Failure message so that makes me think perhaps I'm not interpreting how/when it needs to be used in order to use it correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be that NoSpin needs to be added somewhere. If you do some regular logs when the Spinner is active, it suspends the spinner on line 1, outputs the log on line 2, and resumes the spinner on line 3. If you add NoSpin before logging, it does not resume on line 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants