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

✨ Cleanup webhook logging #2326

Merged

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented May 15, 2023

This PR changes UID consistently to requestID + some smaller cleanups.

Result logs look like this:

{"ts":1684151281449.506,"caller":"admission/http.go:96","msg":"admission: received request","v":1,"webhookGroup":"cluster.x-k8s.io","webhookKind":"MachineDeployment","MachineDeployment":{"name":"my-cluster-default-worker-topo-1-nfx2l","namespace":"default"},"namespace":"default","name":"my-cluster-default-worker-topo-1-nfx2l","resource":{"group":"cluster.x-k8s.io","version":"v1beta1","resource":"machinedeployments"},"user":"kubernetes-[redacted secret grafana:admin-user]","requestID":"ab1c2094-178c-413b-b805-f2e2a7ba391d"}
{"ts":1684151281450.1562,"caller":"v1beta1/machinedeployment_webhook.go:365","msg":"admission: Replica field has been defaulted to 1","v":2,"webhookGroup":"cluster.x-k8s.io","webhookKind":"MachineDeployment","MachineDeployment":{"name":"my-cluster-default-worker-topo-1-nfx2l","namespace":"default"},"namespace":"default","name":"my-cluster-default-worker-topo-1-nfx2l","resource":{"group":"cluster.x-k8s.io","version":"v1beta1","resource":"machinedeployments"},"user":"kubernetes-[redacted secret grafana:admin-user]","requestID":"ab1c2094-178c-413b-b805-f2e2a7ba391d"}
{"ts":1684151281450.6433,"caller":"admission/http.go:143","msg":"admission: wrote response","v":1,"webhookGroup":"cluster.x-k8s.io","webhookKind":"MachineDeployment","code":200,"reason":"","message":"","requestID":"ab1c2094-178c-413b-b805-f2e2a7ba391d","allowed":true}

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 15, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbueringer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 15, 2023
@sbueringer sbueringer added this to the v0.15.x milestone May 15, 2023
@sbueringer sbueringer force-pushed the pr-cleanup-webhook-logging branch 3 times, most recently from d03a406 to f36694d Compare May 15, 2023 11:45
@@ -69,7 +69,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// verify the content type is accurate
if contentType := r.Header.Get("Content-Type"); contentType != "application/json" {
err = fmt.Errorf("contentType=%s, expected application/json", contentType)
wh.getLogger(nil).Error(err, "unable to process a request with an unknown content type", "content type", contentType)
wh.getLogger(nil).Error(err, "unable to process a request with unknown content type")
Copy link
Member Author

Choose a reason for hiding this comment

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

content type is already contained in the error + we don't need it as separate k/v pair for log filtering

@@ -93,7 +93,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
wh.writeResponse(w, reviewResponse)
return
}
wh.getLogger(nil).V(1).Info("received request", "UID", req.UID, "kind", req.Kind, "resource", req.Resource)
wh.getLogger(&req).V(1).Info("received request")
Copy link
Member Author

Choose a reason for hiding this comment

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

k/v pairs are added by getLogger, kind is not needed as we already have webhookKind

@sbueringer
Copy link
Member Author

@FillZpp should be removed

/assign @FillZpp @alvaroaleman

@FillZpp
Copy link
Contributor

FillZpp commented May 16, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2023
@k8s-ci-robot k8s-ci-robot merged commit ca1cf6f into kubernetes-sigs:main May 16, 2023
9 checks passed
@sbueringer sbueringer deleted the pr-cleanup-webhook-logging branch May 16, 2023 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants