Skip to content

Commit c7a5b3b

Browse files
authored
Add configurable data plane log level (#2603)
Add Nginx error log level to NginxProxy. Problem: Users would like to assign a log level for the data plane. Solution: Add Nginx error log level to NginxProxy which allows users to set the error log level for Nginx. Testing: Unit tests and manual testing.
1 parent b41bad9 commit c7a5b3b

37 files changed

+949
-138
lines changed

Diff for: apis/v1alpha1/nginxproxy_types.go

+47
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type NginxProxySpec struct {
4545
// +optional
4646
//nolint:lll
4747
RewriteClientIP *RewriteClientIP `json:"rewriteClientIP,omitempty"`
48+
// Logging defines logging related settings for NGINX.
49+
//
50+
// +optional
51+
Logging *NginxLogging `json:"logging,omitempty"`
4852
// DisableHTTP2 defines if http2 should be disabled for all servers.
4953
// Default is false, meaning http2 will be enabled for all servers.
5054
//
@@ -202,3 +206,46 @@ const (
202206
// HostnameAddressType specifies that the address is a Hostname.
203207
HostnameAddressType AddressType = "Hostname"
204208
)
209+
210+
// NginxLogging defines logging related settings for NGINX.
211+
type NginxLogging struct {
212+
// ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
213+
// debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
214+
// of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
215+
// crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
216+
//
217+
// +optional
218+
// +kubebuilder:default=info
219+
ErrorLevel *NginxErrorLogLevel `json:"errorLevel,omitempty"`
220+
}
221+
222+
// NginxErrorLogLevel type defines the log level of error logs for NGINX.
223+
//
224+
// +kubebuilder:validation:Enum=debug;info;notice;warn;error;crit;alert;emerg
225+
type NginxErrorLogLevel string
226+
227+
const (
228+
// NginxLogLevelDebug is the debug level for NGINX error logs.
229+
NginxLogLevelDebug NginxErrorLogLevel = "debug"
230+
231+
// NginxLogLevelInfo is the info level for NGINX error logs.
232+
NginxLogLevelInfo NginxErrorLogLevel = "info"
233+
234+
// NginxLogLevelNotice is the notice level for NGINX error logs.
235+
NginxLogLevelNotice NginxErrorLogLevel = "notice"
236+
237+
// NginxLogLevelWarn is the warn level for NGINX error logs.
238+
NginxLogLevelWarn NginxErrorLogLevel = "warn"
239+
240+
// NginxLogLevelError is the error level for NGINX error logs.
241+
NginxLogLevelError NginxErrorLogLevel = "error"
242+
243+
// NginxLogLevelCrit is the crit level for NGINX error logs.
244+
NginxLogLevelCrit NginxErrorLogLevel = "crit"
245+
246+
// NginxLogLevelAlert is the alert level for NGINX error logs.
247+
NginxLogLevelAlert NginxErrorLogLevel = "alert"
248+
249+
// NginxLogLevelEmerg is the emerg level for NGINX error logs.
250+
NginxLogLevelEmerg NginxErrorLogLevel = "emerg"
251+
)

Diff for: apis/v1alpha1/zz_generated.deepcopy.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build/Dockerfile.nginx

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ ARG BUILD_AGENT
77

88
RUN apk add --no-cache libcap \
99
&& mkdir -p /var/lib/nginx /usr/lib/nginx/modules \
10-
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
11-
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
10+
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
11+
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
12+
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
13+
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
1214
&& apk del libcap
1315

1416
COPY ${NJS_DIR}/httpmatches.js /usr/lib/nginx/modules/njs/httpmatches.js
@@ -22,4 +24,4 @@ LABEL org.nginx.ngf.image.build.agent="${BUILD_AGENT}"
2224

2325
USER 101:1001
2426

25-
CMD ["sh", "-c", "rm -rf /var/run/nginx/*.sock && /docker-entrypoint.sh nginx -g 'daemon off;'"]
27+
CMD ["sh", "-c", "rm -rf /var/run/nginx/*.sock && nginx -g 'daemon off;'"]

Diff for: build/Dockerfile.nginxplus

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/apk/cert.pem,mode=0644 \
2020
&& printf "%s\n" "https://pkgs.nginx.com/plus/${NGINX_PLUS_VERSION}/alpine/v$(grep -E -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
2121
&& apk add --no-cache nginx-plus nginx-plus-module-njs nginx-plus-module-otel libcap \
2222
&& mkdir -p /var/lib/nginx /usr/lib/nginx/modules \
23-
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
24-
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
23+
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
24+
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
25+
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
26+
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
2527
&& apk del libcap \
2628
# forward request and error logs to docker log collector
2729
&& ln -sf /dev/stdout /var/log/nginx/access.log \

Diff for: charts/nginx-gateway-fabric/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
261261
| `metrics.port` | Set the port where the Prometheus metrics are exposed. | int | `9113` |
262262
| `metrics.secure` | Enable serving metrics via https. By default metrics are served via http. Please note that this endpoint will be secured with a self-signed certificate. | bool | `false` |
263263
| `nginx.config` | The configuration for the data plane that is contained in the NginxProxy resource. | object | `{}` |
264+
| `nginx.debug` | Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource. | bool | `false` |
264265
| `nginx.extraVolumeMounts` | extraVolumeMounts are the additional volume mounts for the nginx container. | list | `[]` |
265266
| `nginx.image.pullPolicy` | | string | `"Always"` |
266267
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginxinc/nginx-gateway-fabric/nginx"` |

Diff for: charts/nginx-gateway-fabric/templates/deployment.yaml

+12-5
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ spec:
131131
mountPath: /etc/nginx/conf.d
132132
- name: nginx-stream-conf
133133
mountPath: /etc/nginx/stream-conf.d
134-
- name: module-includes
135-
mountPath: /etc/nginx/module-includes
134+
- name: nginx-main-includes
135+
mountPath: /etc/nginx/main-includes
136136
- name: nginx-secrets
137137
mountPath: /etc/nginx/secrets
138138
- name: nginx-run
@@ -170,8 +170,8 @@ spec:
170170
mountPath: /etc/nginx/conf.d
171171
- name: nginx-stream-conf
172172
mountPath: /etc/nginx/stream-conf.d
173-
- name: module-includes
174-
mountPath: /etc/nginx/module-includes
173+
- name: nginx-main-includes
174+
mountPath: /etc/nginx/main-includes
175175
- name: nginx-secrets
176176
mountPath: /etc/nginx/secrets
177177
- name: nginx-run
@@ -183,6 +183,13 @@ spec:
183183
{{- with .Values.nginx.extraVolumeMounts -}}
184184
{{ toYaml . | nindent 8 }}
185185
{{- end }}
186+
{{- if .Values.nginx.debug }}
187+
command:
188+
- "/bin/sh"
189+
args:
190+
- "-c"
191+
- "rm -rf /var/run/nginx/*.sock && nginx-debug -g 'daemon off;'"
192+
{{- end }}
186193
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
187194
{{- if .Values.affinity }}
188195
affinity:
@@ -206,7 +213,7 @@ spec:
206213
emptyDir: {}
207214
- name: nginx-stream-conf
208215
emptyDir: {}
209-
- name: module-includes
216+
- name: nginx-main-includes
210217
emptyDir: {}
211218
- name: nginx-secrets
212219
emptyDir: {}

Diff for: charts/nginx-gateway-fabric/values.schema.json

+28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@
7272
"required": [],
7373
"type": "string"
7474
},
75+
"logging": {
76+
"description": "Logging defines logging related settings for NGINX.",
77+
"properties": {
78+
"errorLevel": {
79+
"enum": [
80+
"debug",
81+
"info",
82+
"notice",
83+
"warn",
84+
"error",
85+
"crit",
86+
"alert",
87+
"emerg"
88+
],
89+
"required": [],
90+
"type": "string"
91+
}
92+
},
93+
"required": [],
94+
"type": "object"
95+
},
7596
"rewriteClientIP": {
7697
"description": "RewriteClientIP defines configuration for rewriting the client IP to the original client's IP.",
7798
"properties": {
@@ -179,6 +200,13 @@
179200
"title": "config",
180201
"type": "object"
181202
},
203+
"debug": {
204+
"default": false,
205+
"description": "Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource.",
206+
"required": [],
207+
"title": "debug",
208+
"type": "boolean"
209+
},
182210
"extraVolumeMounts": {
183211
"description": "extraVolumeMounts are the additional volume mounts for the nginx container.",
184212
"items": {

Diff for: charts/nginx-gateway-fabric/values.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,28 @@ nginx:
201201
# pattern: ^([^"$\\]|\\[^$])*$
202202
# minLength: 1
203203
# maxLength: 255
204+
# logging:
205+
# type: object
206+
# description: Logging defines logging related settings for NGINX.
207+
# properties:
208+
# errorLevel:
209+
# type: string
210+
# enum:
211+
# - debug
212+
# - info
213+
# - notice
214+
# - warn
215+
# - error
216+
# - crit
217+
# - alert
218+
# - emerg
204219
# @schema
205220
# -- The configuration for the data plane that is contained in the NginxProxy resource.
206221
config: {}
207222

223+
# -- Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource.
224+
debug: false
225+
208226
# Configuration for NGINX Plus usage reporting.
209227
usage:
210228
# -- The namespace/name of the Secret containing the credentials for NGINX Plus usage reporting.

Diff for: config/crd/bases/gateway.nginx.org_nginxproxies.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ spec:
6262
- ipv4
6363
- ipv6
6464
type: string
65+
logging:
66+
description: Logging defines logging related settings for NGINX.
67+
properties:
68+
errorLevel:
69+
default: info
70+
description: |-
71+
ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
72+
debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
73+
of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
74+
crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
75+
enum:
76+
- debug
77+
- info
78+
- notice
79+
- warn
80+
- error
81+
- crit
82+
- alert
83+
- emerg
84+
type: string
85+
type: object
6586
rewriteClientIP:
6687
description: RewriteClientIP defines configuration for rewriting the
6788
client IP to the original client's IP.

Diff for: config/tests/static-deployment.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ spec:
7474
mountPath: /etc/nginx/conf.d
7575
- name: nginx-stream-conf
7676
mountPath: /etc/nginx/stream-conf.d
77-
- name: module-includes
78-
mountPath: /etc/nginx/module-includes
77+
- name: nginx-main-includes
78+
mountPath: /etc/nginx/main-includes
7979
- name: nginx-secrets
8080
mountPath: /etc/nginx/secrets
8181
- name: nginx-run
@@ -106,8 +106,8 @@ spec:
106106
mountPath: /etc/nginx/conf.d
107107
- name: nginx-stream-conf
108108
mountPath: /etc/nginx/stream-conf.d
109-
- name: module-includes
110-
mountPath: /etc/nginx/module-includes
109+
- name: nginx-main-includes
110+
mountPath: /etc/nginx/main-includes
111111
- name: nginx-secrets
112112
mountPath: /etc/nginx/secrets
113113
- name: nginx-run
@@ -127,7 +127,7 @@ spec:
127127
emptyDir: {}
128128
- name: nginx-stream-conf
129129
emptyDir: {}
130-
- name: module-includes
130+
- name: nginx-main-includes
131131
emptyDir: {}
132132
- name: nginx-secrets
133133
emptyDir: {}

Diff for: deploy/aws-nlb/deploy.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ spec:
248248
name: nginx-conf
249249
- mountPath: /etc/nginx/stream-conf.d
250250
name: nginx-stream-conf
251-
- mountPath: /etc/nginx/module-includes
252-
name: module-includes
251+
- mountPath: /etc/nginx/main-includes
252+
name: nginx-main-includes
253253
- mountPath: /etc/nginx/secrets
254254
name: nginx-secrets
255255
- mountPath: /var/run/nginx
@@ -280,8 +280,8 @@ spec:
280280
name: nginx-conf
281281
- mountPath: /etc/nginx/stream-conf.d
282282
name: nginx-stream-conf
283-
- mountPath: /etc/nginx/module-includes
284-
name: module-includes
283+
- mountPath: /etc/nginx/main-includes
284+
name: nginx-main-includes
285285
- mountPath: /etc/nginx/secrets
286286
name: nginx-secrets
287287
- mountPath: /var/run/nginx
@@ -302,7 +302,7 @@ spec:
302302
- emptyDir: {}
303303
name: nginx-stream-conf
304304
- emptyDir: {}
305-
name: module-includes
305+
name: nginx-main-includes
306306
- emptyDir: {}
307307
name: nginx-secrets
308308
- emptyDir: {}

Diff for: deploy/azure/deploy.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ spec:
245245
name: nginx-conf
246246
- mountPath: /etc/nginx/stream-conf.d
247247
name: nginx-stream-conf
248-
- mountPath: /etc/nginx/module-includes
249-
name: module-includes
248+
- mountPath: /etc/nginx/main-includes
249+
name: nginx-main-includes
250250
- mountPath: /etc/nginx/secrets
251251
name: nginx-secrets
252252
- mountPath: /var/run/nginx
@@ -277,8 +277,8 @@ spec:
277277
name: nginx-conf
278278
- mountPath: /etc/nginx/stream-conf.d
279279
name: nginx-stream-conf
280-
- mountPath: /etc/nginx/module-includes
281-
name: module-includes
280+
- mountPath: /etc/nginx/main-includes
281+
name: nginx-main-includes
282282
- mountPath: /etc/nginx/secrets
283283
name: nginx-secrets
284284
- mountPath: /var/run/nginx
@@ -301,7 +301,7 @@ spec:
301301
- emptyDir: {}
302302
name: nginx-stream-conf
303303
- emptyDir: {}
304-
name: module-includes
304+
name: nginx-main-includes
305305
- emptyDir: {}
306306
name: nginx-secrets
307307
- emptyDir: {}

0 commit comments

Comments
 (0)