Skip to content

Commit

Permalink
refactor: fix nil pointer when glog is removed & update old -v= to …
Browse files Browse the repository at this point in the history
…`-log-level=` (#6620)
  • Loading branch information
AlexFenlon authored Oct 9, 2024
1 parent 153224e commit e7e1757
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 45 deletions.
9 changes: 0 additions & 9 deletions cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,6 @@ func initValidate(ctx context.Context) {

func mustValidateInitialChecks(ctx context.Context) {
l := nl.LoggerFromContext(ctx)
err := flag.Lookup("logtostderr").Value.Set("true")
if err != nil {
nl.Fatalf(l, "Error setting logtostderr to true: %v", err)
}

err = flag.Lookup("include_year").Value.Set("true")
if err != nil {
nl.Fatalf(l, "Error setting include_year flag: %v", err)
}

if startupCheckFn != nil {
err := startupCheckFn()
Expand Down
3 changes: 2 additions & 1 deletion deployments/daemon-set/nginx-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ spec:
- -report-ingress-status
- -external-service=nginx-ingress
#- -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
#- -v=3 # Enables extensive logging. Useful for troubleshooting.
#- -log-level=debug # Enables extensive logging. Useful for troubleshooting. Options include: trace, debug, info, warning, error, fatal
#- -log-format=glog # Sets the log format. Options include: glog, json, text
#- -enable-prometheus-metrics
#- -global-configuration=$(POD_NAMESPACE)/nginx-configuration
# initContainers:
Expand Down
3 changes: 2 additions & 1 deletion deployments/daemon-set/nginx-plus-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ spec:
#- -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
#- -enable-app-protect
#- -enable-app-protect-dos
#- -v=3 # Enables extensive logging. Useful for troubleshooting.
#- -log-level=debug # Enables extensive logging. Useful for troubleshooting. Options include: trace, debug, info, warning, error, fatal
#- -log-format=glog # Sets the log format. Options include: glog, json, text
#- -enable-prometheus-metrics
#- -global-configuration=$(POD_NAMESPACE)/nginx-configuration
# initContainers:
Expand Down
3 changes: 2 additions & 1 deletion deployments/deployment/nginx-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ spec:
#- -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
#- -enable-cert-manager
#- -enable-external-dns
#- -v=3 # Enables extensive logging. Useful for troubleshooting.
#- -log-level=debug # Enables extensive logging. Useful for troubleshooting. Options include: trace, debug, info, warning, error, fatal
#- -log-format=glog # Sets the log format. Options include: glog, json, text
#- -enable-prometheus-metrics
#- -global-configuration=$(POD_NAMESPACE)/nginx-configuration
# initContainers:
Expand Down
3 changes: 2 additions & 1 deletion deployments/deployment/nginx-plus-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ spec:
#- -enable-external-dns
#- -enable-app-protect
#- -enable-app-protect-dos
#- -v=3 # Enables extensive logging. Useful for troubleshooting.
#- -log-level=debug # Enables extensive logging. Useful for troubleshooting. Options include: trace, debug, info, warning, error, fatal
#- -log-format=glog # Sets the log format. Options include: glog, json, text
#- -enable-prometheus-metrics
#- -enable-service-insight
#- -global-configuration=$(POD_NAMESPACE)/nginx-configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ spec:
- -nms-server-address=https://apigw.nms.svc.cluster.local:443/api/platform/v1
- -nms-basic-auth-secret=nginx-cluster-connector/nms-basic-auth
# - -cluster-display-name=my-cluster
# - -v=3
# - -log-level=debug
# - -log-format=glog
# - -skip-tls-verify
# - -min-update-interval=24h
8 changes: 4 additions & 4 deletions internal/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,21 +1056,21 @@ func TestCollectInstallationFlags(t *testing.T) {
{
name: "second flag",
setFlags: []string{
"-v=3",
"-log-level=debug",
},
wantFlags: []string{
"-v=3",
"-log-level=debug",
},
},
{
name: "multiple flags",
setFlags: []string{
"nginx-plus=true",
"-v=3",
"-log-level=debug",
},
wantFlags: []string{
"nginx-plus=true",
"-v=3",
"-log-level=debug",
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,6 @@ Path to the TransportServer NGINX configuration template for a TransportServer r
- Default for NGINX is `nginx.transportserver.tmpl`.
- Default for NGINX Plus is `nginx-plus.transportserver.tmpl`.

<a name="cmdoption-v"></a>

---

### -v `<value>`

Log level for V logs.

<a name="cmdoption-log-level"></a>

---
Expand Down
8 changes: 4 additions & 4 deletions site/content/logging-and-monitoring/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ weight: 1800

This document gives an overview of logging provided by NGINX Ingress Controller.

NGINX Ingress Controller exposes the logs of the Ingress Controller process (the process that generates NGINX configuration and reloads NGINX to apply it) and NGINX access and error logs. All logs are sent to the standard output and error of the Ingress Controller process. To view the logs, you can execute the `kubectl logs` command for an Ingress Controller pod. For example:
NGINX Ingress Controller exposes the logs of the Ingress Controller process (the process that generates NGINX configuration and reloads NGINX to apply it) and NGINX access and error logs. All logs are sent to the standard output and error of the NGINX Ingress Controller process. To view the logs, you can execute the `kubectl logs` command for an Ingress Controller pod. For example:

```shell
kubectl logs <nginx-ingress-pod> -n nginx-ingress
```

## Ingress Controller Process Logs
## NGINX Ingress Controller Process Logs

The Ingress Controller process logs are configured through the `-v` command-line argument of the Ingress Controller, which sets the log verbosity level. The default value is `1`, for which the minimum amount of logs is reported. The value `3` is useful for troubleshooting: you will be able to see how the Ingress Controller gets updates from the Kubernetes API, generates NGINX configuration and reloads NGINX.
The NGINX Ingress Controller process logs are configured through the `-log-level` command-line argument of the NGINX Ingress Controller, which sets the log level. The default value is `info`. Other options include: `trace`, `debug`, `info`, `warning`, `error` and `fatal`. The value `debug` is useful for troubleshooting: you will be able to see how NGINX Ingress Controller gets updates from the Kubernetes API, generates NGINX configuration and reloads NGINX.

See also the doc about Ingress Controller [command-line arguments](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments).
See also the doc about NGINX Ingress Controller [command-line arguments](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments).

## NGINX Logs

Expand Down
6 changes: 3 additions & 3 deletions tests/data/virtual-server-certmanager/certmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5186,7 +5186,7 @@ spec:
image: "quay.io/jetstack/cert-manager-cainjector:v1.9.1"
imagePullPolicy: IfNotPresent
args:
- --v=2
- --log-level=debug
- --leader-election-namespace=kube-system
env:
- name: POD_NAMESPACE
Expand Down Expand Up @@ -5238,7 +5238,7 @@ spec:
image: "quay.io/jetstack/cert-manager-controller:v1.9.1"
imagePullPolicy: IfNotPresent
args:
- --v=2
- --log-level=debug
- --cluster-resource-namespace=$(POD_NAMESPACE)
- --leader-election-namespace=kube-system
ports:
Expand Down Expand Up @@ -5291,7 +5291,7 @@ spec:
image: "quay.io/jetstack/cert-manager-webhook:v1.9.1"
imagePullPolicy: IfNotPresent
args:
- --v=2
- --log-level=debug
- --secure-port=10250
- --dynamic-serving-ca-secret-namespace=$(POD_NAMESPACE)
- --dynamic-serving-ca-secret-name=cert-manager-webhook-ca
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_app_protect_watch_namespace_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def fin():
f"-enable-app-protect",
f"-enable-prometheus-metrics",
f"-watch-namespace-label=app=watch",
f"-v=3",
f"-log-level=debug",
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def fin():
"extra_args": [
f"-enable-custom-resources",
f"-enable-app-protect-dos",
f"-v=3",
f"-log-level=debug",
f"-app-protect-dos-debug",
]
}
Expand Down
8 changes: 4 additions & 4 deletions tests/suite/test_filter_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def fin():
@pytest.mark.ingresses
@pytest.mark.parametrize(
"ingress_controller",
[pytest.param({"extra_args": ["-v=3"]})],
[pytest.param({"extra_args": ["-log-level=debug"]})],
indirect=["ingress_controller"],
)
class TestFilterSecret:
Expand All @@ -45,7 +45,7 @@ def test_filter_secret_single_namespace(self, request, kube_apis, ingress_contro
@pytest.mark.ingresses
@pytest.mark.parametrize(
"ingress_controller",
[pytest.param({"extra_args": ["-v=3"]})],
[pytest.param({"extra_args": ["-log-level=debug"]})],
indirect=["ingress_controller"],
)
class TestFilterAfterIcCreated:
Expand Down Expand Up @@ -99,7 +99,7 @@ def fin():
@pytest.mark.ingresses
@pytest.mark.parametrize(
"ingress_controller",
[pytest.param({"extra_args": ["-v=3", "-watch-namespace=filtered-ns-1,filtered-ns-2"]})],
[pytest.param({"extra_args": ["-log-level=debug", "-watch-namespace=filtered-ns-1,filtered-ns-2"]})],
indirect=["ingress_controller"],
)
class TestFilterSecretMultipuleNamespace:
Expand All @@ -114,7 +114,7 @@ def test_filter_secret_multi_namespace(
@pytest.mark.ingresses
@pytest.mark.parametrize(
"ingress_controller",
[pytest.param({"extra_args": ["-v=3", "-watch-namespace=filtered-ns-1,filtered-ns-2"]})],
[pytest.param({"extra_args": ["-log-level=debug", "-watch-namespace=filtered-ns-1,filtered-ns-2"]})],
indirect=["ingress_controller"],
)
class TestFilterSecretMultipleNamespaceAfterIcCreated:
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_transport_server_backup_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def fin():
"type": "complete",
"extra_args": [
"-enable-tls-passthrough=true",
"-v=3",
"-log-level=debug",
],
},
{"example": "transport-server-backup-service", "tls_passthrough_port": 443},
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_transport_server_tcp_load_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def test_secure_tcp_request_load_balanced(
"-global-configuration=nginx-ingress/nginx-configuration",
"-enable-leader-election=false",
"-enable-prometheus-metrics",
"-v=3",
"-log-level=debug",
],
},
{"example": "transport-server-tcp-load-balance"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def fin():
"-enable-custom-resources",
"-enable-prometheus-metrics",
"-weight-changes-dynamic-reload=true",
"-v=3",
"-log-level=debug",
],
},
{"example": "virtual-server-route-weight-changes-dynamic-reload"},
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_backup_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def fin():
"type": "complete",
"extra_args": [
f"-enable-custom-resources",
f"-v=3",
f"-log-level=debug",
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def fin():
"extra_args": [
f"-enable-custom-resources",
f"-enable-app-protect-dos",
f"-v=3",
f"-log-level=debug",
],
},
{"example": "virtual-server-dos", "app_type": "dos"},
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/test_virtual_server_external_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def fin():
"crd_ingress_controller, virtual_server_setup",
[
(
{"type": "complete", "extra_args": [f"-enable-custom-resources", "-v=3"]},
{"type": "complete", "extra_args": [f"-enable-custom-resources", "-log-level=debug"]},
{"example": "virtual-server-externalname", "app_type": "simple"},
)
],
Expand Down

0 comments on commit e7e1757

Please sign in to comment.