Skip to content

Commit

Permalink
add additional config to health check (#4354)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-town authored Mar 4, 2024
1 parent f4b4c72 commit d8ed126
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 60 deletions.
14 changes: 7 additions & 7 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@babel/preset-typescript": "^7.15.0",
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@porter-dev/api-contracts": "^0.2.112",
"@porter-dev/api-contracts": "^0.2.113",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/lib/porter-apps/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,15 @@ export function defaultSerialized({
const defaultWebHealthCheck: SerializedHealthcheck = {
enabled: false,
httpPath: "/healthz",
timeoutSeconds: 1,
initialDelaySeconds: 15,
};

const defaultWorkerHealthCheck: SerializedHealthcheck = {
enabled: false,
command: "./healthz.sh",
timeoutSeconds: 1,
initialDelaySeconds: 15,
};

return match(type)
Expand Down
19 changes: 18 additions & 1 deletion dashboard/src/lib/porter-apps/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getNumericValue = (
defaultValue: number,
overrideValue?: number,
validAsZero = false
) => {
): number => {
if (!overrideValue) {
return defaultValue;
}
Expand Down Expand Up @@ -161,12 +161,16 @@ export const healthcheckValidator = z.object({
enabled: serviceBooleanValidator,
httpPath: serviceStringValidator.optional(),
command: serviceStringValidator.optional(),
timeoutSeconds: serviceNumberValidator.optional(),
initialDelaySeconds: serviceNumberValidator.optional(),
});
export type ClientHealthCheck = z.infer<typeof healthcheckValidator>;
export type SerializedHealthcheck = {
enabled: boolean;
httpPath?: string;
command?: string;
timeoutSeconds?: number;
initialDelaySeconds?: number;
};

export function serializeHealth({
Expand All @@ -179,6 +183,8 @@ export function serializeHealth({
enabled: health.enabled.value,
httpPath: health.httpPath?.value,
command: health.command?.value,
timeoutSeconds: health.timeoutSeconds?.value,
initialDelaySeconds: health.initialDelaySeconds?.value,
}
);
}
Expand All @@ -200,12 +206,23 @@ export function deserializeHealthCheck({
command: health.command
? ServiceField.string(health.command, override?.command)
: ServiceField.string("", undefined),
timeoutSeconds: health.timeoutSeconds
? ServiceField.number(health.timeoutSeconds, override?.timeoutSeconds)
: ServiceField.number(1, undefined),
initialDelaySeconds: health.initialDelaySeconds
? ServiceField.number(
health.initialDelaySeconds,
override?.initialDelaySeconds
)
: ServiceField.number(15, undefined),
}
: setDefaults
? {
enabled: ServiceField.boolean(false, undefined),
httpPath: ServiceField.string("", undefined),
command: ServiceField.string("", undefined),
timeoutSeconds: ServiceField.number(1, undefined),
initialDelaySeconds: ServiceField.number(15, undefined),
}
: undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Advanced: React.FC<AdvancedProps> = ({ index }) => {

return (
<>
<Text>Termination grace period seconds</Text>
<Text>Termination grace period (seconds)</Text>
<Spacer y={0.25} />
<Container style={{ width: "400px" }}>
<Text color="helper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,56 @@ const Health: React.FC<HealthProps> = ({ index }) => {
</Checkbox>
)}
/>
{healthCheckEnabled.value &&
(serviceType === "web" ? (
<>
<Spacer y={0.5} />
<Text>Health check endpoint</Text>
<Spacer y={0.5} />
<ControlledInput
type="text"
placeholder="ex: /healthz"
{...register(
`app.services.${index}.config.healthCheck.httpPath.value`
)}
/>
</>
) : (
<>
<Spacer y={0.5} />
<Text>Health check command</Text>
<Spacer y={0.5} />
<ControlledInput
type="text"
placeholder="ex: ./healthz.sh"
{...register(
`app.services.${index}.config.healthCheck.command.value`
)}
/>
</>
))}
{healthCheckEnabled.value && (
<>
<Spacer y={0.75} />
{serviceType === "web" ? (
<>
<Text color="helper">Endpoint</Text>
<Spacer y={0.25} />
<ControlledInput
type="text"
placeholder="ex: /healthz"
{...register(
`app.services.${index}.config.healthCheck.httpPath.value`
)}
/>
</>
) : (
<>
<Text color="helper">Command</Text>
<Spacer y={0.25} />
<ControlledInput
type="text"
placeholder="ex: ./healthz.sh"
{...register(
`app.services.${index}.config.healthCheck.command.value`
)}
/>
</>
)}
<Spacer y={0.5} />
<Text color="helper">Timeout (seconds)</Text>
<Spacer y={0.25} />
<ControlledInput
type="text"
placeholder="ex: 1"
{...register(
`app.services.${index}.config.healthCheck.timeoutSeconds.value`
)}
/>
<Spacer y={0.5} />
<Text color="helper">Initial delay (seconds)</Text>
<Spacer y={0.25} />
<ControlledInput
type="text"
placeholder="ex: 30"
{...register(
`app.services.${index}.config.healthCheck.initialDelaySeconds.value`
)}
/>
</>
)}
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ require (
github.com/matryer/is v1.4.0
github.com/nats-io/nats.go v1.24.0
github.com/open-policy-agent/opa v0.44.0
github.com/porter-dev/api-contracts v0.2.112
github.com/porter-dev/api-contracts v0.2.113
github.com/riandyrn/otelchi v0.5.1
github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1523,8 +1523,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
github.com/porter-dev/api-contracts v0.2.112 h1:ZywNLFVopYsZvV5WkjFIXRxoPI64wvJYsy4RMLCTgAY=
github.com/porter-dev/api-contracts v0.2.112/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/api-contracts v0.2.113 h1:sv1huO9MpykJaWhV2D5zTD2LouMbRSBV5ATt/5Ukrbo=
github.com/porter-dev/api-contracts v0.2.113/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
10 changes: 7 additions & 3 deletions internal/porter_app/test/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ var result_nobuild = &porterv1.PorterApp{
},
},
HealthCheck: &porterv1.HealthCheck{
Enabled: true,
HttpPath: "/healthz",
Command: "",
Enabled: true,
HttpPath: "/healthz",
Command: "",
InitialDelaySeconds: &initialDelaySeconds10,
TimeoutSeconds: 5,
},
},
},
Expand Down Expand Up @@ -230,6 +232,8 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
},
}

var initialDelaySeconds10 = int32(10)

func diffProtoWithFailTest(t *testing.T, is *is.I, want, got *porterv1.PorterApp) {
t.Helper()

Expand Down
3 changes: 2 additions & 1 deletion internal/porter_app/testdata/v2_input_no_build_no_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ services:
healthCheck:
enabled: true
httpPath: /healthz
command: ""
timeoutSeconds: 5
initialDelaySeconds: 10
- name: example-wkr
type: worker
run: echo 'work'
Expand Down
2 changes: 2 additions & 0 deletions internal/porter_app/testdata/v2_input_nobuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
healthCheck:
enabled: true
httpPath: /healthz
timeoutSeconds: 5
initialDelaySeconds: 10
- name: example-wkr
type: worker
run: echo 'work'
Expand Down
40 changes: 25 additions & 15 deletions internal/porter_app/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ type Domains struct {

// HealthCheck contains the health check settings
type HealthCheck struct {
Enabled bool `yaml:"enabled"`
HttpPath string `yaml:"httpPath"`
Command string `yaml:"command"`
Enabled bool `yaml:"enabled"`
HttpPath string `yaml:"httpPath,omitempty"`
Command string `yaml:"command,omitempty"`
TimeoutSeconds int `yaml:"timeoutSeconds,omitempty"`
InitialDelaySeconds *int32 `yaml:"initialDelaySeconds,omitempty"`
}

// ProtoFromApp converts a PorterApp type to a base PorterApp proto type and returns env variables
Expand Down Expand Up @@ -416,9 +418,11 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
var healthCheck *porterv1.HealthCheck
if service.HealthCheck != nil {
healthCheck = &porterv1.HealthCheck{
Enabled: service.HealthCheck.Enabled,
HttpPath: service.HealthCheck.HttpPath,
Command: service.HealthCheck.Command,
Enabled: service.HealthCheck.Enabled,
HttpPath: service.HealthCheck.HttpPath,
Command: service.HealthCheck.Command,
TimeoutSeconds: int32(service.HealthCheck.TimeoutSeconds),
InitialDelaySeconds: service.HealthCheck.InitialDelaySeconds,
}
}
webConfig.HealthCheck = healthCheck
Expand Down Expand Up @@ -462,9 +466,11 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
var healthCheck *porterv1.HealthCheck
if service.HealthCheck != nil {
healthCheck = &porterv1.HealthCheck{
Enabled: service.HealthCheck.Enabled,
HttpPath: service.HealthCheck.HttpPath,
Command: service.HealthCheck.Command,
Enabled: service.HealthCheck.Enabled,
HttpPath: service.HealthCheck.HttpPath,
Command: service.HealthCheck.Command,
TimeoutSeconds: int32(service.HealthCheck.TimeoutSeconds),
InitialDelaySeconds: service.HealthCheck.InitialDelaySeconds,
}
}
workerConfig.HealthCheck = healthCheck
Expand Down Expand Up @@ -602,9 +608,11 @@ func appServiceFromProto(service *porterv1.Service) (Service, error) {
var healthCheck *HealthCheck
if webConfig.HealthCheck != nil {
healthCheck = &HealthCheck{
Enabled: webConfig.HealthCheck.Enabled,
HttpPath: webConfig.HealthCheck.HttpPath,
Command: webConfig.HealthCheck.Command,
Enabled: webConfig.HealthCheck.Enabled,
HttpPath: webConfig.HealthCheck.HttpPath,
Command: webConfig.HealthCheck.Command,
TimeoutSeconds: int(webConfig.HealthCheck.TimeoutSeconds),
InitialDelaySeconds: webConfig.HealthCheck.InitialDelaySeconds,
}
}
appService.HealthCheck = healthCheck
Expand Down Expand Up @@ -645,9 +653,11 @@ func appServiceFromProto(service *porterv1.Service) (Service, error) {
var healthCheck *HealthCheck
if workerConfig.HealthCheck != nil {
healthCheck = &HealthCheck{
Enabled: workerConfig.HealthCheck.Enabled,
HttpPath: workerConfig.HealthCheck.HttpPath,
Command: workerConfig.HealthCheck.Command,
Enabled: workerConfig.HealthCheck.Enabled,
HttpPath: workerConfig.HealthCheck.HttpPath,
Command: workerConfig.HealthCheck.Command,
TimeoutSeconds: int(workerConfig.HealthCheck.TimeoutSeconds),
InitialDelaySeconds: workerConfig.HealthCheck.InitialDelaySeconds,
}
}
appService.HealthCheck = healthCheck
Expand Down

0 comments on commit d8ed126

Please sign in to comment.