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

RFC: ktesting: add object formatter #116952

Closed
wants to merge 1 commit into from

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Mar 27, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

This is useful for logging types which implement String incorrectly, for example by inheriting it from metav1.TypeMeta. If implementing fmt.Stringer and logr.Marshaler for the type is not possible or not desirable, then log calls can wrap an instance of the type or a pointer to it with Format. That then returns a wrapper which implements both.

YAML formatting is used for pretty-printing to a multi-line string.

Which issue(s) this PR fixes:

Related-to: #115950

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

/cc @SataQiu @liggitt

This is useful for logging types which implement String incorrectly, for
example by inheriting it from metav1.TypeMeta. If implementing fmt.Stringer and
logr.Marshaler for the type is not possible or not desirable, then log calls
can wrap an instance of the type or a pointer to it with Format. That then
returns a wrapper which implements both.

YAML formatting is used for pretty-printing to a multi-line string.
@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Mar 27, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. labels Mar 27, 2023
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.27 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.27.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Mon Mar 27 16:26:31 UTC 2023.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 27, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Mar 27, 2023
"sigs.k8s.io/yaml"
)

func Format[T any](obj T) formatAny[T] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: add documentation...

limitations under the License.
*/

package ktesting
Copy link
Member

@liggitt liggitt Mar 27, 2023

Choose a reason for hiding this comment

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

would we want the example #115950 was trying to fix (in non-test kubelet server.go code) to reference the test/utils/ktesting package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is up for debate. I picked ktesting because I intend to use YAML here for pretty-printing, if I can convince myself that better formatting during unit testing is really desirable. It could hide that "normal" formatting isn't as good (klog cannot (or should not?) depend on "sigs.k8s.io/yaml").

If "sigs.k8s.io/yaml" was an acceptable dependency for klog, then klog would be a good place for this code.

"staging/src/k8s.io/component-base/logs" might also be okay.

Copy link
Member

Choose a reason for hiding this comment

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

Referencing the test package in normal code might not seem like a good idea.

+1 for klog or component-base/logs

we can also consider using gopkg.in/yaml.v2

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pohly

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 area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 27, 2023
@pohly pohly changed the title ktesting: add object formatter RFC: ktesting: add object formatter Mar 27, 2023
@k8s-ci-robot
Copy link
Contributor

@pohly: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-node-e2e-containerd 28928b0 link true /test pull-kubernetes-node-e2e-containerd
pull-kubernetes-verify 28928b0 link true /test pull-kubernetes-verify

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
Copy link
Contributor Author

pohly commented Apr 11, 2023

kubernetes/klog#374 is a solution with JSON in klog.

@dims
Copy link
Member

dims commented Apr 24, 2023

i've merged kubernetes/klog#374 .. do we need a klog release and then revisit this?

@pohly
Copy link
Contributor Author

pohly commented Apr 24, 2023

I have one more thing that I want to propose for klog, then we can do a release of it, update Kubernetes, and close this PR.

@pohly
Copy link
Contributor Author

pohly commented May 2, 2023

The klog update with klog.Format is pending in #117687.

/close

@k8s-ci-robot
Copy link
Contributor

@pohly: Closed this PR.

In response to this:

The klog update with klog.Format is pending in #117687.

/close

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.

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. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants