Skip to content

Use contextual logging #337

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

Merged
merged 5 commits into from
Feb 15, 2025
Merged

Conversation

tchap
Copy link
Contributor

@tchap tchap commented Feb 14, 2025

All possible direct klog calls are removed.
Instead logr.Logger is loaded from the context
or passed around as an argument.

Related to #251 , this basically concludes the issue.

Testing

Regarding testing, this is pretty hard to test. I am not really able to run integration tests and failing to call ctrl.SetLogger and loading a logger from the context would result, I guess, in log entries being dropped. I don't think this can really happen as ctrl.SetLogger is being called for sure, but it does seem a bit fragile.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 14, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @tchap. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 14, 2025
@tchap tchap force-pushed the contextual-logging branch from 9712144 to 4c6d700 Compare February 14, 2025 11:45
Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 9712144
🔍 Latest deploy log https://app.netlify.com/sites/gateway-api-inference-extension/deploys/67af2ccf177a940008856f59
😎 Deploy Preview https://deploy-preview-337--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 8e8f36f
🔍 Latest deploy log https://app.netlify.com/sites/gateway-api-inference-extension/deploys/67b0e388f8bcdb0009ef5b02
😎 Deploy Preview https://deploy-preview-337--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

targetModelName: "t20",
receivedTime: timeBaseline,
completeTime: timeBaseline.Add(time.Millisecond * 120),
}{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Formatting improved as a side effect, ignore.

if err := p.refreshMetricsOnce(); err != nil {
klog.V(logutil.TRACE).ErrorS(err, "Failed to refresh metrics")
if err := p.refreshMetricsOnce(logger); err != nil {
logger.V(logutil.DEFAULT).Error(err, "Failed to refresh metrics")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually changed this to DEFAULT as I feel logging errors on TRACE is weird, but unsure.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just get very spammy if the errors are transient, but I suppose it's a fair point that you want to be aware of the error regardless.

Copy link
Contributor

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

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

I have a few comments that don't block this PR and we can address as followup since it is huge. But overall I am onboard with this. will let @kfswain make the final pass and lgtm when ready.

@kfswain
Copy link
Collaborator

kfswain commented Feb 14, 2025

This overall lgtm, I do agree with the context as the param so long as the logger lookup is not expensive. However I'm familiarizing myself with https://github.com/go-logr/logr/tree/v1.4.2 before I LGTM. Will follow up shortly

@kfswain
Copy link
Collaborator

kfswain commented Feb 14, 2025

Read through the blog post linked in: https://github.com/go-logr/logr/tree/v1.4.2?tab=readme-ov-file#inspiration As well as where logr chooses to disagree. And I'm aligned with those opinions for certain.

/lgtm
/hold

I think the context comments can be handled in a following PR, just holding to give time for an Ack. Thanks for all the help!

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 14, 2025
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 14, 2025
@tchap
Copy link
Contributor Author

tchap commented Feb 15, 2025

Aligned the log levels and passing a ctx around instead of a logger, so all review issues should be fixed now.

Seems I also still need ok-to-test...

@tchap tchap force-pushed the contextual-logging branch from df7a7ae to dc4c922 Compare February 15, 2025 13:17
@tchap
Copy link
Contributor Author

tchap commented Feb 15, 2025

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 15, 2025
@kfswain
Copy link
Collaborator

kfswain commented Feb 15, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 15, 2025
@tchap tchap force-pushed the contextual-logging branch from dc4c922 to 2320fe5 Compare February 15, 2025 15:21
All possible direct klog calls are removed.
Instead logr.Logger is loaded from the context
or passed around as an argument.
@tchap tchap force-pushed the contextual-logging branch from 2320fe5 to 04b2967 Compare February 15, 2025 15:23
Copy link
Contributor

@ahg-g ahg-g left a comment

Choose a reason for hiding this comment

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

Sorry, a couple more nits

tchap and others added 2 commits February 15, 2025 19:55
Co-authored-by: Abdullah Gharaibeh <[email protected]>
@ahg-g
Copy link
Contributor

ahg-g commented Feb 15, 2025

/lgtm
/approve

This is awesome, great work!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 15, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, tchap

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 15, 2025
@k8s-ci-robot k8s-ci-robot merged commit 6b42ab8 into kubernetes-sigs:main Feb 15, 2025
8 checks passed
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants