From 39a57a14b8d0f4ba2e0f2667a2c313e3f4482dd0 Mon Sep 17 00:00:00 2001
From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com>
Date: Tue, 24 Oct 2023 12:47:17 +0530
Subject: [PATCH] revamp spinner in `mc support diag` (#4727)
The current spinner mechanism looks for the data categories (CPU,
drives, memory, etc) sequentially. If any of the category's data is not
received, it gets stuck there.
If a new data category is introduced without changing the version of the
HealthInfo struct, then `mc support diag` can get stuck for the new
category when talking to an older version of minio.
So instead of looking for the categories one by one, start a spinner for
each category at the beginning, and mark it as done as soon as the
corresponding data is received. When the last category (admin info) is
received, mark any pending category as done so that the command
continues with the rest of the processing.
---
CREDITS | 29 +++++++++
cmd/support-diag-spinner-v3.go | 107 +++++++++++++++++++++++++++++++++
cmd/support-diag.go | 29 +--------
go.mod | 3 +
go.sum | 6 ++
5 files changed, 147 insertions(+), 27 deletions(-)
create mode 100644 cmd/support-diag-spinner-v3.go
diff --git a/CREDITS b/CREDITS
index a685625d..40e0eb03 100644
--- a/CREDITS
+++ b/CREDITS
@@ -11595,3 +11595,32 @@ limitations under the License.
================================================================
+github.com/vbauerster/mpb
+https://github.com/vbauerster/mpb
+----------------------------------------------------------------
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to
+
+================================================================
diff --git a/cmd/support-diag-spinner-v3.go b/cmd/support-diag-spinner-v3.go
new file mode 100644
index 00000000..a5656b24
--- /dev/null
+++ b/cmd/support-diag-spinner-v3.go
@@ -0,0 +1,107 @@
+// Copyright (c) 2015-2023 MinIO, Inc.
+//
+// # This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "sync"
+ "time"
+
+ json "github.com/minio/colorjson"
+ "github.com/minio/madmin-go/v3"
+ "github.com/vbauerster/mpb/v8"
+ "github.com/vbauerster/mpb/v8/decor"
+)
+
+func receiveHealthInfo(decoder *json.Decoder) (info madmin.HealthInfo, e error) {
+ var wg sync.WaitGroup
+ pg := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(16))
+
+ spinnerStyle := mpb.SpinnerStyle().Meta(func(s string) string {
+ return infoText(s)
+ }).PositionLeft()
+
+ type progressSpinner struct {
+ name string
+ spinner *mpb.Bar
+ cond func(madmin.HealthInfo) bool
+ }
+ spinners := []progressSpinner{}
+
+ createSpinner := func(name string, cond func(madmin.HealthInfo) bool) {
+ caption := fmt.Sprintf("%s %s ...", dot, name)
+ wip := mpb.PrependDecorators(decor.Name(greenText(caption)))
+ done := mpb.BarFillerOnComplete(greenText(check))
+ spinner := pg.New(1, spinnerStyle, wip, done)
+ spinners = append(spinners, progressSpinner{
+ name: name,
+ cond: cond,
+ spinner: spinner,
+ })
+ }
+
+ createSpinner("CPU Info", func(info madmin.HealthInfo) bool { return len(info.Sys.CPUInfo) > 0 })
+ createSpinner("Disk Info", func(info madmin.HealthInfo) bool { return len(info.Sys.Partitions) > 0 })
+ createSpinner("OS Info", func(info madmin.HealthInfo) bool { return len(info.Sys.OSInfo) > 0 })
+ createSpinner("Mem Info", func(info madmin.HealthInfo) bool { return len(info.Sys.MemInfo) > 0 })
+ createSpinner("Process Info", func(info madmin.HealthInfo) bool { return len(info.Sys.ProcInfo) > 0 })
+ createSpinner("Server Config", func(info madmin.HealthInfo) bool { return info.Minio.Config.Config != nil })
+ createSpinner("System Errors", func(info madmin.HealthInfo) bool { return len(info.Sys.SysErrs) > 0 })
+ createSpinner("System Services", func(info madmin.HealthInfo) bool { return len(info.Sys.SysServices) > 0 })
+ createSpinner("System Config", func(info madmin.HealthInfo) bool { return len(info.Sys.SysConfig) > 0 })
+ createSpinner("Admin Info", func(info madmin.HealthInfo) bool { return len(info.Minio.Info.Servers) > 0 })
+
+ wg.Add(len(spinners))
+ start := time.Now()
+
+ markDone := func(bar *mpb.Bar) {
+ if bar.Current() == 0 {
+ bar.EwmaIncrement(time.Since(start))
+ wg.Done()
+ }
+ }
+
+ receivedLast := false
+ progress := func(info madmin.HealthInfo) {
+ receivedLast = len(info.Minio.Info.Servers) > 0
+
+ for _, bar := range spinners {
+ if receivedLast || bar.cond(info) {
+ markDone(bar.spinner)
+ }
+ }
+ }
+
+ go func() {
+ for {
+ if e = decoder.Decode(&info); e != nil {
+ if errors.Is(e, io.EOF) {
+ e = nil
+ }
+
+ break
+ }
+
+ progress(info)
+ }
+ }()
+ pg.Wait()
+ return
+}
diff --git a/cmd/support-diag.go b/cmd/support-diag.go
index 99437e4f..55e1b0c8 100644
--- a/cmd/support-diag.go
+++ b/cmd/support-diag.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2015-2022 MinIO, Inc.
+// Copyright (c) 2015-2023 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
@@ -325,19 +325,6 @@ func fetchServerDiagInfo(ctx *cli.Context, client *madmin.AdminClient) (interfac
admin(len(info.Minio.Info.Servers) > 0)
}
- progress := func(info madmin.HealthInfo) {
- _ = cpu(len(info.Sys.CPUInfo) > 0) &&
- diskHw(len(info.Sys.Partitions) > 0) &&
- osInfo(len(info.Sys.OSInfo) > 0) &&
- mem(len(info.Sys.MemInfo) > 0) &&
- process(len(info.Sys.ProcInfo) > 0) &&
- config(info.Minio.Config.Config != nil) &&
- syserr(len(info.Sys.SysErrs) > 0) &&
- syssrv(len(info.Sys.SysServices) > 0) &&
- sysconfig(len(info.Sys.SysConfig) > 0) &&
- admin(len(info.Minio.Info.Servers) > 0)
- }
-
// Fetch info of all servers (cluster or single server)
resp, version, e := client.ServerHealthInfo(cont, *opts, ctx.Duration("deadline"))
if e != nil {
@@ -389,19 +376,7 @@ func fetchServerDiagInfo(ctx *cli.Context, client *madmin.AdminClient) (interfac
}
healthInfo = info
case madmin.HealthInfoVersion:
- info := madmin.HealthInfo{}
- for {
- if e = decoder.Decode(&info); e != nil {
- if errors.Is(e, io.EOF) {
- e = nil
- }
-
- break
- }
-
- progress(info)
- }
- healthInfo = info
+ healthInfo, e = receiveHealthInfo(decoder)
}
// cancel the context if supportDiagChan has returned.
diff --git a/go.mod b/go.mod
index 482b3126..784b42b5 100644
--- a/go.mod
+++ b/go.mod
@@ -53,11 +53,14 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_model v0.4.0
github.com/rivo/tview v0.0.0-20230909130259-ba6a2a345459
+ github.com/vbauerster/mpb/v8 v8.6.2
golang.org/x/term v0.13.0
)
require (
aead.dev/minisign v0.2.0 // indirect
+ github.com/VividCortex/ewma v1.2.0 // indirect
+ github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/minio/mux v1.9.0 // indirect
diff --git a/go.sum b/go.sum
index 22c777e7..58385fb4 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,10 @@
aead.dev/minisign v0.2.0 h1:kAWrq/hBRu4AARY6AlciO83xhNnW9UaC8YipS2uhLPk=
aead.dev/minisign v0.2.0/go.mod h1:zdq6LdSd9TbuSxchxwhpA9zEb9YXcVGoE8JakuiGaIQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
+github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
+github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
+github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
@@ -243,6 +247,8 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
+github.com/vbauerster/mpb/v8 v8.6.2 h1:9EhnJGQRtvgDVCychJgR96EDCOqgg2NsMuk5JUcX4DA=
+github.com/vbauerster/mpb/v8 v8.6.2/go.mod h1:oVJ7T+dib99kZ/VBjoBaC8aPXiSAihnzuKmotuihyFo=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=