Skip to content

Commit d34a1f8

Browse files
committed
Add ability to assign a log level for the data plane
1 parent edbd856 commit d34a1f8

35 files changed

+906
-136
lines changed

Diff for: apis/v1alpha1/nginxproxy_types.go

+47
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ type NginxProxySpec struct {
5959
// +optional
6060
//nolint:lll
6161
RewriteClientIP *RewriteClientIP `json:"rewriteClientIP,omitempty"`
62+
// Logging defines logging related settings for NGINX.
63+
//
64+
// +optional
65+
Logging *NginxLogging `json:"logging,omitempty"`
6266
// DisableHTTP2 defines if http2 should be disabled for all servers.
6367
// Default is false, meaning http2 will be enabled for all servers.
6468
//
@@ -203,3 +207,46 @@ const (
203207
// kubebuilder:validation:Pattern=`^[\.a-zA-Z0-9:]*(\/([0-9]?[0-9]?[0-9]))$`
204208
AddressTypeCIDR AddressType = "cidr"
205209
)
210+
211+
// NginxLogging defines logging related settings for NGINX.
212+
type NginxLogging struct {
213+
// ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
214+
// debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
215+
// of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
216+
// crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
217+
//
218+
// +optional
219+
// +kubebuilder:default=info
220+
ErrorLevel *NginxErrorLogLevel `json:"errorlevel,omitempty"`
221+
}
222+
223+
// NginxErrorLogLevel type defines the log level of error logs for NGINX.
224+
//
225+
// +kubebuilder:validation:Enum=debug;info;notice;warn;error;crit;alert;emerg
226+
type NginxErrorLogLevel string
227+
228+
const (
229+
// NginxLogLevelDebug is the debug level for NGINX error logs.
230+
NginxLogLevelDebug NginxErrorLogLevel = "debug"
231+
232+
// NginxLogLevelInfo is the info level for NGINX error logs.
233+
NginxLogLevelInfo NginxErrorLogLevel = "info"
234+
235+
// NginxLogLevelNotice is the notice level for NGINX error logs.
236+
NginxLogLevelNotice NginxErrorLogLevel = "notice"
237+
238+
// NginxLogLevelWarn is the warn level for NGINX error logs.
239+
NginxLogLevelWarn NginxErrorLogLevel = "warn"
240+
241+
// NginxLogLevelError is the error level for NGINX error logs.
242+
NginxLogLevelError NginxErrorLogLevel = "error"
243+
244+
// NginxLogLevelCrit is the crit level for NGINX error logs.
245+
NginxLogLevelCrit NginxErrorLogLevel = "crit"
246+
247+
// NginxLogLevelAlert is the alert level for NGINX error logs.
248+
NginxLogLevelAlert NginxErrorLogLevel = "alert"
249+
250+
// NginxLogLevelEmerg is the emerg level for NGINX error logs.
251+
NginxLogLevelEmerg NginxErrorLogLevel = "emerg"
252+
)

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. Format: [1024 - 65535] | 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.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ nginx:
8888
# -- Is NGINX Plus image being used
8989
plus: false
9090

91+
# -- Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource.
92+
debug: false
93+
9194
# -- The configuration for the data plane that is contained in the NginxProxy resource.
9295
config:
9396
{}
@@ -112,6 +115,8 @@ nginx:
112115
# batchCount: 4
113116
# serviceName: ""
114117
# spanAttributes: []
118+
# logging:
119+
# errorlevel: info
115120

116121
# Configuration for NGINX Plus usage reporting.
117122
usage:

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: {}

Diff for: deploy/crds.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,27 @@ spec:
647647
- ipv4
648648
- ipv6
649649
type: string
650+
logging:
651+
description: Logging defines logging related settings for NGINX.
652+
properties:
653+
errorlevel:
654+
default: info
655+
description: |-
656+
ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
657+
debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
658+
of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
659+
crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
660+
enum:
661+
- debug
662+
- info
663+
- notice
664+
- warn
665+
- error
666+
- crit
667+
- alert
668+
- emerg
669+
type: string
670+
type: object
650671
rewriteClientIP:
651672
description: RewriteClientIP defines configuration for rewriting the
652673
client IP to the original client's IP.

Diff for: deploy/default/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
@@ -299,7 +299,7 @@ spec:
299299
- emptyDir: {}
300300
name: nginx-stream-conf
301301
- emptyDir: {}
302-
name: module-includes
302+
name: nginx-main-includes
303303
- emptyDir: {}
304304
name: nginx-secrets
305305
- emptyDir: {}

0 commit comments

Comments
 (0)