Print a better error msg when net perf is unsupported (#4194)

Netperf is not supported in a standard deployment, this PR will print a
better error message in that case.
This commit is contained in:
Anis Elleuch
2022-08-08 15:20:18 -07:00
committed by GitHub
parent d43c25ffa3
commit 73b157e4b1
2 changed files with 26 additions and 3 deletions
+13
View File
@@ -41,6 +41,7 @@ type speedTestUI struct {
}
type speedTestResult struct {
err error
final bool
result *madmin.SpeedTestResult
nresult *madmin.NetperfResult
@@ -87,6 +88,18 @@ func (m *speedTestUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
func (m *speedTestUI) View() string {
// Quit when there is an error
if m.result.err != nil {
errMsg := ""
errResp := madmin.ToErrorResponse(m.result.err)
if errResp.Code == "NotImplemented" {
errMsg = "Not implemented"
} else {
errMsg = m.result.err.Error()
}
return fmt.Sprintf("\nNetperf: ✗ (Err: %s)\n", errMsg)
}
var s strings.Builder
s.WriteString("\n")
+13 -3
View File
@@ -63,12 +63,16 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
}
resultCh := make(chan madmin.NetperfResult)
errorCh := make(chan error)
go func() {
result, err := client.Netperf(ctxt, duration)
fatalIf(probe.NewError(err), "Unable to capture network perf results")
defer close(resultCh)
defer close(errorCh)
result, err := client.Netperf(ctxt, duration)
if err != nil {
errorCh <- err
}
resultCh <- result
close(resultCh)
}()
if globalJSON {
@@ -94,6 +98,12 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
go func() {
for {
select {
case err := <-errorCh:
p.Send(speedTestResult{
err: err,
final: true,
})
return
case result := <-resultCh:
p.Send(speedTestResult{
nresult: &result,