Skip to content

Commit 2d69150

Browse files
vadmestekannappanr
authored andcommitted
Show background heal stats in mc admin heal (minio#2808)
1 parent 98e88c2 commit 2d69150

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

cmd/admin-heal.go

+41-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package cmd
1818

1919
import (
20+
"fmt"
2021
"path/filepath"
2122
"strings"
23+
"time"
2224

2325
"github.com/fatih/color"
2426
"github.com/minio/cli"
@@ -133,6 +135,30 @@ func (s stopHealMessage) JSON() string {
133135
return string(stopHealJSONBytes)
134136
}
135137

138+
// backgroundHealStatusMessage is container for stop heal success and failure messages.
139+
type backgroundHealStatusMessage struct {
140+
Status string `json:"status"`
141+
HealInfo madmin.BgHealState
142+
}
143+
144+
// String colorized to show background heal status message.
145+
func (s backgroundHealStatusMessage) String() string {
146+
healPrettyMsg := console.Colorize("HealBackgroundTitle", "Background healing status:\n")
147+
healPrettyMsg += fmt.Sprintf(" Total items scanned: %s\n",
148+
console.Colorize("HealBackground", s.HealInfo.ScannedItemsCount))
149+
healPrettyMsg += fmt.Sprintf(" Last background heal check: %s\n",
150+
console.Colorize("HealBackground", timeDurationToHumanizedDuration(time.Since(s.HealInfo.LastHealActivity)).String()+" ago"))
151+
return healPrettyMsg
152+
}
153+
154+
// JSON jsonified stop heal message.
155+
func (s backgroundHealStatusMessage) JSON() string {
156+
healJSONBytes, e := json.MarshalIndent(s, "", " ")
157+
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
158+
159+
return string(healJSONBytes)
160+
}
161+
136162
func transformScanArg(scanArg string) madmin.HealScanMode {
137163
switch scanArg {
138164
case "deep":
@@ -152,6 +178,8 @@ func mainAdminHeal(ctx *cli.Context) error {
152178
aliasedURL := args.Get(0)
153179

154180
console.SetColor("Heal", color.New(color.FgGreen, color.Bold))
181+
console.SetColor("HealBackgroundTitle", color.New(color.FgGreen, color.Bold))
182+
console.SetColor("HealBackground", color.New(color.Bold))
155183
console.SetColor("HealUpdateUI", color.New(color.FgYellow, color.Bold))
156184
console.SetColor("HealStopped", color.New(color.FgGreen, color.Bold))
157185

@@ -167,6 +195,15 @@ func mainAdminHeal(ctx *cli.Context) error {
167195
splits := splitStr(aliasedURL, "/", 3)
168196
bucket, prefix := splits[1], splits[2]
169197

198+
// Return the background heal status when the user
199+
// doesn't pass a bucket or --recursive flag.
200+
if bucket == "" && !ctx.Bool("recursive") {
201+
bgHealStatus, berr := client.BackgroundHealStatus()
202+
fatalIf(probe.NewError(berr), "Failed to get the status of the background heal.")
203+
printMsg(backgroundHealStatusMessage{Status: "success", HealInfo: bgHealStatus})
204+
return nil
205+
}
206+
170207
opts := madmin.HealOpts{
171208
ScanMode: transformScanArg(ctx.String("scan")),
172209
Remove: ctx.Bool("remove"),
@@ -178,13 +215,13 @@ func mainAdminHeal(ctx *cli.Context) error {
178215
forceStop := ctx.Bool("force-stop")
179216
if forceStop {
180217
_, _, herr := client.Heal(bucket, prefix, opts, "", forceStart, forceStop)
181-
errorIf(probe.NewError(herr), "Failed to stop heal sequence.")
218+
fatalIf(probe.NewError(herr), "Failed to stop heal sequence.")
182219
printMsg(stopHealMessage{Status: "success", Alias: aliasedURL})
183220
return nil
184221
}
185222

186223
healStart, _, herr := client.Heal(bucket, prefix, opts, "", forceStart, false)
187-
errorIf(probe.NewError(herr), "Failed to start heal sequence.")
224+
fatalIf(probe.NewError(herr), "Failed to start heal sequence.")
188225

189226
ui := uiData{
190227
Bucket: bucket,
@@ -203,9 +240,9 @@ func mainAdminHeal(ctx *cli.Context) error {
203240
if res.FailureDetail != "" {
204241
data, _ := json.MarshalIndent(res, "", " ")
205242
traceStr := string(data)
206-
errorIf(probe.NewError(e).Trace(aliasedURL, traceStr), "Unable to display heal status.")
243+
fatalIf(probe.NewError(e).Trace(aliasedURL, traceStr), "Unable to display heal status.")
207244
} else {
208-
errorIf(probe.NewError(e).Trace(aliasedURL), "Unable to display heal status.")
245+
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to display heal status.")
209246
}
210247
}
211248
return nil

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/mattn/go-isatty v0.0.7
2323
github.com/mattn/go-runewidth v0.0.4 // indirect
2424
github.com/minio/cli v1.20.0
25-
github.com/minio/minio v0.0.0-20190619212803-35c38e4bd893
25+
github.com/minio/minio v0.0.0-20190626173654-be72609d1f8f
2626
github.com/minio/minio-go v0.0.0-20190327203652-5325257a208f // indirect
2727
github.com/minio/minio-go/v6 v6.0.29
2828
github.com/minio/sha256-simd v0.1.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ github.com/minio/minio v0.0.0-20190325204105-0250f7de678b/go.mod h1:6ODmvb06uOpN
397397
github.com/minio/minio v0.0.0-20190510004154-ac3b59645e92/go.mod h1:yFbQSwuA61mB/SDurPvsaSydqDyJdfAlBYpMiEe1lz8=
398398
github.com/minio/minio v0.0.0-20190619212803-35c38e4bd893 h1:3vaOD8YTz5F6gp7BC66sDGN2Hj4x0lUxigG/rCSw0lo=
399399
github.com/minio/minio v0.0.0-20190619212803-35c38e4bd893/go.mod h1:E4YtMxTbDvy5kxqZYpHPJ427GowUH7GiQXIg68ctM8s=
400+
github.com/minio/minio v0.0.0-20190626173654-be72609d1f8f h1:MAaUl4XTytIdhQTaB4fI5FbclAUEKly+ELbVw1vN2tE=
401+
github.com/minio/minio v0.0.0-20190626173654-be72609d1f8f/go.mod h1:E4YtMxTbDvy5kxqZYpHPJ427GowUH7GiQXIg68ctM8s=
400402
github.com/minio/minio-go v0.0.0-20190227180923-59af836a7e6d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
401403
github.com/minio/minio-go v0.0.0-20190313212832-5d20267d970d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
402404
github.com/minio/minio-go v0.0.0-20190327203652-5325257a208f h1:u+iNxfkLrfyWp7KxSTV+ZhO4SMHT6qUFxSZ6yhYMQ0Q=

0 commit comments

Comments
 (0)