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

e2e: pretty-print objects #111884

Closed
pohly opened this issue Aug 17, 2022 · 8 comments
Closed

e2e: pretty-print objects #111884

pohly opened this issue Aug 17, 2022 · 8 comments
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/testing Categorizes an issue or PR as relevant to SIG Testing. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@pohly
Copy link
Contributor

pohly commented Aug 17, 2022

What would you like to be added?

There is no good pretty-printing for Kubernetes API objects, which affects debugging. All of the following options have drawbacks:

  • fmt.Sprintf("%+v") (single line, no clear distinction between fields)
  • obj.String() (auto-generated, single line, does not omit empty fields)

What we want is probably:

  • multi-line
  • omitting empty fields as defined by the type

In other words, YAML?

/cc @tallclair

Why is this needed?

For example for

func TimeoutError(msg string, observedObjects ...interface{}) *timeoutError {
return &timeoutError{
msg: msg,
observedObjects: observedObjects,
}
}
:

			err := e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, pod.Namespace)
			framework.ExpectNoError(err, "start pod with inline resource claim")

=>

    Aug 17 09:55:26.691: INFO: Unexpected error: start pod with inline resource claim: 
        <*pod.timeoutError | 0xc004274e40>: {
            msg: "timed out while waiting for pod dra-5838/tester-1 to be running",
            observedObjects: [
                <*v1.Pod | 0xc002123800>{
                    TypeMeta: {Kind: "", APIVersion: ""},
                    ObjectMeta: {
                        Name: "tester-1",
                        GenerateName: "",
                        Namespace: "dra-5838",
                        SelfLink: "",
                        UID: "c3a4dfa5-5297-44e0-acdc-bdfb82035b80",
                        ResourceVersion: "379",
                        Generation: 0,
                        CreationTimestamp: {
                            Time: {
                                wall: 0,
                                ext: 63796319426,
                                loc: {
                                    name: "Local",
                                    zone: [
                                        {name: "LMT", offset: 3208, isDST: false},
                                        {name: "CEST", offset: 7200, isDST: true},
                                        {name: "CET", offset: 3600, isDST: false},
                                        {name: "CEST", offset: 7200, isDST: true},
                                        {name: "CET", offset: 3600, isDST: false},
                                        {name: "CEMT", offset: 10800, isDST: true},
                                        {name: "CEMT", offset: 10800, isDST: true},
                                        {name: "CEST", offset: 7200, isDST: true},
                                        {name: "CET", offset: 3600, isDST: false},
                                    ],
                                    tx: [
                                        {
                                            when: -576460752303423488,
                                            index: 0,
                                            isstd: false,
                                            isutc: false,
                                        },
                                        {when: -2422054408, index: 2, isstd: false, isutc: false},
                                        {when: -1693706400, index: 1, isstd: false, isutc: false},
                                        {when: -1680483600, index: 2, isstd: true, isutc: false},
                                        {when: -1663455600, index: 3, isstd: true, isutc: false},
                                        {when: -1650150000, index: 4, isstd: false, isutc: false},
                                        {when: -1632006000, index: 3, isstd: true, isutc: false},
                                        {when: -1618700400, index: 4, isstd: true, isutc: true},
                                        {when: -938905200, index: 3, isstd: true, isutc: true},
                                        {when: -857257200, index: 4, isstd: false, isutc: false},
                                        {when: -844556400, index: 3, isstd: false, isutc: false},
                                        {when: -828226800, index: 4, isstd: false, isutc: false},
                                        {when: -812502000, index: 3, isstd: false, isutc: false},
                                        {when: -796777200, index: 4, isstd: false, isutc: false},
                                        {when: -781052400, index: 3, isstd: false, isutc: false},
                                        {when: -776563200, index: 5, isstd: false, isutc: false},
                                        {when: -765936000, index: 1, isstd: false, isutc: false},
                                        {when: -761180400, index: 4, isstd: false, isutc: false},
                                        {when: -757386000, index: 2, isstd: false, isutc: false},
                                        {when: -748479600, index: 3, isstd: false, isutc: false},
                                        {when: -733273200, index: 4, isstd: false, isutc: false},
                                        {when: -717631200, index: 3, isstd: false, isutc: false},
                                        {when: -714610800, index: 6, isstd: false, isutc: false},
                                        {w...

    Gomega truncated this representation as it exceeds 'format.MaxLength'.
    Consider having the object provide a custom 'GomegaStringer' representation
    or adjust the parameters in Gomega's 'format' package.

    Learn more here: https://onsi.github.io/gomega/#adjusting-output
@pohly pohly added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 17, 2022
@k8s-ci-robot k8s-ci-robot added 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 Aug 17, 2022
@pohly
Copy link
Contributor Author

pohly commented Aug 17, 2022

/sig testing

@k8s-ci-robot k8s-ci-robot added sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 17, 2022
@aojea
Copy link
Member

aojea commented Aug 17, 2022

CreationTimestamp is 🙃 🥇

@spiffxp
Copy link
Member

spiffxp commented Oct 27, 2022

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 27, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 25, 2023
@pohly
Copy link
Contributor Author

pohly commented Jan 26, 2023

I believe that gomega/format.Object together with the YAML formatter from 5a01a52 is the right way forward. It will automatically switch over to YAML when applicable. This is enabled for all of the in-tree E2E suites.

However, tests must explicitly call it. I'd like to do a bit more work before closing this issue:

@pohly
Copy link
Contributor Author

pohly commented Jan 26, 2023

/remove-lifecycle stale
/assign

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 26, 2023
pohly added a commit to pohly/kubernetes that referenced this issue Mar 2, 2023
The upstream ktesting uses the normal text formatting. This is not very useful
for test output because in tests it is fairly common that larger data
types (structs, slices) need to be dumped and the default `%+v` does not render
those nicely. In particular Kubernetes API objects become very
large (kubernetes#111884).

By installing gomega as formatting helper, we get more readable output, in
particular with the YAML extension for gomega.
@pohly
Copy link
Contributor Author

pohly commented May 15, 2023

klog cannot use it by default because it must not depend on YAML. But JSON is now the default, which is close enough for me.

/close

@k8s-ci-robot
Copy link
Contributor

@pohly: Closing this issue.

In response to this:

klog cannot use it by default because it must not depend on YAML. But JSON is now the default, which is close enough for me.

/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
kind/feature Categorizes issue or PR as related to a new feature. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/testing Categorizes an issue or PR as relevant to SIG Testing. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

5 participants