From c78c66aa4abf8a1f3a957da5072a6da25fdb077e Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Wed, 13 Nov 2024 13:52:13 +0100 Subject: [PATCH] heal: Simplify bucket healing status Avoid using drive count concept to pick a color for a bucket healing result. This was straighforward when we were healing a bucket per erasure set but now it becomes more complex to show a result. Pick green if everything is okay, yellow if a bucket is missing in a drive, red for any other drive state (unformatted, offline, ..) and grey for any weird situation. --- cmd/admin-heal-result-item.go | 41 +++++++++++++++++++++++++++++++++++ cmd/admin-heal-ui.go | 12 +++++++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/cmd/admin-heal-result-item.go b/cmd/admin-heal-result-item.go index e5acc512f2..dcdc9a6ac0 100644 --- a/cmd/admin-heal-result-item.go +++ b/cmd/admin-heal-result-item.go @@ -18,6 +18,7 @@ package cmd import ( + "errors" "fmt" "github.com/minio/madmin-go/v3" @@ -55,6 +56,46 @@ func (h hri) getObjectHCCChange() (b, a col, err error) { return } +// getBucketHCCChange - fetches health color code for bucket healing +// this does not return a Grey color since it does not have any meaning +// for a bucket healing. Return green if the bucket is found in a drive, +// yellow for missing, and red for everything else, grey for weird situations +func (h hri) getBucketHCCChange() (b, a col, err error) { + if h.HealResultItem == nil { + return colGrey, colGrey, errors.New("empty result") + } + + getColCode := func(drives []madmin.HealDriveInfo) (c col) { + var missing, unavailable int + for i := range drives { + switch drives[i].State { + case madmin.DriveStateOk: + case madmin.DriveStateMissing: + missing++ + default: + unavailable++ + } + } + if unavailable > 0 { + return colRed + } + if missing > 0 { + return colYellow + } + return colGreen + } + + a, b = colGrey, colGrey + + if len(h.HealResultItem.Before.Drives) > 0 { + b = getColCode(h.HealResultItem.Before.Drives) + } + if len(h.HealResultItem.After.Drives) > 0 { + a = getColCode(h.HealResultItem.After.Drives) + } + return +} + // getReplicatedFileHCCChange - fetches health color code for metadata // files that are replicated. func (h hri) getReplicatedFileHCCChange() (b, a col, err error) { diff --git a/cmd/admin-heal-ui.go b/cmd/admin-heal-ui.go index 8c15f10f3a..f0a2ea96f2 100644 --- a/cmd/admin-heal-ui.go +++ b/cmd/admin-heal-ui.go @@ -127,7 +127,9 @@ func (ui *uiData) updateStats(i madmin.HealResultItem) error { var afterCol col h := newHRI(&i) switch h.Type { - case madmin.HealItemMetadata, madmin.HealItemBucket: + case madmin.HealItemBucket: + _, afterCol, err = h.getBucketHCCChange() + case madmin.HealItemMetadata, madmin.HealItemBucketMetadata: _, afterCol, err = h.getReplicatedFileHCCChange() default: _, afterCol, err = h.getObjectHCCChange() @@ -206,7 +208,9 @@ func (ui *uiData) printItemsQuietly(s *madmin.HealTaskStatus) (err error) { for _, item := range s.Items { h := newHRI(&item) switch h.Type { - case madmin.HealItemMetadata, madmin.HealItemBucket: + case madmin.HealItemBucket: + b, a, err = h.getBucketHCCChange() + case madmin.HealItemMetadata, madmin.HealItemBucketMetadata: b, a, err = h.getReplicatedFileHCCChange() default: b, a, err = h.getObjectHCCChange() @@ -267,7 +271,9 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) { var b, a col var err error switch h.Type { - case madmin.HealItemMetadata, madmin.HealItemBucket: + case madmin.HealItemBucket: + b, a, err = h.getBucketHCCChange() + case madmin.HealItemMetadata, madmin.HealItemBucketMetadata: b, a, err = h.getReplicatedFileHCCChange() default: if h.Type == madmin.HealItemObject {