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

webhook: switch to contextual logger #1295

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

ykaliuta
Copy link
Contributor

@ykaliuta ykaliuta commented Oct 10, 2024

Jira: https://issues.redhat.com/browse/RHOAIENG-14419

Use k8s contextual logger instead of own. Comparing to other parts of the operator webhook is a bit special since it serves own endpoints and has context independent from controllers.

Include more info (operation), just to get more details. Do not add kind since it's clear from "resource" field.

Since controller-framework adds "admission" to the name, use own LogConstructor with own base logger for the framework's DefaultLogConstructor.

Add name locally to distinguish from framework's messages.

Add Name field to the structures to avoid copying string literal for both WithName() and WithValues().

The output changes and it looks like

{"level":"info","ts":"2024-10-11T05:17:20Z","logger":"ValidatingWebhook","msg":"Validation request","object":{"name":"default-dsci"},"namespace":"","name":"default-dsci","resource":{"group":"dscinitialization.opendatahub.io","version":"v1","resource":"dscinitializations"},"user":"kube:admin","requestID":"e5bf3768-6faa-4e14-9004-e54ee84ad8b7","webhook":"ValidatingWebhook","operation":"CREATE"}

or for the defaulter:

{"level":"info","ts":"2024-10-11T04:50:48Z","logger":"DefaultingWebhook","msg":"Defaulting DSC","object":{"name":"default-dsc"},"namespace":"","name":"default-dsc","resource":{"group":"datasciencecluster.opendatahub.io","version":"v1","resource":"datascienceclusters"},"user":"kube:admin","requestID":"c9213ff3-80ee-40c0-9f15-12188dece68e","webhook":"DefaultingWebhook"}

(the messages are not from the current codebase, was added for demo only)

Description

How Has This Been Tested?

Screenshot or short clip

Merge criteria

  • You have read the contributors guide.
  • Commit messages are meaningful - have a clear and concise summary and detailed explanation of what was changed and why.
  • Pull Request contains a description of the solution, a link to the JIRA issue, and to any dependent or related Pull Request.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@ykaliuta
Copy link
Contributor Author

/cc @lburgazzoli @zdtsw

@openshift-ci openshift-ci bot requested a review from zdtsw October 10, 2024 05:23
@ykaliuta
Copy link
Contributor Author

ykaliuta commented Oct 10, 2024

I can add "webhook" to the name, may be it will make filtering a bit easy( .WithName("webhook") should make "logger": "admission.webhook"). What do you think?

{"level":"info","ts":"2024-10-10T07:10:07Z","logger":"admission.webhook","msg":"Got request","object":{"name":"default-dsc"},"namespace":"","name":"default-dsc","resource":{"group":"datasciencecluster.opendatahub.io","version":"v1","resource":"datascienceclusters"},"user":"kube:admin","requestID":"031bd339-2da2-4c42-aa76-44bc6f571ce2"}

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.

Please upload report for BASE (incubation@e8e266f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
controllers/webhook/webhook.go 73.33% 4 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             incubation    #1295   +/-   ##
=============================================
  Coverage              ?   19.24%           
=============================================
  Files                 ?       30           
  Lines                 ?     2676           
  Branches              ?        0           
=============================================
  Hits                  ?      515           
  Misses                ?     2099           
  Partials              ?       62           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lburgazzoli
Copy link
Contributor

+1 to add webhook to the name

Copy link

openshift-ci bot commented Oct 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: zdtsw

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

@zdtsw
Copy link
Member

zdtsw commented Oct 10, 2024

/onhold

@zdtsw
Copy link
Member

zdtsw commented Oct 10, 2024

did not see the comments that you wanna add the name

Copy link

openshift-ci bot commented Oct 11, 2024

New changes are detected. LGTM label has been removed.

@ykaliuta
Copy link
Contributor Author

Updated. Wondering, would it be better to move newLogConstructor to logger package.

@ykaliuta ykaliuta force-pushed the logger-webhook branch 3 times, most recently from bf3ab29 to 7c99412 Compare October 11, 2024 05:19
@ykaliuta
Copy link
Contributor Author

/cc @bartoszmajsak

@lburgazzoli
Copy link
Contributor

LGTM, I let @zdtsw for final review

@zdtsw
Copy link
Member

zdtsw commented Oct 11, 2024

i am fine with the change, only one part i am not sure is Name: "DSCDefaulter",
when i added the DSCDefaulter, it was used for internal type/variable, but if we want it be in the logger , it could get confused for the one does not know the detail of code.
can it be something maybe MutatingDefaultWebhook ?

@ykaliuta
Copy link
Contributor Author

i am fine with the change, only one part i am not sure is Name: "DSCDefaulter", when i added the DSCDefaulter, it was used for internal type/variable, but if we want it be in the logger , it could get confused for the one does not know the detail of code. can it be something maybe MutatingDefaultWebhook ?

Good point. Will "DefaultingWebhook" work?

Use k8s contextual logger instead of own. Comparing to other parts
of the operator webhook is a bit special since it serves own
endpoints and has context independent from controllers.

Include more info (operation), just to get more details. Do not add
kind since it's clear from "resource" field.

Since controller-framework adds "admission" to the name, use own
LogConstructor with own base logger for the framework's
DefaultLogConstructor.

Add name locally to distinguish from framework's messages.

Add Name field to the structures to avoid copying string literal for
both WithName() and WithValues().

The output changes and it looks like

```
{"level":"info","ts":"2024-10-11T05:17:20Z","logger":"ValidatingWebhook","msg":"Validation request","object":{"name":"default-dsci"},"namespace":"","name":"default-dsci","resource":{"group":"dscinitialization.opendatahub.io","version":"v1","resource":"dscinitializations"},"user":"kube:admin","requestID":"e5bf3768-6faa-4e14-9004-e54ee84ad8b7","webhook":"ValidatingWebhook","operation":"CREATE"}
```

or for the defaulter:

```
{"level":"info","ts":"2024-10-11T04:50:48Z","logger":"DefaultingWebhook","msg":"Defaulting DSC","object":{"name":"default-dsc"},"namespace":"","name":"default-dsc","resource":{"group":"datasciencecluster.opendatahub.io","version":"v1","resource":"datascienceclusters"},"user":"kube:admin","requestID":"c9213ff3-80ee-40c0-9f15-12188dece68e","webhook":"DefaultingWebhook"}
```

(the messages are not from the current codebase, was added for demo only)

Signed-off-by: Yauheni Kaliuta <[email protected]>
@ykaliuta
Copy link
Contributor Author

/unhold

@zdtsw zdtsw merged commit 2eed721 into opendatahub-io:incubation Oct 14, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants