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

✨ Surface API Server warnings in client #1468

Merged
merged 2 commits into from
Apr 13, 2021
Merged

✨ Surface API Server warnings in client #1468

merged 2 commits into from
Apr 13, 2021

Conversation

MadhavJivrajani
Copy link
Contributor

@MadhavJivrajani MadhavJivrajani commented Apr 4, 2021

  • Add a WarningHandler that writes to stderr
    • Deduplicates warnings
    • Highlight warning output with color when the outut supports it

Fix #1150

/hold
/cc joelanford

  • Currently, by default warnings are surfaced, should an option be provided to turn off the warnings if needed as illustrated here?

@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 Apr 4, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @MadhavJivrajani!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 4, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @MadhavJivrajani. 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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 4, 2021
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/ok-to-test

pkg/client/client.go Outdated Show resolved Hide resolved
@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 Apr 4, 2021
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 8, 2021
- Add a wrapper around `logr.Logger` that implements WarnignHandler
- Add options in client.go for settiing up behaviour of warning handler

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
@MadhavJivrajani
Copy link
Contributor Author

/hold cancel

@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 Apr 11, 2021
pkg/client/client.go Outdated Show resolved Hide resolved
pkg/log/warning_handler.go Outdated Show resolved Hide resolved
pkg/client/client.go Outdated Show resolved Hide resolved
pkg/log/warning_handler.go Outdated Show resolved Hide resolved
Deduplicate: !options.Opts.AllowDuplicateLogs,
},
),
)
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering a bit if the client is the best place to plug this in. Maybe pkg/cluster would be better? Or both?
Many ppl will use the cache-backed client and all its read operations will not have this enabled since they go through the cache.
cc @vincepri

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
}
l.written[message] = struct{}{}
}
l.logger.Info(message)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
l.logger.Info(message)
l.logger.Warn(message)

Copy link
Contributor Author

@MadhavJivrajani MadhavJivrajani Apr 13, 2021

Choose a reason for hiding this comment

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

One clarification: if I understand correctly, the logr.Logger interface doesn't implement a Warn level and instead recommends specifying verbosity levels for Info logs itself as explained here, so maybe setting a verbosity level using V or using coloured output for the Info messages that come out of the API Warning Logger?

Copy link
Member

Choose a reason for hiding this comment

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

I see, lets keep it at Info then

@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 13, 2021
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks for your work!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, MadhavJivrajani

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 Apr 13, 2021
@k8s-ci-robot k8s-ci-robot merged commit 7ef2da0 into kubernetes-sigs:master Apr 13, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.9.x milestone Apr 13, 2021
@MadhavJivrajani
Copy link
Contributor Author

Thanks so much for the constant feedback @alvaroaleman! I had a great time working on this 😄

RainbowMango pushed a commit to RainbowMango/controller-runtime that referenced this pull request Sep 1, 2021
* Surface API Server warnings in client

- Add a wrapper around `logr.Logger` that implements WarnignHandler
- Add options in client.go for settiing up behaviour of warning handler

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

* rename logger type

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
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/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Surface warnings sent by apiserver via client-go
3 participants