allow terminal control back for 'top api/disk' (#4239)

similar to #4237 fix other command TUI's as well,
also no locking is needed to protect maps.

Update()/View() are serial so need to add mutexes.
This commit is contained in:
Harshavardhana
2022-09-09 03:48:39 -07:00
committed by GitHub
parent 3142b54cc1
commit ea96e2b2c8
5 changed files with 17 additions and 38 deletions
+1 -2
View File
@@ -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")
}
}
+5 -10
View File
@@ -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
}
+5 -11
View File
@@ -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
}
+5 -8
View File
@@ -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 {
+1 -7
View File
@@ -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 {