diff --git a/cmd/admin-scanner-status.go b/cmd/admin-scanner-status.go index a5699b12..e2f03e55 100644 --- a/cmd/admin-scanner-status.go +++ b/cmd/admin-scanner-status.go @@ -22,7 +22,6 @@ import ( "context" "errors" "fmt" - "os" "sort" "strings" "time" @@ -129,7 +128,7 @@ func mainAdminScannerInfo(ctx *cli.Context) error { if !globalJSON { if e := ui.Start(); e != nil { cancel() - os.Exit(1) + fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to fetch scanner metrics") } } diff --git a/cmd/support-top-api.go b/cmd/support-top-api.go index 1999f49e..c1d7dda5 100644 --- a/cmd/support-top-api.go +++ b/cmd/support-top-api.go @@ -19,7 +19,6 @@ package cmd import ( "context" - "os" tea "github.com/charmbracelet/bubbletea" "github.com/minio/cli" @@ -105,16 +104,8 @@ func mainSupportTopAPI(ctx *cli.Context) error { // Start listening on all trace activity. traceCh := client.ServiceTrace(ctxt, opts) - done := make(chan struct{}) p := tea.NewProgram(initTraceUI()) - go func() { - if e := p.Start(); e != nil { - os.Exit(1) - } - close(done) - }() - go func() { for apiCallInfo := range traceCh { if apiCallInfo.Err != nil { @@ -131,6 +122,10 @@ func mainSupportTopAPI(ctx *cli.Context) error { } }() - <-done + if e := p.Start(); e != nil { + cancel() + fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to fetch top API events") + } + return nil } diff --git a/cmd/support-top-disk.go b/cmd/support-top-disk.go index 3af13c3c..f281a5df 100644 --- a/cmd/support-top-disk.go +++ b/cmd/support-top-disk.go @@ -20,7 +20,6 @@ package cmd import ( "context" "log" - "os" "time" tea "github.com/charmbracelet/bubbletea" @@ -98,16 +97,7 @@ func mainSupportTopDisk(ctx *cli.Context) error { ByDisk: true, } - done := make(chan struct{}) - p := tea.NewProgram(initTopDiskUI(disks, ctx.Int("count"))) - go func() { - if e := p.Start(); e != nil { - os.Exit(1) - } - close(done) - }() - go func() { out := func(m madmin.RealtimeMetrics) { for name, metric := range m.ByDisk { @@ -124,6 +114,10 @@ func mainSupportTopDisk(ctx *cli.Context) error { } }() - <-done + if e := p.Start(); e != nil { + cancel() + fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to fetch top disks events") + } + return nil } diff --git a/cmd/top-api-spinner.go b/cmd/top-api-spinner.go index 0f76c077..5ef93102 100644 --- a/cmd/top-api-spinner.go +++ b/cmd/top-api-spinner.go @@ -104,7 +104,7 @@ func (m *traceUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { - case "ctrl+c": + case "ctrl+c", "q", "esc": m.quitting = true return m, tea.Quit default: @@ -120,14 +120,11 @@ func (m *traceUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } return m, nil - - case spinner.TickMsg: - var cmd tea.Cmd - m.spinner, cmd = m.spinner.Update(msg) - return m, cmd - default: - return m, nil } + + var cmd tea.Cmd + m.spinner, cmd = m.spinner.Update(msg) + return m, cmd } func (m *traceUI) View() string { diff --git a/cmd/top-disk-spinner.go b/cmd/top-disk-spinner.go index 45e60f0d..ba0157d1 100644 --- a/cmd/top-disk-spinner.go +++ b/cmd/top-disk-spinner.go @@ -21,7 +21,6 @@ import ( "fmt" "sort" "strings" - "sync" "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" @@ -40,7 +39,6 @@ type topDiskUI struct { disksInfo map[string]madmin.Disk - mu sync.Mutex prevTopMap map[string]madmin.DiskIOStats currTopMap map[string]madmin.DiskIOStats } @@ -84,7 +82,7 @@ func (m *topDiskUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { - case "ctrl+c", "q": + case "ctrl+c", "q", "esc": m.quitting = true return m, tea.Quit case "right": @@ -113,10 +111,8 @@ func (m *topDiskUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case topDiskResult: - m.mu.Lock() m.prevTopMap[msg.diskName] = m.currTopMap[msg.diskName] m.currTopMap[msg.diskName] = msg.stats - m.mu.Unlock() if msg.final { m.quitting = true return m, tea.Quit @@ -218,7 +214,6 @@ func (m *topDiskUI) View() string { var data []diskIOStat - m.mu.Lock() for disk := range m.currTopMap { currDisk, ok := m.disksInfo[disk] if !ok || currDisk.PoolIndex != m.pool { @@ -226,7 +221,6 @@ func (m *topDiskUI) View() string { } data = append(data, generateDiskStat(m.disksInfo[disk], m.currTopMap[disk], m.prevTopMap[disk], 1000)) } - m.mu.Unlock() sort.Slice(data, func(i, j int) bool { switch m.sortBy {