mirror of https://github.com/linkerd/linkerd2.git
Ensure consistent JSON logging for proxy-injector container (#13335)
Ensure consistent JSON logging for proxy-injector container
When JSON logging is enabled in the proxy-injector `controllerLogFormat: json` some log messages adhere to the JSON format while others do not. This inconsistency creates difficulty in parsing logs, especially in automated workflows. For example:
```
{"level":"info","msg":"received admission review request \"83a0ce4d-ab81-42c9-abe4-e0ade0f926e2\"","time":"2024-10-10T21:06:18Z"}
time="2024-10-10T21:06:18Z" level=info msg="received pod/mypod"
```
Modified the logging implementation in the `controller/proxy-injector/webhook.go` to ensure all log messages follow the JSON format consistently. This was achieved by removing a new instance of the logrus logger that was being created in the file and replacing it with the global logger instance, ensuring all logs respect the controllerLogFormat configuration.
Reproduced the issue by enabling JSON logging and observing mixed-format logs when install the emojivoto sample application. Applied the changes and verified that all logs consistently use the JSON format.
Ran the linkerd check command and confirmed there are no additional warnings or issues.
Tested various scenarios, including pods with and without the injection annotation, to ensure consistent logging behavior.
Fixes #13168
Signed-off-by: Micah See msee@usc.edu
This commit is contained in:
parent
c3261ed7c3
commit
264b67c5fe
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/linkerd/linkerd2/pkg/inject"
|
"github.com/linkerd/linkerd2/pkg/inject"
|
||||||
pkgK8s "github.com/linkerd/linkerd2/pkg/k8s"
|
pkgK8s "github.com/linkerd/linkerd2/pkg/k8s"
|
||||||
"github.com/linkerd/linkerd2/pkg/version"
|
"github.com/linkerd/linkerd2/pkg/version"
|
||||||
"github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
admissionv1beta1 "k8s.io/api/admission/v1beta1"
|
admissionv1beta1 "k8s.io/api/admission/v1beta1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
@ -25,8 +25,6 @@ const (
|
||||||
eventTypeInjected = "Injected"
|
eventTypeInjected = "Injected"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logrus.New()
|
|
||||||
|
|
||||||
// Inject returns the function that produces an AdmissionResponse containing
|
// Inject returns the function that produces an AdmissionResponse containing
|
||||||
// the patch, if any, to apply to the pod (proxy sidecar and eventually the
|
// the patch, if any, to apply to the pod (proxy sidecar and eventually the
|
||||||
// init container to set it up)
|
// init container to set it up)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue