Skip to content

Commit

Permalink
Fix empty version in health report download
Browse files Browse the repository at this point in the history
In the "Download" option after generating health report, the version
header was getting printed with an empty version number. This was
happening because the version variable was shadowed inside a for loop.

Couple of other improvements:
- avoid gzipping the health info twice
- do not maintain list of tests to perform in console, simply use list
  of all tests from madmin
  • Loading branch information
anjalshireesh committed May 9, 2024
1 parent 1058efb commit 2aaee45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
25 changes: 3 additions & 22 deletions api/admin_health_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/minio/console/pkg/utils"

subnet "github.com/minio/console/pkg/subnet"
"github.com/minio/madmin-go/v3"
mc "github.com/minio/mc/cmd"
"github.com/minio/websocket"
)
Expand All @@ -44,21 +43,7 @@ func startHealthInfo(ctx context.Context, conn WSConn, client MinioAdmin, deadli
}

// Fetch info of all servers (cluster or single server)
healthDataTypes := []madmin.HealthDataType{
madmin.HealthDataTypeMinioInfo,
madmin.HealthDataTypeMinioConfig,
madmin.HealthDataTypeSysCPU,
madmin.HealthDataTypeSysDriveHw,
madmin.HealthDataTypeSysDocker,
madmin.HealthDataTypeSysOsInfo,
madmin.HealthDataTypeSysLoad,
madmin.HealthDataTypeSysMem,
madmin.HealthDataTypeSysNet,
madmin.HealthDataTypeSysProcess,
}
var err error
// Fetch info of all servers (cluster or single server)
healthInfo, version, err := client.serverHealthInfo(ctx, healthDataTypes, *deadline)
healthInfo, version, err := client.serverHealthInfo(ctx, *deadline)
if err != nil {
return err
}
Expand All @@ -75,7 +60,7 @@ func startHealthInfo(ctx context.Context, conn WSConn, client MinioAdmin, deadli
}

ctx = context.WithValue(ctx, utils.ContextClientIP, conn.remoteAddress())
err = sendHealthInfoToSubnet(ctx, healthInfo, client)
err = sendHealthInfoToSubnet(ctx, compressedDiag, client)
report := messageReport{
Encoded: encodedDiag,
ServerHealthInfo: healthInfo,
Expand Down Expand Up @@ -116,7 +101,7 @@ func updateMcGlobals(subnetTokenConfig subnet.LicenseTokenConfig) error {
return nil
}

func sendHealthInfoToSubnet(ctx context.Context, healthInfo interface{}, client MinioAdmin) error {
func sendHealthInfoToSubnet(ctx context.Context, compressedHealthInfo []byte, client MinioAdmin) error {
filename := fmt.Sprintf("health_%d.json.gz", time.Now().Unix())
subnetTokenConfig, e := GetSubnetKeyFromMinIOConfig(ctx, client)
if e != nil {
Expand All @@ -135,10 +120,6 @@ func sendHealthInfoToSubnet(ctx context.Context, healthInfo interface{}, client
return e
}
}
compressedHealthInfo, e := mc.TarGZHealthInfo(healthInfo, madmin.HealthInfoVersion)
if e != nil {
return e
}
e = os.WriteFile(filename, compressedHealthInfo, 0o666)
if e != nil {
return e
Expand Down
9 changes: 5 additions & 4 deletions api/client-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type MinioAdmin interface {
addRemoteBucket(ctx context.Context, bucket string, target *madmin.BucketTarget) (string, error)
// Account password management
changePassword(ctx context.Context, accessKey, secretKey string) error
serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error)
serverHealthInfo(ctx context.Context, deadline time.Duration) (interface{}, string, error)
// List Tiers
listTiers(ctx context.Context) ([]*madmin.TierConfig, error)
// Tier Info
Expand Down Expand Up @@ -389,13 +389,15 @@ func (ac AdminClient) getBucketQuota(ctx context.Context, bucket string) (madmin
}

// serverHealthInfo implements mc.ServerHealthInfo - Connect to a minio server and call Health Info Management API
func (ac AdminClient) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error) {
func (ac AdminClient) serverHealthInfo(ctx context.Context, deadline time.Duration) (interface{}, string, error) {
info := madmin.HealthInfo{}
var healthInfo interface{}
var version string
var tryCount int
for info.Version == "" && tryCount < 10 {
resp, version, err := ac.Client.ServerHealthInfo(ctx, healthDataTypes, deadline, "")
var resp *http.Response
var err error
resp, version, err = ac.Client.ServerHealthInfo(ctx, madmin.HealthDataTypesList, deadline, "")
if err != nil {
return nil, version, err
}
Expand All @@ -407,7 +409,6 @@ func (ac AdminClient) serverHealthInfo(ctx context.Context, healthDataTypes []ma
}
tryCount++
time.Sleep(2 * time.Second)

}
if info.Version == "" {
return nil, "", ErrHealthReportFail
Expand Down

0 comments on commit 2aaee45

Please sign in to comment.