Skip to content

Commit

Permalink
DAOS-16127 tools: Include relevant pool health in container health (#…
Browse files Browse the repository at this point in the history
…15489)

If the parent pool is in a degraded state, show this in the container
health string, as otherwise users may only focus on the container
health and miss the other details.

Signed-off-by: Michael MacDonald <[email protected]>
  • Loading branch information
mjmac committed Dec 16, 2024
1 parent 8088155 commit 25deeb4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
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 @@ -132,12 +132,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 @@ -180,7 +184,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

0 comments on commit 25deeb4

Please sign in to comment.