Export perf test result related types (#4246)
So that they can be used by `health-analyzer` when parsing the performance test results data.
This commit is contained in:
+17
-13
@@ -37,31 +37,35 @@ var whiteStyle = lipgloss.NewStyle().
|
||||
type speedTestUI struct {
|
||||
spinner spinner.Model
|
||||
quitting bool
|
||||
result speedTestResult
|
||||
result PerfTestResult
|
||||
}
|
||||
|
||||
type speedTestType byte
|
||||
// PerfTestType - The type of performance test (net/drive/object)
|
||||
type PerfTestType byte
|
||||
|
||||
// Constants for performance test type
|
||||
const (
|
||||
netSpeedTest speedTestType = 1 << iota
|
||||
driveSpeedTest
|
||||
objectSpeedTest
|
||||
NetPerfTest PerfTestType = 1 << iota
|
||||
DrivePerfTest
|
||||
ObjectPerfTest
|
||||
)
|
||||
|
||||
func (s speedTestType) Name() string {
|
||||
switch s {
|
||||
case netSpeedTest:
|
||||
// Name - returns name of the performance test
|
||||
func (p PerfTestType) Name() string {
|
||||
switch p {
|
||||
case NetPerfTest:
|
||||
return "NetPerf"
|
||||
case driveSpeedTest:
|
||||
case DrivePerfTest:
|
||||
return "DrivePerf"
|
||||
case objectSpeedTest:
|
||||
case ObjectPerfTest:
|
||||
return "ObjectPerf"
|
||||
}
|
||||
return "<unknown>"
|
||||
}
|
||||
|
||||
type speedTestResult struct {
|
||||
Type speedTestType `json:"type"`
|
||||
// PerfTestResult - stores the result of a performance test
|
||||
type PerfTestResult struct {
|
||||
Type PerfTestType `json:"type"`
|
||||
ObjectResult *madmin.SpeedTestResult `json:"object,omitempty"`
|
||||
NetResult *madmin.NetperfResult `json:"network,omitempty"`
|
||||
DriveResult []madmin.DriveSpeedTestResult `json:"drive,omitempty"`
|
||||
@@ -92,7 +96,7 @@ func (m *speedTestUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
case speedTestResult:
|
||||
case PerfTestResult:
|
||||
m.result = msg
|
||||
if msg.Final {
|
||||
m.quitting = true
|
||||
|
||||
+10
-10
@@ -68,8 +68,8 @@ func mainAdminSpeedTestDrive(ctx *cli.Context, aliasedURL string) error {
|
||||
|
||||
if globalJSON {
|
||||
if e != nil {
|
||||
printMsg(speedTestResult{
|
||||
Type: driveSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: DrivePerfTest,
|
||||
Err: e.Error(),
|
||||
Final: true,
|
||||
})
|
||||
@@ -82,8 +82,8 @@ func mainAdminSpeedTestDrive(ctx *cli.Context, aliasedURL string) error {
|
||||
results = append(results, result)
|
||||
}
|
||||
}
|
||||
printMsg(speedTestResult{
|
||||
Type: driveSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: DrivePerfTest,
|
||||
DriveResult: results,
|
||||
Final: true,
|
||||
})
|
||||
@@ -103,8 +103,8 @@ func mainAdminSpeedTestDrive(ctx *cli.Context, aliasedURL string) error {
|
||||
|
||||
go func() {
|
||||
if e != nil {
|
||||
printMsg(speedTestResult{
|
||||
Type: driveSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: DrivePerfTest,
|
||||
Err: e.Error(),
|
||||
})
|
||||
return
|
||||
@@ -115,14 +115,14 @@ func mainAdminSpeedTestDrive(ctx *cli.Context, aliasedURL string) error {
|
||||
if result.Version != "" {
|
||||
results = append(results, result)
|
||||
} else {
|
||||
p.Send(speedTestResult{
|
||||
Type: driveSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: DrivePerfTest,
|
||||
DriveResult: []madmin.DriveSpeedTestResult{},
|
||||
})
|
||||
}
|
||||
}
|
||||
p.Send(speedTestResult{
|
||||
Type: driveSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: DrivePerfTest,
|
||||
DriveResult: results,
|
||||
Final: true,
|
||||
})
|
||||
|
||||
+10
-10
@@ -64,14 +64,14 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
|
||||
if globalJSON {
|
||||
select {
|
||||
case e := <-errorCh:
|
||||
printMsg(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: NetPerfTest,
|
||||
Err: e.Error(),
|
||||
Final: true,
|
||||
})
|
||||
case result := <-resultCh:
|
||||
printMsg(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: NetPerfTest,
|
||||
NetResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
@@ -93,22 +93,22 @@ func mainAdminSpeedTestNetperf(ctx *cli.Context, aliasedURL string) error {
|
||||
for {
|
||||
select {
|
||||
case e := <-errorCh:
|
||||
p.Send(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: NetPerfTest,
|
||||
Err: e.Error(),
|
||||
Final: true,
|
||||
})
|
||||
return
|
||||
case result := <-resultCh:
|
||||
p.Send(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: NetPerfTest,
|
||||
NetResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
return
|
||||
default:
|
||||
p.Send(speedTestResult{
|
||||
Type: netSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: NetPerfTest,
|
||||
NetResult: &madmin.NetperfResult{},
|
||||
})
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
+12
-12
@@ -95,8 +95,8 @@ func mainAdminSpeedTestObject(ctx *cli.Context, aliasedURL string) error {
|
||||
|
||||
if globalJSON {
|
||||
if e != nil {
|
||||
printMsg(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
Err: e.Error(),
|
||||
Final: true,
|
||||
})
|
||||
@@ -108,14 +108,14 @@ func mainAdminSpeedTestObject(ctx *cli.Context, aliasedURL string) error {
|
||||
if result.Version == "" {
|
||||
continue
|
||||
}
|
||||
printMsg(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
ObjectResult: &result,
|
||||
})
|
||||
}
|
||||
|
||||
printMsg(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
printMsg(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
ObjectResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
@@ -135,8 +135,8 @@ func mainAdminSpeedTestObject(ctx *cli.Context, aliasedURL string) error {
|
||||
|
||||
go func() {
|
||||
if e != nil {
|
||||
p.Send(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
Err: e.Error(),
|
||||
Final: true,
|
||||
})
|
||||
@@ -145,13 +145,13 @@ func mainAdminSpeedTestObject(ctx *cli.Context, aliasedURL string) error {
|
||||
|
||||
var result madmin.SpeedTestResult
|
||||
for result = range resultCh {
|
||||
p.Send(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
ObjectResult: &result,
|
||||
})
|
||||
}
|
||||
p.Send(speedTestResult{
|
||||
Type: objectSpeedTest,
|
||||
p.Send(PerfTestResult{
|
||||
Type: ObjectPerfTest,
|
||||
ObjectResult: &result,
|
||||
Final: true,
|
||||
})
|
||||
|
||||
+4
-3
@@ -128,12 +128,13 @@ func objectTestShortResult(result *madmin.SpeedTestResult) (msg string) {
|
||||
return msg
|
||||
}
|
||||
|
||||
func (s speedTestResult) String() string {
|
||||
func (p PerfTestResult) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (s speedTestResult) JSON() string {
|
||||
JSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
// JSON - jsonified update message.
|
||||
func (p PerfTestResult) JSON() string {
|
||||
JSONBytes, e := json.MarshalIndent(p, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(JSONBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user