-
Notifications
You must be signed in to change notification settings - Fork 206
Add wrapper func for spew.Sprintf in utils #226
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
Conversation
Welcome @haoruan! |
The original issue is 6 years old, and I don't know how much sense that makes today, is this still something we want? @thockin |
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/assign @thockin |
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.
Thanks for picking this up! Unfortunately, I don't think this quite meets needs.
https://go.dev/play/p/Gvyo85V6YdA
First, %+v
and %#v
are not "pretty". They are the opposite :)
Second, this doesn't disable methods, so somewhat less useful (would need this covered in test): https://go.dev/play/p/qciduo52P1q
Compare to litter (spew has more config, so does kr/pretty): https://go.dev/play/p/Z4Mz93Ip6Su
So I think the first step is to go look at k/k and see the places this would be used and figure out what most of them want. Then come back to this and explain why whichever impl you think is right is the best choice. Lastly, a rich test with maps, String() and Error() methods, etc
Thanks the advise, seems we're not limited by the format/lib, I will check again |
spew.Sdump() has the pretty format with full newlines, indentation, type, and pointer information:
Also we can set Config.DisableMethods to disable String(), or Error(). spew.Sdump() has been widely used in kubernetes to dump object, or show the output diff in failed unit test, and spew.Sprintf() did the same thing with the same purpose. I'm not sure if they're reserved by purpose or we just missed them. So my opinion is to make it uniform across the whole project, and replace Sprintf() with Sdump() instead of creating a wrapper. Later we can close the original issue, and create a new one to do the replacement. |
The reason I opened the issue was because it's all over the map. Most places that want to dump something don't ever look at the logs, so don't notice that it uses .String() or prints pointer values or whatever. |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
I realized this never got completed, sorry. I don't love Sdump(), but it seems like least bad. If we're going to do this, we should add We should probably call this package "dump" or "pretty" or similar. We should document that the output of pretty.Print() may change over time and if anyone needs guaranteed output, they should take more direct control |
A nice end-goal of this might be that nothing in k/k depends on spew directly. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: haoruan The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Thanks for the comments, PTAL if we're going to take it. |
@BenTheElder @jpbetz @tallclair @cici37 @msau42 As discussed earlier, I recall now why JSON is not a great choice. The GO JSON lib is very ...limited. https://go.dev/play/p/ef_FY4KyrV- Spew is unmaintained and large. I am sure we could fork it and make it do what we want but....ugh kr.Pretty is already used trasitively, though I can't see how to make it's output not include newlines. litter is nicer output, but is a net new dep. If we could get 3 or 4 deps which use spew to switch, we could justify this as a one-for-one. @haoruan if you are still up for it, how about this:
What do you think? |
Sounds good, will work on k/k first. Should we close this one? |
yeah, let's do that, but please xref it so I don't forget :)
…On Sun, Oct 16, 2022 at 8:14 PM Hao Ruan ***@***.***> wrote:
Sounds good, will work on k/k first. Should we close this one?
—
Reply to this email directly, view it on GitHub
<#226 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKWAVDX4JDWU7YEKSLDRATWDTABBANCNFSM5HEAKMCQ>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
A wrapper of spew.Sprintf, so to pretty print object with a util function
Which issue(s) this PR fixes:
Fixes kubernetes/kubernetes#8976
Special notes for your reviewer:
With existing usage of spew.Sprintf, the spew.Sdump is a better choice because it has the pretty format with full newlines, indentation and type.
Release note: