Skip to content

Commit

Permalink
Merge branch 'main' into docs/add-docs-for-helm-operator-oom
Browse files Browse the repository at this point in the history
  • Loading branch information
haywoodsh committed Jan 24, 2023
2 parents 15ec556 + 7c117ec commit b21a07a
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ spec:
type: string
jitter:
type: string
keepalive-time:
type: string
mandatory:
type: boolean
passes:
Expand Down
2 changes: 2 additions & 0 deletions deployments/common/crds/k8s.nginx.org_virtualservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ spec:
type: string
jitter:
type: string
keepalive-time:
type: string
mandatory:
type: boolean
passes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ spec:
type: string
jitter:
type: string
keepalive-time:
type: string
mandatory:
type: boolean
passes:
Expand Down
2 changes: 2 additions & 0 deletions deployments/helm-chart/crds/k8s.nginx.org_virtualservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ spec:
type: string
jitter:
type: string
keepalive-time:
type: string
mandatory:
type: boolean
passes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ healthCheck:
statusMatch: "! 500"
mandatory: true
persistent: true
keepalive-time: 60s
```

Note: This feature is supported only in NGINX Plus.
Expand All @@ -435,6 +436,7 @@ Note: This feature is supported only in NGINX Plus.
|``grpcService`` | The gRPC service to be monitored on the upstream server. Only valid on gRPC type upstreams. | ``string`` | No |
|``mandatory`` | Require every newly added server to pass all configured health checks before NGINX Plus sends traffic to it. If this is not specified, or is set to false, the server will be initially considered healthy. When combined with [slow-start](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#slow_start), it gives a new server more time to connect to databases and “warm up” before being asked to handle their full share of traffic. | ``bool`` | No |
|``persistent`` | Set the initial “up” state for a server after reload if the server was considered healthy before reload. Enabling persistent requires that the mandatory parameter is also set to `true`. | ``bool`` | No |
|``keepalive-time`` | Enables [keepalive](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) connections for health checks and specifies the time during which requests can be processed through one keepalive connection. The default is ``60s``. | ``string`` | No |
{{% /table %}}

### Upstream.SessionCookie
Expand Down
1 change: 1 addition & 0 deletions examples/custom-resources/health-checks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spec:
path: /healthz
interval: 20s
jitter: 3s
keep_alive: 120s
fails: 5
passes: 5
port: 8080
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ type HealthCheck struct {
GRPCService string
Mandatory bool
Persistent bool
KeepaliveTime string
}

// TLSRedirect defines a redirect in a Server.
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ server {
fails={{ $hc.Fails }} passes={{ $hc.Passes }}{{ if $hc.Match }} match={{ $hc.Match }}{{ end }}
{{ if $hc.Mandatory }} mandatory{{ if $hc.Persistent }} persistent{{ end }}{{ end }}
{{ if $hc.GRPCPass }} type=grpc{{ if $hc.GRPCStatus }} grpc_status={{ $hc.GRPCStatus }}{{ end }}
{{ if $hc.GRPCService }} grpc_service={{ $hc.GRPCService }}{{ end }}{{ end }};
{{ if $hc.GRPCService }} grpc_service={{ $hc.GRPCService }}{{ end }}{{ end }} keepalive_time={{ $hc.KeepaliveTime }};
}
{{ end }}

Expand Down
5 changes: 5 additions & 0 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func newHealthCheckWithDefaults(upstream conf_v1.Upstream, upstreamName string,
URI: uri,
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
ProxyPass: fmt.Sprintf("%v://%v", generateProxyPassProtocol(upstream.TLS.Enable), upstreamName),
Expand Down Expand Up @@ -1396,6 +1397,10 @@ func generateHealthCheck(
hc.Jitter = generateTime(upstream.HealthCheck.Jitter)
}

if upstream.HealthCheck.KeepaliveTime != "" {
hc.KeepaliveTime = generateTime(upstream.HealthCheck.KeepaliveTime)
}

if upstream.HealthCheck.Fails > 0 {
hc.Fails = upstream.HealthCheck.Fails
}
Expand Down
11 changes: 11 additions & 0 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7100,6 +7100,7 @@ func TestNewHealthCheckWithDefaults(t *testing.T) {
URI: "/",
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand Down Expand Up @@ -7128,6 +7129,7 @@ func TestGenerateHealthCheck(t *testing.T) {
Path: "/healthz",
Interval: "5s",
Jitter: "2s",
KeepaliveTime: "120s",
Fails: 3,
Passes: 2,
Port: 8080,
Expand Down Expand Up @@ -7157,6 +7159,7 @@ func TestGenerateHealthCheck(t *testing.T) {
URI: "/healthz",
Interval: "5s",
Jitter: "2s",
KeepaliveTime: "120s",
Fails: 3,
Passes: 2,
Port: 8080,
Expand Down Expand Up @@ -7187,6 +7190,7 @@ func TestGenerateHealthCheck(t *testing.T) {
URI: "/",
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand All @@ -7209,6 +7213,7 @@ func TestGenerateHealthCheck(t *testing.T) {
URI: "/",
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand All @@ -7227,6 +7232,7 @@ func TestGenerateHealthCheck(t *testing.T) {
Enable: true,
Interval: "1m 5s",
Jitter: "2m 3s",
KeepaliveTime: "1m 6s",
ConnectTimeout: "1m 10s",
SendTimeout: "1m 20s",
ReadTimeout: "1m 30s",
Expand All @@ -7242,6 +7248,7 @@ func TestGenerateHealthCheck(t *testing.T) {
URI: "/",
Interval: "1m5s",
Jitter: "2m3s",
KeepaliveTime: "1m6s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand Down Expand Up @@ -7269,6 +7276,7 @@ func TestGenerateHealthCheck(t *testing.T) {
URI: "/",
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand Down Expand Up @@ -7308,6 +7316,7 @@ func TestGenerateGrpcHealthCheck(t *testing.T) {
Enable: true,
Interval: "5s",
Jitter: "2s",
KeepaliveTime: "120s",
Fails: 3,
Passes: 2,
Port: 50051,
Expand Down Expand Up @@ -7339,6 +7348,7 @@ func TestGenerateGrpcHealthCheck(t *testing.T) {
GRPCPass: fmt.Sprintf("grpc://%v", upstreamName),
Interval: "5s",
Jitter: "2s",
KeepaliveTime: "120s",
Fails: 3,
Passes: 2,
Port: 50051,
Expand Down Expand Up @@ -7371,6 +7381,7 @@ func TestGenerateGrpcHealthCheck(t *testing.T) {
GRPCPass: fmt.Sprintf("grpc://%v", upstreamName),
Interval: "5s",
Jitter: "0s",
KeepaliveTime: "60s",
Fails: 1,
Passes: 1,
Headers: make(map[string]string),
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type HealthCheck struct {
GRPCService string `json:"grpcService"`
Mandatory bool `json:"mandatory"`
Persistent bool `json:"persistent"`
KeepaliveTime string `json:"keepalive-time"`
}

// Header defines an HTTP Header.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/validation/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func validateUpstreamHealthCheck(hc *v1.HealthCheck, typeName string, fieldPath
allErrs = append(allErrs, validateTime(hc.ReadTimeout, fieldPath.Child("read-timeout"))...)
allErrs = append(allErrs, validateTime(hc.SendTimeout, fieldPath.Child("send-timeout"))...)
allErrs = append(allErrs, validateStatusMatch(hc.StatusMatch, fieldPath.Child("statusMatch"))...)
allErrs = append(allErrs, validateTime(hc.KeepaliveTime, fieldPath.Child("keepalive-time"))...)

for i, header := range hc.Headers {
idxPath := fieldPath.Child("headers").Index(i)
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,7 @@ func TestValidateUpstreamHealthCheck(t *testing.T) {
StatusMatch: "! 500",
Mandatory: true,
Persistent: true,
KeepaliveTime: "120s",
}

allErrs := validateUpstreamHealthCheck(hc, "", field.NewPath("healthCheck"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
path: 200
interval: 1.5
jitter: 2.0
keepalive-time: 2.0
fails: "one"
passes: "one"
port: "80"
Expand Down Expand Up @@ -49,6 +50,7 @@ spec:
path: 200
interval: 1.5
jitter: 2.0
keepalive-time: 2.0
fails: "one"
passes: "one"
port: "80"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ spec:
path: "invalid"
interval: 1.5d
jitter: invalid
keepalive-time: 1.3d
fails: -5
passes: -1
port: -1
Expand Down Expand Up @@ -48,6 +49,7 @@ spec:
path: "invalid"
interval: 1.5d
jitter: invalid
keepalive-time: 1.3d
fails: -5
passes: -1
port: -1
Expand Down
6 changes: 3 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ attrs==22.2.0 \
# via
# -r requirements.txt
# pytest
cachetools==5.2.1 \
--hash=sha256:5991bc0e08a1319bb618d3195ca5b6bc76646a49c21d55962977197b301cc1fe \
--hash=sha256:8462eebf3a6c15d25430a8c27c56ac61340b2ecf60c9ce57afc2b97e450e47da
cachetools==5.3.0 \
--hash=sha256:13dfddc7b8df938c21a940dfa6557ce6e94a2f1cdfa58eb90c805721d58f2c14 \
--hash=sha256:429e1a1e845c008ea6c85aa35d4b98b65d6a9763eeef3e37e92728a12d1de9d4
# via
# -r requirements.txt
# google-auth
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def test_config_after_enable_healthcheck(
param_list = [
"health_check port=50051 interval=1s jitter=2s",
"type=grpc grpc_status=12",
"grpc_service=helloworld.Greeter;",
"grpc_service=helloworld.Greeter keepalive_time=60s;",
]
for p in param_list:
assert p in config
Expand Down
9 changes: 7 additions & 2 deletions tests/suite/test_virtual_server_upstream_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class TestOptionsSpecificForPlus:
"health_check uri=/ interval=5s jitter=0s",
"fails=1 passes=1",
"mandatory persistent",
";",
"keepalive_time=60s;",
"slow_start=3h",
"queue 100 timeout=60s;",
"ntlm;",
Expand All @@ -531,6 +531,7 @@ class TestOptionsSpecificForPlus:
"read-timeout": "45s",
"send-timeout": "55s",
"headers": [{"name": "Host", "value": "virtual-server.example.com"}],
"keepalive-time": "120s",
},
"queue": {"size": 1000, "timeout": "66s"},
"slow-start": "0s",
Expand All @@ -544,7 +545,8 @@ class TestOptionsSpecificForPlus:
"proxy_connect_timeout 35s;",
"proxy_read_timeout 45s;",
"proxy_send_timeout 55s;",
'proxy_set_header Host "virtual-server.example.com";',
'proxy_set_header Host "virtual-server.example.com"',
"keepalive_time=120s;",
"slow_start=0s",
"queue 1000 timeout=66s;",
"ntlm;",
Expand Down Expand Up @@ -632,6 +634,7 @@ def test_validation_flow(
"upstreams[0].healthCheck.path",
"upstreams[0].healthCheck.interval",
"upstreams[0].healthCheck.jitter",
"upstreams[0].healthCheck.keepalive-time",
"upstreams[0].healthCheck.fails",
"upstreams[0].healthCheck.passes",
"upstreams[0].healthCheck.connect-timeout",
Expand All @@ -653,6 +656,7 @@ def test_validation_flow(
"upstreams[1].healthCheck.path",
"upstreams[1].healthCheck.interval",
"upstreams[1].healthCheck.jitter",
"upstreams[1].healthCheck.keepalive-time",
"upstreams[1].healthCheck.fails",
"upstreams[1].healthCheck.passes",
"upstreams[1].healthCheck.connect-timeout",
Expand Down Expand Up @@ -693,6 +697,7 @@ def test_openapi_validation_flow(
"healthCheck.path",
"healthCheck.interval",
"healthCheck.jitter",
"healthCheck.keepalive-time",
"healthCheck.fails",
"healthCheck.passes",
"healthCheck.port",
Expand Down

0 comments on commit b21a07a

Please sign in to comment.