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

Add configurable data plane log level #2561

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apis/v1alpha1/nginxproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type NginxProxySpec struct {
// +optional
//nolint:lll
RewriteClientIP *RewriteClientIP `json:"rewriteClientIP,omitempty"`
// Logging defines logging related settings for NGINX.
//
// +optional
Logging *NginxLogging `json:"logging,omitempty"`
// DisableHTTP2 defines if http2 should be disabled for all servers.
// Default is false, meaning http2 will be enabled for all servers.
//
Expand Down Expand Up @@ -203,3 +207,46 @@ const (
// kubebuilder:validation:Pattern=`^[\.a-zA-Z0-9:]*(\/([0-9]?[0-9]?[0-9]))$`
AddressTypeCIDR AddressType = "cidr"
)

// NginxLogging defines logging related settings for NGINX.
type NginxLogging struct {
// ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
// debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
// of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
// crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
//
// +optional
// +kubebuilder:default=info
ErrorLevel *NginxErrorLogLevel `json:"errorlevel,omitempty"`
}

// NginxErrorLogLevel type defines the log level of error logs for NGINX.
//
// +kubebuilder:validation:Enum=debug;info;notice;warn;error;crit;alert;emerg
type NginxErrorLogLevel string

const (
// NginxLogLevelDebug is the debug level for NGINX error logs.
NginxLogLevelDebug NginxErrorLogLevel = "debug"

// NginxLogLevelInfo is the info level for NGINX error logs.
NginxLogLevelInfo NginxErrorLogLevel = "info"

// NginxLogLevelNotice is the notice level for NGINX error logs.
NginxLogLevelNotice NginxErrorLogLevel = "notice"

// NginxLogLevelWarn is the warn level for NGINX error logs.
NginxLogLevelWarn NginxErrorLogLevel = "warn"

// NginxLogLevelError is the error level for NGINX error logs.
NginxLogLevelError NginxErrorLogLevel = "error"

// NginxLogLevelCrit is the crit level for NGINX error logs.
NginxLogLevelCrit NginxErrorLogLevel = "crit"

// NginxLogLevelAlert is the alert level for NGINX error logs.
NginxLogLevelAlert NginxErrorLogLevel = "alert"

// NginxLogLevelEmerg is the emerg level for NGINX error logs.
NginxLogLevelEmerg NginxErrorLogLevel = "emerg"
)
25 changes: 25 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

8 changes: 5 additions & 3 deletions build/Dockerfile.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ ARG BUILD_AGENT

RUN apk add --no-cache libcap \
&& mkdir -p /var/lib/nginx /usr/lib/nginx/modules \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
bjee19 marked this conversation as resolved.
Show resolved Hide resolved
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
&& apk del libcap

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

USER 101:1001

CMD ["sh", "-c", "rm -rf /var/run/nginx/*.sock && /docker-entrypoint.sh nginx -g 'daemon off;'"]
CMD ["sh", "-c", "rm -rf /var/run/nginx/*.sock && nginx -g 'daemon off;'"]
6 changes: 4 additions & 2 deletions build/Dockerfile.nginxplus
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ RUN --mount=type=secret,id=nginx-repo.crt,dst=/etc/apk/cert.pem,mode=0644 \
&& 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 \
&& apk add --no-cache nginx-plus nginx-plus-module-njs nginx-plus-module-otel libcap \
&& mkdir -p /var/lib/nginx /usr/lib/nginx/modules \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx \
&& setcap 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
&& setcap -v 'cap_net_bind_service=+ep' /usr/sbin/nginx-debug \
&& apk del libcap \
# forward request and error logs to docker log collector
&& ln -sf /dev/stdout /var/log/nginx/access.log \
Expand Down
1 change: 1 addition & 0 deletions charts/nginx-gateway-fabric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
| `metrics.port` | Set the port where the Prometheus metrics are exposed. Format: [1024 - 65535] | int | `9113` |
| `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` |
| `nginx.config` | The configuration for the data plane that is contained in the NginxProxy resource. | object | `{}` |
| `nginx.debug` | Is NGINX run in debug mode. This should be used with setting the NGINX error log level to debug. | bool | `false` |
| `nginx.extraVolumeMounts` | extraVolumeMounts are the additional volume mounts for the nginx container. | list | `[]` |
| `nginx.image.pullPolicy` | | string | `"Always"` |
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginxinc/nginx-gateway-fabric/nginx"` |
Expand Down
17 changes: 12 additions & 5 deletions charts/nginx-gateway-fabric/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ spec:
mountPath: /etc/nginx/conf.d
- name: nginx-stream-conf
mountPath: /etc/nginx/stream-conf.d
- name: module-includes
mountPath: /etc/nginx/module-includes
- name: main-includes
mountPath: /etc/nginx/main-includes
- name: nginx-secrets
mountPath: /etc/nginx/secrets
- name: nginx-run
Expand Down Expand Up @@ -170,8 +170,8 @@ spec:
mountPath: /etc/nginx/conf.d
- name: nginx-stream-conf
mountPath: /etc/nginx/stream-conf.d
- name: module-includes
mountPath: /etc/nginx/module-includes
- name: main-includes
mountPath: /etc/nginx/main-includes
- name: nginx-secrets
mountPath: /etc/nginx/secrets
- name: nginx-run
Expand All @@ -183,6 +183,13 @@ spec:
{{- with .Values.nginx.extraVolumeMounts -}}
{{ toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.nginx.debug}}
command:
- "/bin/sh"
args:
- "-c"
- "rm -rf /var/run/nginx/*.sock && nginx-debug -g 'daemon off;'"
{{- end }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
{{- if .Values.affinity }}
affinity:
Expand All @@ -206,7 +213,7 @@ spec:
emptyDir: {}
- name: nginx-stream-conf
emptyDir: {}
- name: module-includes
- name: main-includes
emptyDir: {}
- name: nginx-secrets
emptyDir: {}
Expand Down
5 changes: 5 additions & 0 deletions charts/nginx-gateway-fabric/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ nginx:
# -- Is NGINX Plus image being used
plus: false

# -- Is NGINX run in debug mode. This should be used with setting the NGINX error log level to debug.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kate-osborn Should the wording on the comment be more strict to specify "require"?

I think it'd be fine to run NGINX in debug mode without NGINX error log level being debug, there'd be no point but I'd be fine with that. I can change this to something like "In order for this to be useful, NGINX error log level should be set to debug" or anything you suggest.

debug: false

# -- The configuration for the data plane that is contained in the NginxProxy resource.
config:
{}
Expand All @@ -112,6 +115,8 @@ nginx:
# batchCount: 4
# serviceName: ""
# spanAttributes: []
# logging:
# errorlevel: info

# Configuration for NGINX Plus usage reporting.
usage:
Expand Down
21 changes: 21 additions & 0 deletions config/crd/bases/gateway.nginx.org_nginxproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ spec:
- ipv4
- ipv6
type: string
logging:
description: Logging defines logging related settings for NGINX.
properties:
errorlevel:
default: info
description: |-
ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
enum:
- debug
- info
- notice
- warn
- error
- crit
- alert
- emerg
type: string
type: object
rewriteClientIP:
description: RewriteClientIP defines configuration for rewriting the
client IP to the original client's IP.
Expand Down
10 changes: 5 additions & 5 deletions config/tests/static-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ spec:
mountPath: /etc/nginx/conf.d
- name: nginx-stream-conf
mountPath: /etc/nginx/stream-conf.d
- name: module-includes
mountPath: /etc/nginx/module-includes
- name: main-includes
mountPath: /etc/nginx/main-includes
- name: nginx-secrets
mountPath: /etc/nginx/secrets
- name: nginx-run
Expand Down Expand Up @@ -106,8 +106,8 @@ spec:
mountPath: /etc/nginx/conf.d
- name: nginx-stream-conf
mountPath: /etc/nginx/stream-conf.d
- name: module-includes
mountPath: /etc/nginx/module-includes
- name: main-includes
mountPath: /etc/nginx/main-includes
- name: nginx-secrets
mountPath: /etc/nginx/secrets
- name: nginx-run
Expand All @@ -127,7 +127,7 @@ spec:
emptyDir: {}
- name: nginx-stream-conf
emptyDir: {}
- name: module-includes
- name: main-includes
emptyDir: {}
- name: nginx-secrets
emptyDir: {}
Expand Down
10 changes: 5 additions & 5 deletions deploy/aws-nlb/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand Down Expand Up @@ -280,8 +280,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand All @@ -302,7 +302,7 @@ spec:
- emptyDir: {}
name: nginx-stream-conf
- emptyDir: {}
name: module-includes
name: main-includes
- emptyDir: {}
name: nginx-secrets
- emptyDir: {}
Expand Down
10 changes: 5 additions & 5 deletions deploy/azure/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand Down Expand Up @@ -277,8 +277,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand All @@ -301,7 +301,7 @@ spec:
- emptyDir: {}
name: nginx-stream-conf
- emptyDir: {}
name: module-includes
name: main-includes
- emptyDir: {}
name: nginx-secrets
- emptyDir: {}
Expand Down
21 changes: 21 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,27 @@ spec:
- ipv4
- ipv6
type: string
logging:
description: Logging defines logging related settings for NGINX.
properties:
errorlevel:
default: info
description: |-
ErrorLevel defines the error log level. Possible log levels listed in order of increasing severity are
debug, info, notice, warn, error, crit, alert, and emerg. Setting a certain log level will cause all messages
of the specified and more severe log levels to be logged. For example, the log level 'error' will cause error,
crit, alert, and emerg messages to be logged. https://nginx.org/en/docs/ngx_core_module.html#error_log
enum:
- debug
- info
- notice
- warn
- error
- crit
- alert
- emerg
type: string
type: object
rewriteClientIP:
description: RewriteClientIP defines configuration for rewriting the
client IP to the original client's IP.
Expand Down
10 changes: 5 additions & 5 deletions deploy/default/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand Down Expand Up @@ -277,8 +277,8 @@ spec:
name: nginx-conf
- mountPath: /etc/nginx/stream-conf.d
name: nginx-stream-conf
- mountPath: /etc/nginx/module-includes
name: module-includes
- mountPath: /etc/nginx/main-includes
name: main-includes
- mountPath: /etc/nginx/secrets
name: nginx-secrets
- mountPath: /var/run/nginx
Expand All @@ -299,7 +299,7 @@ spec:
- emptyDir: {}
name: nginx-stream-conf
- emptyDir: {}
name: module-includes
name: main-includes
- emptyDir: {}
name: nginx-secrets
- emptyDir: {}
Expand Down
Loading
Loading