mirror of
https://github.com/minio/mc.git
synced 2025-07-30 07:23:03 +03:00
Change the JSON output of mc support perf (#4198)
Change the JSON output of mc support perf The new change will still print multiple JSON lines for each conducted performance test but now we have a new field called 'type' field to difference between network, drive and object tests. This change also adds 'final' field to indicate this is the final json of a particular performance testing. Also, errors when conducting those tests will have a field 'err' as well in the JSON output.
This commit is contained in:
@ -24,24 +24,10 @@ import (
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
type netperfResult madmin.NetperfResult
|
||||
|
||||
func (m netperfResult) String() (msg string) {
|
||||
// string version is handled by banner.
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m netperfResult) JSON() string {
|
||||
JSONBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(JSONBytes)
|
||||
}
|
||||
|
||||
func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
|
||||
client, perr := newAdminClient(aliasedURL)
|
||||
if perr != nil {
|
||||
@ -76,13 +62,21 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
|
||||
}()
|
||||
|
||||
if globalJSON {
|
||||
for {
|
||||
select {
|
||||
case result := <-resultCh:
|
||||
printMsg(netperfResult(result))
|
||||
return nil
|
||||
}
|
||||
select {
|
||||
case err := <-errorCh:
|
||||
printMsg(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
Err: err.Error(),
|
||||
Final: true,
|
||||
})
|
||||
case result := <-resultCh:
|
||||
printMsg(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
NetResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
@ -100,19 +94,22 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
|
||||
select {
|
||||
case err := <-errorCh:
|
||||
p.Send(speedTestResult{
|
||||
err: err,
|
||||
final: true,
|
||||
Type: netSpeedTest,
|
||||
Err: err.Error(),
|
||||
Final: true,
|
||||
})
|
||||
return
|
||||
case result := <-resultCh:
|
||||
p.Send(speedTestResult{
|
||||
nresult: &result,
|
||||
final: true,
|
||||
Type: netSpeedTest,
|
||||
NetResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
return
|
||||
default:
|
||||
p.Send(speedTestResult{
|
||||
nresult: &madmin.NetperfResult{},
|
||||
Type: netSpeedTest,
|
||||
NetResult: &madmin.NetperfResult{},
|
||||
})
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
Reference in New Issue
Block a user