From db1b1bd8112c0ca94825bfd157e50fc17e3f3ff1 Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Thu, 1 Jul 2021 22:34:08 +0530 Subject: [PATCH] fix: health report incompatibility with old minio (#3751) When the subnet health command from current mc is used with the MinIO versions before the latest health data structure changes (v2) were introduced, the generated report doesn't contain the cluster information (minio -> info). This is because these old versions of minio don't return this information in the output of the `healthinfo` api. Fixed this by explicitly pulling the server info separately when we detect that the health schema version is not v2. --- cmd/admin-subnet-health.go | 20 ++++++++++++++++---- cmd/health_v1.go | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/admin-subnet-health.go b/cmd/admin-subnet-health.go index 3379d81d..26b5481a 100644 --- a/cmd/admin-subnet-health.go +++ b/cmd/admin-subnet-health.go @@ -486,8 +486,8 @@ func fetchServerHealthInfo(ctx *cli.Context, client *madmin.AdminClient) (interf decoder := json.NewDecoder(resp.Body) switch version { case madmin.HealthInfoVersion0: + info := madmin.HealthInfoV0{} for { - var info madmin.HealthInfoV0 if err = decoder.Decode(&info); err != nil { if errors.Is(err, io.EOF) { err = nil @@ -497,11 +497,23 @@ func fetchServerHealthInfo(ctx *cli.Context, client *madmin.AdminClient) (interf } progressV0(info) - healthInfo = MapHealthInfoToV1(info, nil) } + + // Old minio versions don't return the MinIO info in + // response of the healthinfo api. So fetch it separately + minioInfo, err := client.ServerInfo(globalContext) + if err != nil { + info.Minio.Error = err.Error() + } else { + info.Minio.Info = minioInfo + } + + healthInfo = MapHealthInfoToV1(info, nil) + version = madmin.HealthInfoVersion1 + case madmin.HealthInfoVersion: + info := madmin.HealthInfo{} for { - var info madmin.HealthInfo if err = decoder.Decode(&info); err != nil { if errors.Is(err, io.EOF) { err = nil @@ -511,8 +523,8 @@ func fetchServerHealthInfo(ctx *cli.Context, client *madmin.AdminClient) (interf } progress(info) - healthInfo = info } + healthInfo = info } // In case any of the spinners have not stopped yet (can happen in some diff --git a/cmd/health_v1.go b/cmd/health_v1.go index 863dabdb..2d40acc7 100644 --- a/cmd/health_v1.go +++ b/cmd/health_v1.go @@ -137,7 +137,7 @@ func (ch ClusterHealthV1) GetTimestamp() time.Time { } // MapHealthInfoToV1 - maps the health info returned by minio server to V1 format -func MapHealthInfoToV1(healthInfo madmin.HealthInfoV0, err error) HealthReportInfo { +func MapHealthInfoToV1(healthInfo madmin.HealthInfoV0, err error) ClusterHealthV1 { ch := ClusterHealthV1{} ch.TimeStamp = healthInfo.TimeStamp if err != nil {