mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00

--health-log-destination flags These flags can affect the output of the HealtCheck log. Currently, when a container is configured with HealthCheck, the output from the HealthCheck command is only logged to the container status file, which is accessible via `podman inspect`. It is also limited to the last five executions and the first 500 characters per execution. This makes debugging past problems very difficult, since the only information available about the failure of the HealthCheck command is the generic `healthcheck service failed` record. - The `--health-log-destination` flag sets the destination of the HealthCheck log. - `none`: (default behavior) `HealthCheckResults` are stored in overlay containers. (For example: `$runroot/healthcheck.log`) - `directory`: creates a log file named `<container-ID>-healthcheck.log` with JSON `HealthCheckResults` in the specified directory. - `events_logger`: The log will be written with logging mechanism set by events_loggeri. It also saves the log to a default directory, for performance on a system with a large number of logs. - The `--health-max-log-count` flag sets the maximum number of attempts in the HealthCheck log file. - A value of `0` indicates an infinite number of attempts in the log file. - The default value is `5` attempts in the log file. - The `--health-max-log-size` flag sets the maximum length of the log stored. - A value of `0` indicates an infinite log length. - The default value is `500` log characters. Add --health-max-log-count flag Signed-off-by: Jan Rodák <hony.com@seznam.cz> Add --health-max-log-size flag Signed-off-by: Jan Rodák <hony.com@seznam.cz> Add --health-log-destination flag Signed-off-by: Jan Rodák <hony.com@seznam.cz> (cherry picked from commit de856dab99ef8816392972347678fcb49ae57e50) Signed-off-by: Jan Rodák <hony.com@seznam.cz>
158 lines
5.9 KiB
Go
158 lines
5.9 KiB
Go
package define
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/containers/image/v5/manifest"
|
|
)
|
|
|
|
const (
|
|
// HealthCheckHealthy describes a healthy container
|
|
HealthCheckHealthy string = "healthy"
|
|
// HealthCheckUnhealthy describes an unhealthy container
|
|
HealthCheckUnhealthy string = "unhealthy"
|
|
// HealthCheckStarting describes the time between when the container starts
|
|
// and the start-period (time allowed for the container to start and application
|
|
// to be running) expires.
|
|
HealthCheckStarting string = "starting"
|
|
// HealthCheckReset describes reset of HealthCheck logs
|
|
HealthCheckReset string = "reset"
|
|
)
|
|
|
|
// HealthCheckStatus represents the current state of a container
|
|
type HealthCheckStatus int
|
|
|
|
const (
|
|
// HealthCheckSuccess means the health worked
|
|
HealthCheckSuccess HealthCheckStatus = iota
|
|
// HealthCheckFailure means the health ran and failed
|
|
HealthCheckFailure HealthCheckStatus = iota
|
|
// HealthCheckContainerStopped means the health check cannot
|
|
// be run because the container is stopped
|
|
HealthCheckContainerStopped HealthCheckStatus = iota
|
|
// HealthCheckContainerNotFound means the container could
|
|
// not be found in local store
|
|
HealthCheckContainerNotFound HealthCheckStatus = iota
|
|
// HealthCheckNotDefined means the container has no health
|
|
// check defined in it
|
|
HealthCheckNotDefined HealthCheckStatus = iota
|
|
// HealthCheckInternalError means some something failed obtaining or running
|
|
// a given health check
|
|
HealthCheckInternalError HealthCheckStatus = iota
|
|
// HealthCheckDefined means the healthcheck was found on the container
|
|
HealthCheckDefined HealthCheckStatus = iota
|
|
// HealthCheckStartup means the healthcheck was unhealthy, but is still
|
|
// either within the startup HC or the startup period of the healthcheck
|
|
HealthCheckStartup HealthCheckStatus = iota
|
|
)
|
|
|
|
// Healthcheck defaults. These are used both in the cli as well in
|
|
// libpod and were moved from cmd/podman/common
|
|
const (
|
|
// DefaultHealthCheckInterval default value
|
|
DefaultHealthCheckInterval = "30s"
|
|
// DefaultHealthCheckRetries default value
|
|
DefaultHealthCheckRetries uint = 3
|
|
// DefaultHealthCheckStartPeriod default value
|
|
DefaultHealthCheckStartPeriod = "0s"
|
|
// DefaultHealthCheckTimeout default value
|
|
DefaultHealthCheckTimeout = "30s"
|
|
// DefaultHealthMaxLogCount default value
|
|
DefaultHealthMaxLogCount uint = 5
|
|
// DefaultHealthMaxLogSize default value
|
|
DefaultHealthMaxLogSize uint = 500
|
|
// DefaultHealthCheckLocalDestination default value
|
|
DefaultHealthCheckLocalDestination string = "local"
|
|
)
|
|
|
|
const HealthCheckEventsLoggerDestination string = "events_logger"
|
|
|
|
// HealthConfig.Test options
|
|
const (
|
|
// HealthConfigTestNone disables healthcheck
|
|
HealthConfigTestNone = "NONE"
|
|
// HealthConfigTestCmd execs arguments directly
|
|
HealthConfigTestCmd = "CMD"
|
|
// HealthConfigTestCmdShell runs commands with the system's default shell
|
|
HealthConfigTestCmdShell = "CMD-SHELL"
|
|
)
|
|
|
|
// HealthCheckOnFailureAction defines how Podman reacts when a container's health
|
|
// status turns unhealthy.
|
|
type HealthCheckOnFailureAction int
|
|
|
|
// Healthcheck on-failure actions.
|
|
const (
|
|
// HealthCheckOnFailureActionNonce instructs Podman to not react on an unhealthy status.
|
|
HealthCheckOnFailureActionNone = iota // Must be first iota for backwards compatibility
|
|
// HealthCheckOnFailureActionInvalid denotes an invalid on-failure policy.
|
|
HealthCheckOnFailureActionInvalid = iota
|
|
// HealthCheckOnFailureActionNonce instructs Podman to kill the container on an unhealthy status.
|
|
HealthCheckOnFailureActionKill = iota
|
|
// HealthCheckOnFailureActionNonce instructs Podman to restart the container on an unhealthy status.
|
|
HealthCheckOnFailureActionRestart = iota
|
|
// HealthCheckOnFailureActionNonce instructs Podman to stop the container on an unhealthy status.
|
|
HealthCheckOnFailureActionStop = iota
|
|
)
|
|
|
|
// String representations for on-failure actions.
|
|
const (
|
|
strHealthCheckOnFailureActionNone = "none"
|
|
strHealthCheckOnFailureActionInvalid = "invalid"
|
|
strHealthCheckOnFailureActionKill = "kill"
|
|
strHealthCheckOnFailureActionRestart = "restart"
|
|
strHealthCheckOnFailureActionStop = "stop"
|
|
)
|
|
|
|
// SupportedHealthCheckOnFailureActions lists all supported healthcheck restart policies.
|
|
var SupportedHealthCheckOnFailureActions = []string{
|
|
strHealthCheckOnFailureActionNone,
|
|
strHealthCheckOnFailureActionKill,
|
|
strHealthCheckOnFailureActionRestart,
|
|
strHealthCheckOnFailureActionStop,
|
|
}
|
|
|
|
// String returns the string representation of the HealthCheckOnFailureAction.
|
|
func (h HealthCheckOnFailureAction) String() string {
|
|
switch h {
|
|
case HealthCheckOnFailureActionNone:
|
|
return strHealthCheckOnFailureActionNone
|
|
case HealthCheckOnFailureActionKill:
|
|
return strHealthCheckOnFailureActionKill
|
|
case HealthCheckOnFailureActionRestart:
|
|
return strHealthCheckOnFailureActionRestart
|
|
case HealthCheckOnFailureActionStop:
|
|
return strHealthCheckOnFailureActionStop
|
|
default:
|
|
return strHealthCheckOnFailureActionInvalid
|
|
}
|
|
}
|
|
|
|
// ParseHealthCheckOnFailureAction parses the specified string into a HealthCheckOnFailureAction.
|
|
// An error is returned for an invalid input.
|
|
func ParseHealthCheckOnFailureAction(s string) (HealthCheckOnFailureAction, error) {
|
|
switch s {
|
|
case "", strHealthCheckOnFailureActionNone:
|
|
return HealthCheckOnFailureActionNone, nil
|
|
case strHealthCheckOnFailureActionKill:
|
|
return HealthCheckOnFailureActionKill, nil
|
|
case strHealthCheckOnFailureActionRestart:
|
|
return HealthCheckOnFailureActionRestart, nil
|
|
case strHealthCheckOnFailureActionStop:
|
|
return HealthCheckOnFailureActionStop, nil
|
|
default:
|
|
err := fmt.Errorf("invalid on-failure action %q for health check: supported actions are %s", s, strings.Join(SupportedHealthCheckOnFailureActions, ","))
|
|
return HealthCheckOnFailureActionInvalid, err
|
|
}
|
|
}
|
|
|
|
// StartupHealthCheck is the configuration of a startup healthcheck.
|
|
type StartupHealthCheck struct {
|
|
manifest.Schema2HealthConfig
|
|
// Successes are the number of successes required to mark the startup HC
|
|
// as passed.
|
|
// If set to 0, a single success will mark the HC as passed.
|
|
Successes int `json:",omitempty"`
|
|
}
|