-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
component-helpers: Support structured and contextual logging #120637
component-helpers: Support structured and contextual logging #120637
Conversation
Skipping CI for Draft Pull Request. |
def55dc
to
196cf2a
Compare
/wg structured-logging /assign @pohly |
/remove-sig api-machinery |
/triage accepted |
@@ -28,7 +28,7 @@ import ( | |||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |||
"k8s.io/client-go/informers" | |||
"k8s.io/client-go/kubernetes/fake" | |||
"k8s.io/klog/v2/ktesting" | |||
"k8s.io/kubernetes/test/utils/ktesting" |
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.
There's no need for this change, can you remove it?
Otherwise it would be better to use tCtx
instead of ctx
below to indicate that k/k ktesting (in contrast to klog ktesting) returns more than just a context.Context
.
@bells17: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
@pohly I have made the necessary corrections. Could you please review them again? |
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
LGTM label has been added. Git tree hash: ec6481fde3a099229eb832ce2697285d60c76ac4
|
/label tide/merge-method-squash @bells17: should you need to update the PR again, then feel free to squash manually with a single, clean commit message. |
@@ -750,7 +750,7 @@ func nodeAddressesChangeDetected(addressSet1, addressSet2 []v1.NodeAddress) bool | |||
return false | |||
} | |||
|
|||
func updateNodeAddressesFromNodeIP(node *v1.Node, nodeAddresses []v1.NodeAddress) ([]v1.NodeAddress, error) { | |||
func updateNodeAddressesFromNodeIP(ctx context.Context, node *v1.Node, nodeAddresses []v1.NodeAddress) ([]v1.NodeAddress, error) { |
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.
where is this context used?
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.
Not used (anymore?).
@bells17: can you remove the parameter? Please squash (but don't rebase!) during your next push.
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.
where is this context used?
Not used (anymore?)
Thank you. This change was unnecessary, so I removed it.
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.
@pohly I have squashed the commits into one. I followed the steps below, but please let me know if there are any issues with the procedure.
$ git rebase -i HEAD~6
$ git push origin component-helpers-structured-and-contextual-logging --force
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.
2576586
to
5a3fd49
Compare
// cloudProvider is unset or `"external"`. | ||
func ParseNodeIPArgument(nodeIP, cloudProvider string) ([]net.IP, error) { | ||
// ParseNodeIPArgument parses kubelet's --node-ip argument. | ||
// If nodeIP contains invalid values, they will be returned as strings. |
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 API now is really weird, I assume that is to avoid logging inside a library that ... IIRC we have to do because of the sloppy IPs thing, and is only used in this file and in cmd/kubelet so I think that is not as bad ... @danwinship 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.
I'm to blame for the API, see #120637 (comment) for reference 😅
IMHO having a parser function do logging to inform the user should better be avoided. It depends on the context in which the parsing happens if and how the user should be informed, which isn't known to the function.
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 added parseNodeIP
originally but I feel like sig-node owns it now so it's more up to them.
The logging-in-the-middle-of-a-helper-function was just to preserve the original behavior where it used to be logging directly from cmd/kubelet/app/server.go
, and probably I wouldn't have done it that way if I'd had to think about contexts/loggers at the time.
One possibility would be to not change the API of parseNodeIPs
, and just have RunKubelet
check if len(nodeIPs) == len(strings.Split(kubeServer.NodeIP, ","))
and warn that "some values" were invalid and were ignored if not.
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.
or return (nodeIPs []net.IP, warning, err error)
or (nodeIPs []net.IP, fatal bool, err error)
(I feel like "fatal" should come after "err" there except that "err" should always be last...)
I was just dealing with the same thing in another PR. Maybe we need a standard convention for functions that want to emit/return both warnings and errors?
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.
Returning warning
(presumably a string) and a non-fatal pre-formatted error in the second case both have the problem that they use unstructured formatting (i.e. some flavor of fmt.Sprintf) of a message. That might not work well when the caller uses structured logging. I prefer returning just the information about a problem and leaving the formatting of that to the caller.
len(nodeIPs) == len(strings.Split(kubeServer.NodeIP, ","))
feels like it defeats the purpose of abstracting the parsing in a helper function.
I added parseNodeIP originally but I feel like sig-node owns it now so it's more up to them.
They'll probably just defer to you 😜
Do you want to pull someone else in or do you feel confident going ahead with it as-is and approving it?
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.
Maybe we need a standard convention for functions that want to emit/return both warnings and errors?
Defining conventions is hard, ensuring that fellow developers know about them and follow them is even harder. I suspect unless Go itself defines something, we won't have a chance to establish this on our own for Kubernetes.
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.
@mrunalp: you reviewed this earlier for SIG Node. Any opinion ("I feel like sig-node owns it now so it's more up to them")? ^^^
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.
Do you want to pull someone else in or do you feel confident going ahead with it as-is and approving it?
I don't have approver bits on those directories anyway...
I prefer returning just the information about a problem and leaving the formatting of that to the caller.
I guess that since the semantics of the function are essentially "parse the valid IPs but ignore the invalid ones for backward-compatibility reasons", then returning a list of the invalid IPs does make sense.
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 don't have approver bits on those directories anyway...
@mrunalp already approved earlier. What I need from you (or someone from SIG Networking) is approval for pkg/controller/nodeipam/ipam/OWNERS - I know, it's complicated 😢
LGTM the networking bits, just one question on the ParseNodeIPArgument function that I prefer @danwinship to take a look as he has more context |
/approve |
/lgtm |
LGTM label has been added. Git tree hash: c18b444697d6bdc0834e3912978b42329d5ebbd5
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bells17, danwinship, mrunalp, pohly, wojtek-t 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Implement support for structured logging and contextual logging in component-helpers.
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md
I've unified the implementation to use contextual logging, as some parts of component-helpers were already using contextual logging.
Which issue(s) this PR fixes:
Fixes #120638
Special notes for your reviewer:
I've confirmed that they pass the logcheck tests:
Does this PR introduce a user-facing change?