Skip to content

Commit

Permalink
account for exited but not because it was fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Apr 3, 2024
1 parent e6ddaf9 commit d42de1c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions check_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
)

type Result struct {
Name string
Fatal bool
Healthy bool
HasCheck bool
Logs string
ProbeLogs string
Name string // Name of the container
Fatal bool // True if the container is exited with a non-zero exit code.
Healthy bool // True if the container is healthy, false if probe is failing
HasCheck bool // True if the container has a health check
Logs string // Logs of the container
ProbeLogs string // Logs of the probe
}

// map[container name]result
type Results map[string]Result

var flag_name string
Expand Down Expand Up @@ -140,10 +141,15 @@ func checkContainer(c d_types.Container, checksCh chan Result) {
res.HasCheck, _ = hasHealthCheck(c.ID)
res.Name = getContainerName(c.Names)
running, _ := isRunning(c.ID)
exitCode, _ := getExitCode(c.ID)
if !running {
res.Fatal = true
if exitCode != 0 {
res.Fatal = true
res.ProbeLogs, _ = getFailedProbeLogs(c.ID)
} else {
res.Healthy = false
}
res.Logs, _ = getLogs(c.ID)
res.ProbeLogs, _ = getFailedProbeLogs(c.ID)
checksCh <- res
return
}
Expand Down Expand Up @@ -201,6 +207,14 @@ func isRunning(cID string) (bool, error) {

return container.State.Running, nil
}
func getExitCode(cID string) (int, error) {
container, err := apiClient.ContainerInspect(context.Background(), cID)
if err != nil {
return 0, fmt.Errorf("failed to inspect container: %w", err)
}

return container.State.ExitCode, nil
}

// getHealth returns the health status of the container
func getHealth(cID string) (string, error) {
Expand Down

0 comments on commit d42de1c

Please sign in to comment.