Skip to content

Commit e40738b

Browse files
Merge pull request #24216 from Honny1/dev/jrodak/healthcheck-log
[v5.2-rhel] Add --health-max-log-count, --health-max-log-size, --health-log-destination flags
2 parents 39171ac + d8eef21 commit e40738b

33 files changed

+701
-238
lines changed

cmd/podman/common/create.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
184184
)
185185
_ = cmd.RegisterFlagCompletionFunc(healthIntervalFlagName, completion.AutocompleteNone)
186186

187+
healthLogDestinationFlagName := "health-log-destination"
188+
createFlags.StringVar(
189+
&cf.HealthLogDestination,
190+
healthLogDestinationFlagName, define.DefaultHealthCheckLocalDestination,
191+
"set the destination of the HealthCheck log. Directory path, local or events_logger (local use container state file)",
192+
)
193+
_ = cmd.RegisterFlagCompletionFunc(healthLogDestinationFlagName, completion.AutocompleteNone)
194+
195+
healthMaxLogCountFlagName := "health-max-log-count"
196+
createFlags.UintVar(
197+
&cf.HealthMaxLogCount,
198+
healthMaxLogCountFlagName, define.DefaultHealthMaxLogCount,
199+
"set maximum number of attempts in the HealthCheck log file. ('0' value means an infinite number of attempts in the log file)",
200+
)
201+
_ = cmd.RegisterFlagCompletionFunc(healthMaxLogCountFlagName, completion.AutocompleteNone)
202+
203+
healthMaxLogSizeFlagName := "health-max-log-size"
204+
createFlags.UintVar(
205+
&cf.HealthMaxLogSize,
206+
healthMaxLogSizeFlagName, define.DefaultHealthMaxLogSize,
207+
"set maximum length in characters of stored HealthCheck log. ('0' value means an infinite log length)",
208+
)
209+
_ = cmd.RegisterFlagCompletionFunc(healthMaxLogSizeFlagName, completion.AutocompleteNone)
210+
187211
healthRetriesFlagName := "health-retries"
188212
createFlags.UintVar(
189213
&cf.HealthRetries,

cmd/podman/common/create_opts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,7 @@ func DefineCreateDefaults(opts *entities.ContainerCreateOptions) {
8585
opts.Ulimit = ulimits()
8686
opts.SeccompPolicy = "default"
8787
opts.Volume = volumes()
88+
opts.HealthLogDestination = define.DefaultHealthCheckLocalDestination
89+
opts.HealthMaxLogCount = define.DefaultHealthMaxLogCount
90+
opts.HealthMaxLogSize = define.DefaultHealthMaxLogSize
8891
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
####> This option file is used in:
2+
####> podman create, run
3+
####> If file is edited, make sure the changes
4+
####> are applicable to all of those.
5+
#### **--health-log-destination**=*directory_path*
6+
7+
Set the destination of the HealthCheck log. Directory path, local or events_logger (local use container state file) (Default: local)
8+
9+
* `local`: (default) HealthCheck logs are stored in overlay containers. (For example: `$runroot/healthcheck.log`)
10+
* `directory`: creates a log file named `<container-ID>-healthcheck.log` with HealthCheck logs in the specified directory.
11+
* `events_logger`: The log will be written with logging mechanism set by events_logger. It also saves the log to a default directory, for performance on a system with a large number of logs.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
####> This option file is used in:
2+
####> podman create, run
3+
####> If file is edited, make sure the changes
4+
####> are applicable to all of those.
5+
#### **--health-max-log-count**=*number of stored logs*
6+
7+
Set maximum number of attempts in the HealthCheck log file. ('0' value means an infinite number of attempts in the log file) (Default: 5 attempts)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
####> This option file is used in:
2+
####> podman create, run
3+
####> If file is edited, make sure the changes
4+
####> are applicable to all of those.
5+
#### **--health-max-log-size**=*size of stored logs*
6+
7+
Set maximum length in characters of stored HealthCheck log. ("0" value means an infinite log length) (Default: 500 characters)

docs/source/markdown/podman-create.1.md.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ See [**Environment**](#environment) note below for precedence and examples.
169169

170170
@@option health-interval
171171

172+
@@option health-log-destination
173+
174+
@@option health-max-log-count
175+
176+
@@option health-max-log-size
177+
172178
@@option health-on-failure
173179

174180
@@option health-retries

docs/source/markdown/podman-run.1.md.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ See [**Environment**](#environment) note below for precedence and examples.
203203

204204
@@option health-interval
205205

206+
@@option health-log-destination
207+
208+
@@option health-max-log-count
209+
210+
@@option health-max-log-size
211+
206212
@@option health-on-failure
207213

208214
@@option health-retries

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ Valid options for `[Container]` are listed below:
267267
| GroupAdd=keep-groups | --group-add=keep-groups |
268268
| HealthCmd=/usr/bin/command | --health-cmd=/usr/bin/command |
269269
| HealthInterval=2m | --health-interval=2m |
270+
| HealthLogDestination=/foo/log | --health-log-destination=/foo/log |
271+
| HealthMaxLogCount=5 | --health-max-log-count=5 |
272+
| HealthMaxLogSize=500 | --health-max-log-size=500 |
270273
| HealthOnFailure=kill | --health-on-failure=kill |
271274
| HealthRetries=5 | --health-retries=5 |
272275
| HealthStartPeriod=1m | --health-start-period=period=1m |
@@ -475,6 +478,28 @@ Equivalent to the Podman `--health-cmd` option.
475478
Set an interval for the healthchecks. An interval of disable results in no automatic timer setup.
476479
Equivalent to the Podman `--health-interval` option.
477480

481+
### `HealthLogDestination=`
482+
483+
Set the destination of the HealthCheck log. Directory path, local or events_logger (local use container state file)
484+
(Default: local)
485+
Equivalent to the Podman `--health-log-destination` option.
486+
487+
* `local`: (default) HealthCheck logs are stored in overlay containers. (For example: `$runroot/healthcheck.log`)
488+
* `directory`: creates a log file named `<container-ID>-healthcheck.log` with HealthCheck logs in the specified directory.
489+
* `events_logger`: The log will be written with logging mechanism set by events_logger. It also saves the log to a default directory, for performance on a system with a large number of logs.
490+
491+
### `HealthMaxLogCount=`
492+
493+
Set maximum number of attempts in the HealthCheck log file. ('0' value means an infinite number of attempts in the log file)
494+
(Default: 5 attempts)
495+
Equivalent to the Podman `--Health-max-log-count` option.
496+
497+
### `HealthMaxLogSize=`
498+
499+
Set maximum length in characters of stored HealthCheck log. ("0" value means an infinite log length)
500+
(Default: 500 characters)
501+
Equivalent to the Podman `--Health-max-log-size` option.
502+
478503
### `HealthOnFailure=`
479504

480505
Action to take once the container transitions to an unhealthy state.

libpod/container_config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ type ContainerMiscConfig struct {
413413
HealthCheckConfig *manifest.Schema2HealthConfig `json:"healthcheck"`
414414
// HealthCheckOnFailureAction defines an action to take once the container turns unhealthy.
415415
HealthCheckOnFailureAction define.HealthCheckOnFailureAction `json:"healthcheck_on_failure_action"`
416+
// HealthLogDestination defines the destination where the log is stored
417+
HealthLogDestination string `json:"healthLogDestination,omitempty"`
418+
// HealthMaxLogCount is maximum number of attempts in the HealthCheck log file.
419+
// ('0' value means an infinite number of attempts in the log file)
420+
HealthMaxLogCount uint `json:"healthMaxLogCount,omitempty"`
421+
// HealthMaxLogSize is the maximum length in characters of stored HealthCheck log
422+
// ("0" value means an infinite log length)
423+
HealthMaxLogSize uint `json:"healthMaxLogSize,omitempty"`
416424
// StartupHealthCheckConfig is the configuration of the startup
417425
// healthcheck for the container. This will run before the regular HC
418426
// runs, and when it passes the regular HC will be activated.

libpod/container_inspect.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
195195
// inspect status should be set to nil.
196196
if c.config.HealthCheckConfig != nil && !(len(c.config.HealthCheckConfig.Test) == 1 && c.config.HealthCheckConfig.Test[0] == "NONE") {
197197
// This container has a healthcheck defined in it; we need to add its state
198-
healthCheckState, err := c.getHealthCheckLog()
198+
healthCheckState, err := c.readHealthCheckLog()
199199
if err != nil {
200200
// An error here is not considered fatal; no health state will be displayed
201201
logrus.Error(err)
@@ -417,6 +417,12 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
417417

418418
ctrConfig.HealthcheckOnFailureAction = c.config.HealthCheckOnFailureAction.String()
419419

420+
ctrConfig.HealthLogDestination = c.config.HealthLogDestination
421+
422+
ctrConfig.HealthMaxLogCount = c.config.HealthMaxLogCount
423+
424+
ctrConfig.HealthMaxLogSize = c.config.HealthMaxLogSize
425+
420426
ctrConfig.CreateCommand = c.config.CreateCommand
421427

422428
ctrConfig.Timezone = c.config.Timezone

0 commit comments

Comments
 (0)