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
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.

Required-githooks: true
Change-Id: Icc2fd74b5c4ca6d6c6ca84b790c99af6ee97f11a
Signed-off-by: Michael MacDonald <mjmac@google.com>
  • Loading branch information
mjmac committed Nov 11, 2024
1 parent d4070e8 commit a9a0132
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 @@ -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

0 comments on commit a9a0132

Please sign in to comment.