-
Notifications
You must be signed in to change notification settings - Fork 42
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
Closes #99: Make logging configurable. #100
Conversation
Hi @fgiloux. Thanks for your PR. I'm waiting for a operator-framework member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
@camilamacedo86 can you please review the PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/ok-to-test |
Pull Request Test Coverage Report for Build 2052966183
💛 - Coveralls |
@theishshah @varshaprasad96 can you please take a look? I would very welcome if we can get it merged soon. |
@theishshah @varshaprasad96 Anything preventing the merge of this PR? |
@fgiloux I made this comment over on the issue. WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
/hold
holding for @joelanford's lgtm based on the last comment.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: varshaprasad96 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 |
@joelanford @varshaprasad96 @camilamacedo86 reworked to address Joe's concerns |
prune/prune.go
Outdated
// Note that there is no compile time check whether a logger can be retrieved by either way. | ||
// keysAndValues allow to add fields to the logs, cf logr documentation. | ||
func Logger(ctx context.Context, cfg Config, keysAndValues ...interface{}) logr.Logger { | ||
log := cfg.Log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of feel like cfg.Log
(if it's set) should win over logr.FromContext()
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that cfg.Log is set once whereas logr.FromContext() can be changed, although unlikely with every request. I picked the one with the scope having the shorter lifetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that if I go to the trouble of setting the logger in the config, that's an extra explicit step I'm taking to say "use this logger". With the code as is, if I was using this in Reconcile
, I'd have to create a new context that drops the logger from the Reconcile context before using the prune functions. That seems pretty awkward.
prune/prune.go
Outdated
func Logger(ctx context.Context, cfg Config, keysAndValues ...interface{}) logr.Logger { | ||
log := cfg.Log | ||
if ctx != nil { | ||
if logger, err := logr.FromContext(ctx); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use controller-runtime's version of this function so that if there isn't a logger in the context, we end up with the controller-runtime's global logger? Or is that too much coupling to controller-runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was to avoid coupling with controller-runtime... but the library has already a dependency on controller-runtime. I think Jeff wanted to make it available to other frameworks, hence
type Config struct {
Clientset kubernetes.Interface // kube client used by pruning
Due to the already existing dependency I can use the controller-runtime version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also means that we will always get a logger from context. In that case this cannot have precedence over the logger set in the config struct otherwise this would never be set.
prune/prune.go
Outdated
@@ -181,3 +181,17 @@ func (config Config) validate() (err error) { | |||
} | |||
return nil | |||
} | |||
|
|||
// Logger returns a logger from the context using logr method or Config.Log if none is found | |||
// controller-runtime automatically provides a logger in context.Context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// controller-runtime automatically provides a logger in context.Context. | |
// controller-runtime automatically provides a logger in context.Context during Reconcile calls. |
Maybe other times as well? This is the only one I know about though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't debate on that :-)
// controller-runtime automatically provides a logger in context.Context. | ||
// Note that there is no compile time check whether a logger can be retrieved by either way. | ||
// keysAndValues allow to add fields to the logs, cf logr documentation. | ||
func Logger(ctx context.Context, cfg Config, keysAndValues ...interface{}) logr.Logger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is exported in controller-runtime and the user can leverage it for custom code that gets injected through PreDeleteHook and CustomStrategy. I am passing the context to them for the purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Makes sense. Thanks for the explanation!
/lgtm |
…xt (controller-runtime way) Signed-off-by: Frederic Giloux <fgiloux@redhat.com>
Hi @joelanford @jmrodri @varshaprasad96 This project is still < 1.0.0, any reason for we do not move forward when the api diff fails? c/c @fgiloux |
Do we know what the impact would be if this broke (what change is necessary for callers?, how many operators are using the library?). I'd say its okay to break this if necessary, but we should generally try to avoid it. Did someone mention that @ryantking had a larger design or some follow-on changes to make? If so, I'd suggest that we try to avoid breaking these APIs twice. |
@camilamacedo86 @joelanford as per #99 the current situation is that Config.log is not exported and not set automatically but it is called in the code. In my opinion this makes the library broken. Hence there is nothing to break. As the prune library is documented in multiple places the urgency is to make it usable That's the aim of this PR.
No impact, adding a field, which is optional is not breaking an API. This means if the library had happened to work it would work further but it did not by any way.
As log is called and not configurable my guess would be exactly 0.
I mentioned that. The EP has been however stale waiting to get merged for months. The urgency is to make a documented library usable. |
Seems like the breaking change is adding a context parameter to the PreDelete and StrategyFunc function signatures. Based on everything @fgiloux said, it seems like a no brainer to get this library to a working state even if that means some minor breaking API changes. /lgtm |
/lgtm |
Description of the change:
Closes #99
This pull request aligns the logging configuration in the prune feature with what is done in the rest of the library. It declares a package level variable for a logger. The logger is retrieved from the controller-runtime library, which is leveraging logr.
Motivation for the change:
The current prune implementation could not be used outside of the prune package as the log field of the Config struct was unexported.
A pull request for amending the documentation will follow.