Skip to content

Commit

Permalink
ILM expiry replication details for mc admin replicatte status
Browse files Browse the repository at this point in the history
Signed-off-by: Shubhendu Ram Tripathi <[email protected]>
  • Loading branch information
shtripat committed Oct 20, 2023
1 parent 3d44ab0 commit 62aa11c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 10 deletions.
115 changes: 108 additions & 7 deletions cmd/admin-replicate-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ var adminReplicateStatusFlags = []cli.Flag{
Name: "groups",
Usage: "display only groups",
},
cli.BoolFlag{
Name: "ilm-expiry-rules",
Usage: "display only ilm expiry rules",
},
cli.BoolFlag{
Name: "all",
Usage: "display all available site replication status",
Expand All @@ -70,6 +74,10 @@ var adminReplicateStatusFlags = []cli.Flag{
Name: "group",
Usage: "display group sync status",
},
cli.StringFlag{
Name: "ilm-expiry-rule",
Usage: "display ILM expiry rule sync status",
},
}

// Some cell values
Expand Down Expand Up @@ -312,6 +320,42 @@ func (i srStatus) String() string {
}
}
}
if i.opts.ILMExpiryRules {
messages = append(messages,
console.Colorize("SummaryHdr", "ILM Expiry Rules replication status:"))
switch {
case i.MaxILMExpiryRules == 0:
messages = append(messages, console.Colorize("Summary", "No ILM Expiry Rules present\n"))
default:
msg := console.Colorize(i.getTheme(len(info.ILMExpiryStats) == 0), fmt.Sprintf("%d/%d ILM Expiry Rules in sync", info.MaxILMExpiryRules-len(info.ILMExpiryStats), info.MaxILMExpiryRules)) + "\n"
messages = append(messages, fmt.Sprintf("%s %s", coloredDot, msg))
if len(i.ILMExpiryStats) > 0 {
messages = append(messages, i.siteHeader(siteNames, "ILM Expiry Rules"))
}
var detailFields []Field
for b, ssMap := range i.ILMExpiryStats {
var details []string
details = append(details, b)
detailFields = append(detailFields, legendFields[0])
for _, sname := range siteNames {
detailFields = append(detailFields, legendFields[0])
dID := nameIDMap[sname]
ss := ssMap[dID]
switch {
case !ss.HasILMExpiryRules:
details = append(details, blankCell)
case ss.ILMExpiryRuleMismatch:
details = append(details, fmt.Sprintf("%s in-sync", crossTickCell))
default:
details = append(details, fmt.Sprintf("%s in-sync", tickCell))
}
}
messages = append(messages, newPrettyTable(" | ",
detailFields...).buildRow(details...))
messages = append(messages, "")
}
}
}

