diff --git a/changes/32208-fleetctl-preview-logging b/changes/32208-fleetctl-preview-logging new file mode 100644 index 0000000000..c52f4e8e2b --- /dev/null +++ b/changes/32208-fleetctl-preview-logging @@ -0,0 +1 @@ +- Disabled debug logging by default in `fleetctl preview` and reformatted login information diff --git a/cmd/fleetctl/fleetctl/preview.go b/cmd/fleetctl/fleetctl/preview.go index 249d7a241e..b03d82bb73 100644 --- a/cmd/fleetctl/fleetctl/preview.go +++ b/cmd/fleetctl/fleetctl/preview.go @@ -17,6 +17,7 @@ import ( "strings" "time" + "github.com/briandowns/spinner" "github.com/cenkalti/backoff/v4" "github.com/fleetdm/fleet/v4/ee/server/licensing" "github.com/fleetdm/fleet/v4/orbit/pkg/constant" @@ -30,6 +31,7 @@ import ( kitlog "github.com/go-kit/log" "github.com/google/go-github/v37/github" "github.com/mitchellh/go-ps" + "github.com/rs/zerolog" "github.com/urfave/cli/v2" ) @@ -370,11 +372,17 @@ Use the stop and reset subcommands to manage the server and dependencies once st client.SetToken(token) fmt.Println("Loading starter library...") + + logger := kitlog.NewNopLogger() + if c.Bool(debugFlagName) { + logger = kitlog.NewLogfmtLogger(os.Stderr) + } + if err := service.ApplyStarterLibrary( c.Context, address, token, - kitlog.NewLogfmtLogger(os.Stderr), + logger, fleethttp.NewClient, service.NewClient, nil, // No mock ApplyGroup for production code @@ -408,16 +416,18 @@ Use the stop and reset subcommands to manage the server and dependencies once st return fmt.Errorf("Error disabling analytics collection in app config: %w", err) } + fmt.Println() fmt.Println("Fleet will now log you into the UI automatically.") fmt.Println("You can also open the UI at this URL: http://localhost:1337/previewlogin.") - fmt.Println("Email:", email) - fmt.Println("Password:", password) + fmt.Println("Email:\033[1m", email, "\033[0m") + fmt.Println("Password:\033[1m", password, "\033[0m") + fmt.Println() if !c.Bool(noHostsFlagName) { fmt.Println("Enrolling local host...") orbitDir := filepath.Join(previewDir, "orbit") - if err := downloadOrbitAndStart(orbitDir, secrets.Secrets[0].Secret, address, c.String(orbitChannel), c.String(osquerydChannel), c.String(updateURL), c.String(updateRootKeys)); err != nil { + if err := downloadOrbitAndStart(orbitDir, secrets.Secrets[0].Secret, address, c.String(orbitChannel), c.String(osquerydChannel), c.String(updateURL), c.String(updateRootKeys), c.Bool(debugFlagName)); err != nil { return fmt.Errorf("downloading orbit and osqueryd: %w", err) } @@ -559,6 +569,10 @@ func waitStartup() error { client := fleethttp.NewClient(fleethttp.WithTLSClientConfig(&tls.Config{InsecureSkipVerify: true})) + spin := spinner.New([]string{"|", "/", "-", "\\"}, 250*time.Millisecond) + spin.Start() + defer spin.Stop() + if err := backoff.Retry( func() error { resp, err := client.Get("https://localhost:8412/healthz") @@ -643,6 +657,12 @@ func previewStopCommand() *cli.Command { return fmt.Errorf("docker-compose file not found in preview directory: %w", err) } + fmt.Println("Stopping services...") + + spin := spinner.New([]string{"|", "/", "-", "\\"}, 250*time.Millisecond) + spin.Start() + defer spin.Stop() + out, err := compose.Command("stop").CombinedOutput() if err != nil { fmt.Println(string(out)) @@ -668,6 +688,9 @@ func previewStopCommand() *cli.Command { return fmt.Errorf("Failed to stop orbit: %w", err) } + // Spinner stop can be called multiple times, just make sure we don't spin over the message + spin.Stop() + fmt.Println("Fleet preview server and dependencies stopped. Start again with fleetctl preview.") return nil @@ -774,7 +797,7 @@ func processNameMatches(pid int, expectedPrefix string) (bool, error) { return strings.HasPrefix(strings.ToLower(process.Executable()), strings.ToLower(expectedPrefix)), nil } -func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquerydChannel, updateURL, updateRoots string) error { +func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquerydChannel, updateURL, updateRoots string, debug bool) error { if err := os.MkdirAll(destDir, constant.DefaultDirMode); err != nil { return fmt.Errorf("create orbit directory %q: %w", destDir, err) } @@ -812,6 +835,10 @@ func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquery updateOpt.RootKeys = updateRoots } + if !debug { + zerolog.SetGlobalLevel(zerolog.ErrorLevel) + } + if _, err := packaging.InitializeUpdates(updateOpt); err != nil { return fmt.Errorf("initialize updates: %w", err) } @@ -821,11 +848,16 @@ func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquery return fmt.Errorf("failed to locate executable for %s: %w", constant.OrbitTUFTargetName, err) } + dbgFlag := "--debug=false" + if debug { + dbgFlag = "--debug=true" + } + cmd := exec.Command(orbitPath, "--root-dir", destDir, "--fleet-url", address, "--insecure", - "--debug", + dbgFlag, "--enroll-secret", enrollSecret, "--orbit-channel", orbitChannel, "--osqueryd-channel", osquerydChannel,