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

⚠ Change webhook request received / response written logs to log level 4 #2334

Merged
merged 1 commit into from
May 19, 2023
Merged
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
6 changes: 3 additions & 3 deletions pkg/webhook/admission/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
wh.writeResponse(w, reviewResponse)
return
}
wh.getLogger(&req).V(1).Info("received request")
wh.getLogger(&req).V(4).Info("received request")

reviewResponse = wh.Handle(ctx, req)
wh.writeResponseTyped(w, reviewResponse, actualAdmRevGVK)
Expand Down Expand Up @@ -136,11 +136,11 @@ func (wh *Webhook) writeAdmissionResponse(w io.Writer, ar v1.AdmissionReview) {
}
} else {
res := ar.Response
if log := wh.getLogger(nil); log.V(1).Enabled() {
if log := wh.getLogger(nil); log.V(4).Enabled() {
Copy link
Member

Choose a reason for hiding this comment

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

It is technically a breaking change in that the logs may disappear when running on v1, right?

Copy link
Member Author

@sbueringer sbueringer May 19, 2023

Choose a reason for hiding this comment

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

Yup. Not sure if we consider logs as part of our API. As far as I'm aware k/k doesn't.

If it's just about changing the PR title, no objections against changing to breaking

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the PR title

Copy link
Member

Choose a reason for hiding this comment

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

I don't have full context and I defer the decision to the team, but as far as I remember in previous versions of controller runtime those logs lines were not generated, so it could also be considered a fix...

Copy link
Member

@alvaroaleman alvaroaleman May 19, 2023

Choose a reason for hiding this comment

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

Oh okay, is this new relative to 0.14?

Copy link
Member Author

@sbueringer sbueringer May 19, 2023

Choose a reason for hiding this comment

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

Just checked. The behavior was the same with 0.14. We just didn't notice it before as we are running our controllers per default with log level 0. (we just use a higher log level for dev)

The recommended production log level is 2 though IIRC. I couldn't find a quote for that though.

But based on the guidance I think 1 is not appropriate (https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md).

if res.Result != nil {
log = log.WithValues("code", res.Result.Code, "reason", res.Result.Reason, "message", res.Result.Message)
}
log.V(1).Info("wrote response", "requestID", res.UID, "allowed", res.Allowed)
log.V(4).Info("wrote response", "requestID", res.UID, "allowed", res.Allowed)
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/webhook/authentication/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ar.SetGroupVersionKind(authenticationv1.SchemeGroupVersion.WithKind("TokenReview"))
_, actualTokRevGVK, err := authenticationCodecs.UniversalDeserializer().Decode(body, nil, &ar)
if err != nil {
wh.getLogger(&req).Error(err, "unable to decode the request")
wh.getLogger(nil).Error(err, "unable to decode the request")
reviewResponse = Errored(err)
wh.writeResponse(w, reviewResponse)
return
}
wh.getLogger(&req).V(1).Info("received request")
wh.getLogger(&req).V(4).Info("received request")

if req.Spec.Token == "" {
err = errors.New("token is empty")
Expand Down Expand Up @@ -135,9 +135,7 @@ func (wh *Webhook) writeTokenResponse(w io.Writer, ar authenticationv1.TokenRevi
wh.writeResponse(w, Errored(err))
}
res := ar
if wh.getLogger(nil).V(1).Enabled() {
wh.getLogger(nil).V(1).Info("wrote response", "requestID", res.UID, "authenticated", res.Status.Authenticated)
}
wh.getLogger(nil).V(4).Info("wrote response", "requestID", res.UID, "authenticated", res.Status.Authenticated)
}

// unversionedTokenReview is used to decode both v1 and v1beta1 TokenReview types.
Expand Down