switch i.opts.Entity {
case madmin.SRBucketEntity:
Expand All @@ -322,7 +366,8 @@ func (i srStatus) String() string {
messages = append(messages, i.getUserStatusSummary(siteNames, nameIDMap, "User")...)
case madmin.SRGroupEntity:
messages = append(messages, i.getGroupStatusSummary(siteNames, nameIDMap, "Group")...)

case madmin.SRILMExpiryRuleEntity:
messages = append(messages, i.getILMExpiryStatusSummary(siteNames, nameIDMap, "ILMExpiryRule")...)
}
if i.opts.Metrics {
uiFn := func(theme string) func(string) string {
Expand Down Expand Up @@ -716,29 +761,85 @@ func (i srStatus) getGroupStatusSummary(siteNames []string, nameIDMap map[string
return messages
}

func (i srStatus) getILMExpiryStatusSummary(siteNames []string, nameIDMap map[string]string, legend string) []string {
var messages []string
coloredDot := console.Colorize("Status", dot)
var found bool
for _, st := range i.SRStatusInfo.ILMExpiryStats[i.opts.EntityValue] {
if st.HasILMExpiryRules {
found = true
break
}
}
if !found {
messages = append(messages, console.Colorize("Summary", fmt.Sprintf("ILM Expiry Rule %s not found\n", i.opts.EntityValue)))
return messages
}

rowLegend := []string{"ILM Expiry Rule"}
detailFields := make([][]Field, len(rowLegend))

var rules []string
detailFields[0] = make([]Field, len(siteNames)+1)
detailFields[0][0] = Field{"Entity", 15}
rules = append(rules, "ILM Expiry Rule")
rows := make([]string, len(rowLegend))
for j, sname := range siteNames {
dID := nameIDMap[sname]
ss := i.SRStatusInfo.ILMExpiryStats[i.opts.EntityValue][dID]
var theme, msgStr string
for r := range rowLegend {
switch r {
case 0:
theme, msgStr = syncStatus(ss.ILMExpiryRuleMismatch, ss.HasILMExpiryRules)
rules = append(rules, msgStr)
detailFields[r][j+1] = Field{theme, fieldLen}
}
}
}
for r := range rowLegend {
switch r {
case 0:
rows[r] = newPrettyTable(" | ",
detailFields[r]...).buildRow(rules...)
}
}
messages = append(messages,
console.Colorize("SummaryHdr", fmt.Sprintf("%s %s\n", coloredDot, console.Colorize("Summary", "ILM Expiry Rule replication summary for: ")+console.Colorize("UserMessage", i.opts.EntityValue))))
siteHdr := i.siteHeader(siteNames, legend)
messages = append(messages, siteHdr)

messages = append(messages, rows...)
return messages
}

// Calculate srstatus options for command line flags
func srStatusOpts(ctx *cli.Context) (opts madmin.SRStatusOptions) {
if !(ctx.IsSet("buckets") ||
ctx.IsSet("users") ||
ctx.IsSet("groups") ||
ctx.IsSet("policies") ||
ctx.IsSet("ilm-expiry-rules") ||
ctx.IsSet("bucket") ||
ctx.IsSet("user") ||
ctx.IsSet("group") ||
ctx.IsSet("policy") ||
ctx.IsSet("ilm-expiry-rule") ||
ctx.IsSet("all")) || ctx.IsSet("all") {
opts.Buckets = true
opts.Users = true
opts.Groups = true
opts.Policies = true
opts.Metrics = true
opts.ILMExpiryRules = true
return
}
opts.Buckets = ctx.Bool("buckets")
opts.Policies = ctx.Bool("policies")
opts.Users = ctx.Bool("users")
opts.Groups = ctx.Bool("groups")
for _, name := range []string{"bucket", "user", "group", "policy"} {
opts.ILMExpiryRules = ctx.Bool("ilm-expiry-rules")
for _, name := range []string{"bucket", "user", "group", "policy", "ilm-expiry-rule"} {
if ctx.IsSet(name) {
opts.Entity = madmin.GetSREntityType(name)
opts.EntityValue = ctx.String(name)
Expand All @@ -756,13 +857,13 @@ func mainAdminReplicationStatus(ctx *cli.Context) error {
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
"Need exactly one alias argument.")
}
groupStatus := ctx.IsSet("buckets") || ctx.IsSet("groups") || ctx.IsSet("users") || ctx.IsSet("policies")
indivStatus := ctx.IsSet("bucket") || ctx.IsSet("group") || ctx.IsSet("user") || ctx.IsSet("policy")
groupStatus := ctx.IsSet("buckets") || ctx.IsSet("groups") || ctx.IsSet("users") || ctx.IsSet("policies") || ctx.IsSet("ilm-expiry-rules")
indivStatus := ctx.IsSet("bucket") || ctx.IsSet("group") || ctx.IsSet("user") || ctx.IsSet("policy") || ctx.IsSet("ilm-expiry-rule")
if groupStatus && indivStatus {
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
"Cannot specify both (bucket|group|policy|user) flag and one or more of buckets|groups|policies|users) flag(s)")
"Cannot specify both (bucket|group|policy|user|ilm-expiry-rule) flag and one or more of buckets|groups|policies|users|ilm-expiry-rules) flag(s)")
}
setSlc := []bool{ctx.IsSet("bucket"), ctx.IsSet("user"), ctx.IsSet("group"), ctx.IsSet("policy")}
setSlc := []bool{ctx.IsSet("bucket"), ctx.IsSet("user"), ctx.IsSet("group"), ctx.IsSet("policy"), ctx.IsSet("ilm-expiry-rule")}
count := 0
for _, s := range setSlc {
if s {
Expand All @@ -771,7 +872,7 @@ func mainAdminReplicationStatus(ctx *cli.Context) error {
}
if count > 1 {
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
"Cannot specify more than one of --bucket, --policy, --user, --group flags at the same time")
"Cannot specify more than one of --bucket, --policy, --user, --group, --ilm-expiry-rule flags at the same time")
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
)

replace github.com/minio/madmin-go/v3 v3.0.21 => github.com/shtripat/madmin-go/v3 v3.0.0-20231017111648-65788bbf47a1
replace github.com/minio/madmin-go/v3 v3.0.21 => github.com/shtripat/madmin-go/v3 v3.0.0-20231020072222-a21f11ac3241
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFt
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shtripat/madmin-go/v3 v3.0.0-20231017111648-65788bbf47a1 h1:FkfzyBLsLM5uX4+cdaMfuY+6WDos/VB9lOHeyviKhZE=
github.com/shtripat/madmin-go/v3 v3.0.0-20231017111648-65788bbf47a1/go.mod h1:B2EgtEGrfWx+AkXv+OAcS6IHwoIJcd1p75QfDPSPd6Q=
github.com/shtripat/madmin-go/v3 v3.0.0-20231020072222-a21f11ac3241 h1:WIAk4NUibHK8NXgEsjmDWbmSPvdewoVqQTQF+gh8qm4=
github.com/shtripat/madmin-go/v3 v3.0.0-20231020072222-a21f11ac3241/go.mod h1:B2EgtEGrfWx+AkXv+OAcS6IHwoIJcd1p75QfDPSPd6Q=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit 62aa11c

Please sign in to comment.