Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First stab at distinct health check ports #751

Open
wants to merge 8 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/configuration/health-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
grace: 5
interval: 5
path: /check
port: 8000
timeout: 3
```

Expand All @@ -42,4 +43,5 @@ services:
| **grace** | 5 | The amount of time in seconds to wait for a [Process](/reference/primitives/app/process) to boot before beginning health checks |
| **interval** | 5 | The number of seconds between health checks |
| **path** | / | The HTTP endpoint that will be requested |
| **port** | Inherited from service port | The port that the health check will connect to |
| **timeout** | 4 | The number of seconds to wait for a valid response |
17 changes: 17 additions & 0 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ func (m *Manifest) ApplyDefaults() error {
m.Services[i].Health.Path = "/"
}

if s.Health.Port.Port == 0 && s.Port.Port > 0 {
m.Services[i].Health.Port.Port = s.Port.Port
if s.Port.Scheme != "" {
m.Services[i].Health.Port.Scheme = s.Port.Scheme
} else {
m.Services[i].Health.Port.Scheme = "http"
}
}

Comment on lines +158 to +166
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if health port is defined but health scheme is not defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the code shows, if you don't define the scheme, it will default to http.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am asking when health port is defined case. i can see in the code if health port defined the it will not execute the scheme condition in here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, sorry I misunderstood 😆 Yeah, I may have missed that... let me update!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nightfury1204 added default now, thank you!

if s.Health.Interval == 0 {
m.Services[i].Health.Interval = 5
}
Expand All @@ -171,6 +180,14 @@ func (m *Manifest) ApplyDefaults() error {
if s.Liveness.Interval == 0 {
m.Services[i].Liveness.Interval = 5
}
if s.Liveness.Port.Port == 0 && s.Port.Port > 0 {
m.Services[i].Liveness.Port.Port = s.Port.Port
if s.Port.Scheme != "" {
m.Services[i].Liveness.Port.Scheme = s.Port.Scheme
} else {
m.Services[i].Liveness.Port.Scheme = "http"
}
}
if s.Liveness.Timeout == 0 {
m.Services[i].Liveness.Timeout = 5
}
Expand Down
1 change: 1 addition & 0 deletions pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestManifestLoad(t *testing.T) {
Health: manifest.ServiceHealth{
Grace: 5,
Path: "/auth",
Port: 2001,
Interval: 5,
Timeout: 4,
},
Expand Down
24 changes: 13 additions & 11 deletions pkg/manifest/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,22 @@ type ServiceDnsConfig struct {
}

type ServiceHealth struct {
Disable bool
Grace int
Interval int
Path string
Timeout int
Disable bool `yaml:"disable,omitempty"`
Grace int `yaml:"grace,omitempty"`
Interval int `yaml:"interval,omitempty"`
Path string `yaml:"path,omitempty"`
Port ServicePortScheme `yaml:"port,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
}

type ServiceLiveness struct {
Grace int `yaml:"grace,omitempty"`
Interval int `yaml:"interval,omitempty"`
Path string `yaml:"path,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
SuccessThreshold int `yaml:"successThreshold,omitempty"`
FailureThreshold int `yaml:"failureThreshold,omitempty"`
Grace int `yaml:"grace,omitempty"`
Interval int `yaml:"interval,omitempty"`
Path string `yaml:"path,omitempty"`
Port ServicePortScheme `yaml:"port,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
SuccessThreshold int `yaml:"successThreshold,omitempty"`
FailureThreshold int `yaml:"failureThreshold,omitempty"`
}

type ServiceLifecycle struct {
Expand Down
27 changes: 15 additions & 12 deletions provider/k8s/template/app/service.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ spec:
{{ end }}
{{ end }}
{{ end }}
{{ with .Service.Port.Port }}
{{ if and (not (eq $.Service.Port.Scheme "GRPC")) (not (eq $.Service.Liveness.Path ""))}}
{{ with .Service.Liveness.Port }}
{{ if and (not (eq $.Service.Liveness.Port.Scheme "GRPC")) (not (eq $.Service.Liveness.Path ""))}}
livenessProbe:
httpGet:
path: {{$.Service.Liveness.Path}}"
Expand All @@ -163,7 +163,19 @@ spec:
successThreshold: {{$.Service.Liveness.SuccessThreshold}}
failureThreshold: {{$.Service.Liveness.FailureThreshold}}
{{ end }}
{{ if and (not (eq $.Service.Port.Scheme "GRPC")) (not $.Service.Health.Disable) }}
{{ if (eq $.Service.Liveness.Port.Scheme "GRPC") }}
livenessProbe:
grpc:
port: {{.}}
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 15
successThreshold: 1
failureThreshold: 5
{{ end }}
{{ end }}
{{ with .Service.Health.Port }}
{{ if and (not (eq $.Service.Health.Port.Scheme "GRPC")) (not $.Service.Health.Disable) }}
readinessProbe:
httpGet:
path: "{{$.Service.Health.Path}}"
Expand All @@ -174,15 +186,6 @@ spec:
timeoutSeconds: {{$.Service.Health.Timeout}}
successThreshold: 1
failureThreshold: 3
{{ else if $.Service.GrpcHealthEnabled }}
livenessProbe:
grpc:
port: {{.}}
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 15
successThreshold: 1
failureThreshold: 5
{{ end }}
{{ end }}
ports:
Expand Down