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
Migrate client-go/metadata to contextual logging #122225
Migrate client-go/metadata to contextual logging #122225
Conversation
Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
@ricardoapl: GitHub didn't allow me to request PR reviews from the following users: kubernetes/wg-structured-logging-reviews. Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs. In response to this:
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. |
Please note that we're already in Test Freeze for the Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Dec 7 16:15:00 UTC 2023. |
Welcome @ricardoapl! |
Hi @ricardoapl. Thanks for your PR. I'm waiting for a kubernetes 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. |
/triage accepted |
@@ -191,7 +191,7 @@ func (c *client) Get(ctx context.Context, name string, opts metav1.GetOptions, s | |||
} | |||
obj, err := result.Get() | |||
if runtime.IsNotRegisteredError(err) { | |||
klog.V(5).Infof("Unable to retrieve PartialObjectMetadata: %#v", err) | |||
klog.FromContext(ctx).V(5).Info("Could not retrieve PartialObjectMetadata", "err", err) |
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.
The unit test(staging/src/k8s.io/client-go/metadata/metadata_test.go) corresponding to the Get
method can use _, ctx := ktesting.NewTestContext(t)
to pass context to test the contextual logging.
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.
Thank you, should be resolved with 04e5522 and fb20f8f
Please take another look
make test WHAT=./staging/src/k8s.io/client-go/metadata/ GOFLAGS="-v"
+++ [1208 10:21:40] Set GOMAXPROCS automatically to 12
+++ [1208 10:21:40] Running tests without code coverage and with -race
=== RUN TestClient
=== RUN TestClient/GET_is_able_to_convert_a_JSON_object_to_PartialObjectMetadata
metadata.go:194: I1208 10:05:11.876937] Could not retrieve PartialObjectMetadata err="no kind \"Pod\" is registered for version \"v1\" in scheme \"k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register.go:27\""
=== RUN TestClient/LIST_is_able_to_convert_a_JSON_object_to_PartialObjectMetadata
metadata.go:230: I1208 10:05:11.878102] Could not retrieve PartialObjectMetadataList err="no kind \"PodList\" is registered for version \"v1\" in scheme \"k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register.go:27\""
=== RUN TestClient/GET_fails_if_the_object_is_JSON_and_has_no_kind
=== RUN TestClient/GET_fails_if_the_object_is_JSON_and_has_no_apiVersion
=== RUN TestClient/GET_fails_if_the_object_is_JSON_and_not_clearly_metadata
metadata.go:194: I1208 10:05:11.880156] Could not retrieve PartialObjectMetadata err="no kind \"Pod\" is registered for version \"v1\" in scheme \"k8s.io/apimachinery/pkg/apis/meta/internalversion/scheme/register.go:27\""
=== RUN TestClient/Delete_fails_if_DeleteOptions_cannot_be_serialized_to_JSON
=== RUN TestClient/DeleteCollection_fails_if_DeleteOptions_cannot_be_serialized_to_JSON
--- PASS: TestClient (0.01s)
--- PASS: TestClient/GET_is_able_to_convert_a_JSON_object_to_PartialObjectMetadata (0.01s)
--- PASS: TestClient/LIST_is_able_to_convert_a_JSON_object_to_PartialObjectMetadata (0.00s)
--- PASS: TestClient/GET_fails_if_the_object_is_JSON_and_has_no_kind (0.00s)
--- PASS: TestClient/GET_fails_if_the_object_is_JSON_and_has_no_apiVersion (0.00s)
--- PASS: TestClient/GET_fails_if_the_object_is_JSON_and_not_clearly_metadata (0.00s)
--- PASS: TestClient/Delete_fails_if_DeleteOptions_cannot_be_serialized_to_JSON (0.00s)
--- PASS: TestClient/DeleteCollection_fails_if_DeleteOptions_cannot_be_serialized_to_JSON (0.00s)
PASS
ok k8s.io/kubernetes/staging/src/k8s.io/client-go/metadata (cached)
@@ -227,7 +227,7 @@ func (c *client) List(ctx context.Context, opts metav1.ListOptions) (*metav1.Par | |||
} | |||
obj, err := result.Get() | |||
if runtime.IsNotRegisteredError(err) { | |||
klog.V(5).Infof("Unable to retrieve PartialObjectMetadataList: %#v", err) | |||
klog.FromContext(ctx).V(5).Info("Could not retrieve PartialObjectMetadataList", "err", err) |
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.
same above.
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.
Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
@@ -55,7 +56,7 @@ func TestClient(t *testing.T) { | |||
testCases := []struct { | |||
name string | |||
handler func(t *testing.T, w http.ResponseWriter, req *http.Request) | |||
want func(t *testing.T, client *Client) | |||
want func(t *testing.T, ctx context.Context, client *Client) |
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.
Typically ctx
is the first parameter in a function. I prefer to follow that also here and below.
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.
Typically ctx is the first parameter in a function.
Indeed. I wasn't sure about it, because I found a few parts of the codebase doing it the other way around.
Should be resolved with 372ecf8
Please take another look
Thank you
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 agree, it's a bit subjective. I got annoyed by the separate parameters and proposed a solution here (still to be implemented, comments welcome): #122148 (comment)
Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
/ok-to-test |
/lgtm Wait for confirmation from the hack & client-go reviewer |
LGTM label has been added. Git tree hash: a763fed9a91a11250086033eeb84cf592da4e225
|
/label tide/merge-method-squash |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ricardoapl, sttts 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 |
* client-go: migrate metadata to contextual logging Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * client-go: test for metadata contextual logs Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: extract context for table driven testing Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: pass context as first parameter Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> --------- Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
* client-go: migrate metadata to contextual logging Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * client-go: test for metadata contextual logs Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: extract context for table driven testing Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: pass context as first parameter Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> --------- Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
* client-go: migrate metadata to contextual logging Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * client-go: test for metadata contextual logs Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: extract context for table driven testing Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: pass context as first parameter Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> --------- Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
* client-go: migrate metadata to contextual logging Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * client-go: test for metadata contextual logs Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: extract context for table driven testing Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> * refactor: pass context as first parameter Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com> --------- Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Migrate client-go/metadata to contextual logging
Which issue(s) this PR fixes:
Part of kubernetes/enhancements#3077
Special notes for your reviewer:
Log output before migration
Log output after migration
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
/wg structured-logging
/area logging
/priority important-longterm
/cc @kubernetes/wg-structured-logging-reviews