Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-16127 tools: Include relevant pool health in container health #15489

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/control/cmd/daos/pretty/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ func printPoolHealth(out io.Writer, pi *daos.PoolInfo, verbose bool) {
fmt.Fprintf(out, "%s: %s\n", pi.Name(), strings.Join(healthStrings, ","))
}

func printContainerHealth(out io.Writer, ci *daos.ContainerInfo, verbose bool) {
func printContainerHealth(out io.Writer, pi *daos.PoolInfo, ci *daos.ContainerInfo, verbose bool) {
if ci == nil {
return
}

fmt.Fprintf(out, "%s: %s\n", ci.Name(), txtfmt.Title(ci.Health))
healthStr := txtfmt.Title(ci.Health)
if pi != nil && pi.DisabledTargets > 0 {
healthStr += " (Pool Degraded)"
}
fmt.Fprintf(out, "%s: %s\n", ci.Name(), healthStr)
}

// PrintSystemHealthInfo pretty-prints the supplied system health struct.
Expand Down Expand Up @@ -173,7 +177,7 @@ func PrintSystemHealthInfo(out io.Writer, shi *daos.SystemHealthInfo, verbose bo
iiiw := txtfmt.NewIndentWriter(iiw)
if len(shi.Containers[pool.UUID]) > 0 {
for _, cont := range shi.Containers[pool.UUID] {
printContainerHealth(iiiw, cont, verbose)
printContainerHealth(iiiw, pool, cont, verbose)
}
} else {
fmt.Fprintln(iiiw, "No containers in pool.")
Expand Down
39 changes: 37 additions & 2 deletions src/control/cmd/daos/pretty/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,47 @@ var healthyContainer = &daos.ContainerInfo{

func TestPretty_printContainerHealth(t *testing.T) {
for name, tc := range map[string]struct {
pi *daos.PoolInfo
ci *daos.ContainerInfo
verbose bool
expPrintStr string
}{
"nil ContainerInfo": {},
"healthy": {
"unhealthy pool, healthy container": {
pi: &daos.PoolInfo{
DisabledTargets: 1,
},
ci: healthyContainer,
expPrintStr: fmt.Sprintf(`
%s: Healthy (Pool Degraded)
`, healthyContainer.ContainerLabel),
},
"unhealthy pool, unhealthy container": {
pi: &daos.PoolInfo{
DisabledTargets: 1,
},
ci: func() *daos.ContainerInfo {
clone := *healthyContainer
clone.Health = "UNHEALTHY"
return &clone
}(),
expPrintStr: fmt.Sprintf(`
%s: Unhealthy (Pool Degraded)
`, healthyContainer.ContainerLabel),
},
"healthy pool, unhealthy container": {
pi: healthyPool,
ci: func() *daos.ContainerInfo {
clone := *healthyContainer
clone.Health = "UNHEALTHY"
return &clone
}(),
expPrintStr: fmt.Sprintf(`
%s: Unhealthy
`, healthyContainer.ContainerLabel),
},
"healthy pool, healthy container": {
pi: healthyPool,
ci: healthyContainer,
expPrintStr: fmt.Sprintf(`
%s: Healthy
Expand All @@ -305,7 +340,7 @@ func TestPretty_printContainerHealth(t *testing.T) {
} {
t.Run(name, func(t *testing.T) {
var bld strings.Builder
printContainerHealth(&bld, tc.ci, tc.verbose)
printContainerHealth(&bld, tc.pi, tc.ci, tc.verbose)

if diff := cmp.Diff(strings.TrimLeft(tc.expPrintStr, "\n"), bld.String()); diff != "" {
t.Fatalf("unexpected pretty-printed string (-want, +got):\n%s\n", diff)
Expand Down
Loading