Skip to content

Commit

Permalink
feat(template): add timeout definitions for container module healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Vollstädt authored and thsig committed May 4, 2021
1 parent 3cdbfc9 commit d716c9a
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
12 changes: 12 additions & 0 deletions core/src/plugins/container/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface ServiceHealthCheckSpec {
}
command?: string[]
tcpPort?: string
readinessTimeoutSeconds?: number
livenessTimeoutSeconds?: number
}

export interface ServiceLimitSpec {
Expand Down Expand Up @@ -289,6 +291,16 @@ const healthCheckSchema = () =>
tcpPort: joi
.string()
.description("Set this to check the service's health by checking if this TCP port is accepting connections."),
readinessTimeoutSeconds: joi
.number()
.min(1)
.default(3)
.description("The maximum number of seconds to wait until the readiness check counts as failed."),
livenessTimeoutSeconds: joi
.number()
.min(1)
.default(3)
.description("The maximum number of seconds to wait until the liveness check counts as failed."),
})
.xor("httpGet", "command", "tcpPort")

Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/container/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ function configureHealthCheck(container: V1Container, spec: ContainerServiceConf
container.readinessProbe = {
initialDelaySeconds: 2,
periodSeconds: readinessPeriodSeconds,
timeoutSeconds: 3,
timeoutSeconds: spec.healthCheck?.readinessTimeoutSeconds || 3,
successThreshold: 2,
failureThreshold: readinessFailureThreshold,
}
Expand All @@ -647,7 +647,7 @@ function configureHealthCheck(container: V1Container, spec: ContainerServiceConf
container.livenessProbe = {
initialDelaySeconds: readinessPeriodSeconds * readinessFailureThreshold,
periodSeconds: dev ? 10 : 5,
timeoutSeconds: 3,
timeoutSeconds: spec.healthCheck?.livenessTimeoutSeconds || 3,
successThreshold: 1,
failureThreshold: dev ? 30 : 3,
}
Expand Down
14 changes: 12 additions & 2 deletions core/test/unit/src/plugins/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ describe("plugins.container", () => {
path: "/health",
port: "http",
},
livenessTimeoutSeconds: 10,
readinessTimeoutSeconds: 10,
},
limits: {
cpu: 123,
Expand Down Expand Up @@ -329,7 +331,11 @@ describe("plugins.container", () => {
env: {
SOME_ENV_VAR: "value",
},
healthCheck: { httpGet: { path: "/health", port: "http" } },
healthCheck: {
httpGet: { path: "/health", port: "http" },
readinessTimeoutSeconds: 10,
livenessTimeoutSeconds: 10,
},
limits: {
cpu: 123,
memory: 456,
Expand Down Expand Up @@ -398,7 +404,11 @@ describe("plugins.container", () => {
env: {
SOME_ENV_VAR: "value",
},
healthCheck: { httpGet: { path: "/health", port: "http" } },
healthCheck: {
httpGet: { path: "/health", port: "http" },
readinessTimeoutSeconds: 10,
livenessTimeoutSeconds: 10,
},
limits: {
cpu: 123,
memory: 456,
Expand Down
26 changes: 26 additions & 0 deletions docs/reference/module-types/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ services:
# Set this to check the service's health by checking if this TCP port is accepting connections.
tcpPort:

# The maximum number of seconds to wait until the readiness check counts as failed.
readinessTimeoutSeconds: 3

# The maximum number of seconds to wait until the liveness check counts as failed.
livenessTimeoutSeconds: 3

# If this module uses the `hotReload` field, the container will be run with this command/entrypoint when the
# service is deployed with hot reloading enabled.
hotReloadCommand:
Expand Down Expand Up @@ -1314,6 +1320,26 @@ Set this to check the service's health by checking if this TCP port is accepting
| -------- | -------- |
| `string` | No |

### `services[].healthCheck.readinessTimeoutSeconds`

[services](#services) > [healthCheck](#serviceshealthcheck) > readinessTimeoutSeconds

The maximum number of seconds to wait until the readiness check counts as failed.

| Type | Default | Required |
| -------- | ------- | -------- |
| `number` | `3` | No |

### `services[].healthCheck.livenessTimeoutSeconds`

[services](#services) > [healthCheck](#serviceshealthcheck) > livenessTimeoutSeconds

The maximum number of seconds to wait until the liveness check counts as failed.

| Type | Default | Required |
| -------- | ------- | -------- |
| `number` | `3` | No |

### `services[].hotReloadCommand[]`

[services](#services) > hotReloadCommand
Expand Down
26 changes: 26 additions & 0 deletions docs/reference/module-types/maven-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ services:
# Set this to check the service's health by checking if this TCP port is accepting connections.
tcpPort:

# The maximum number of seconds to wait until the readiness check counts as failed.
readinessTimeoutSeconds: 3

# The maximum number of seconds to wait until the liveness check counts as failed.
livenessTimeoutSeconds: 3

# If this module uses the `hotReload` field, the container will be run with this command/entrypoint when the
# service is deployed with hot reloading enabled.
hotReloadCommand:
Expand Down Expand Up @@ -1322,6 +1328,26 @@ Set this to check the service's health by checking if this TCP port is accepting
| -------- | -------- |
| `string` | No |

### `services[].healthCheck.readinessTimeoutSeconds`

[services](#services) > [healthCheck](#serviceshealthcheck) > readinessTimeoutSeconds

The maximum number of seconds to wait until the readiness check counts as failed.

| Type | Default | Required |
| -------- | ------- | -------- |
| `number` | `3` | No |

### `services[].healthCheck.livenessTimeoutSeconds`

[services](#services) > [healthCheck](#serviceshealthcheck) > livenessTimeoutSeconds

The maximum number of seconds to wait until the liveness check counts as failed.

| Type | Default | Required |
| -------- | ------- | -------- |
| `number` | `3` | No |

### `services[].hotReloadCommand[]`

[services](#services) > hotReloadCommand
Expand Down

0 comments on commit d716c9a

Please sign in to comment.