-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
Don't pretty-print by default. Saves an allocation (or more) and a copy. #9361
Conversation
EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded. |
Post 1.0 we should switch to letting go restful serialize our response which reduces the cost of this. |
@@ -56,6 +56,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | |||
var apiResource string | |||
var httpCode int | |||
reqStart := time.Now() | |||
pretty := isPrettyPrint(req) |
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.
A little concerned about proxy looking at query parameters. I would say proxy shouldn't do this (otherwise if he backend also supports pp it's going to get mangled).
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 guess since its errors it's less impactful...
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 we could just make indentation true by default for proxy 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.
Yeah, I think that makes the most sense. Until we have larger errors (I have a todo to make an update conflict return the conflicting resource) we can get away with always indenting errors for a lot of code.
On Jun 6, 2015, at 12:14 PM, Brian Grant notifications@github.com wrote:
In pkg/apiserver/proxy.go:
@@ -56,6 +56,7 @@ func (r *ProxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var apiResource string
var httpCode int
reqStart := time.Now()
- pretty := isPrettyPrint(req)
Or we could just make indentation true by default for proxy errors.—
Reply to this email directly or view it on GitHub.
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.
switched to default true.
Ref. most recent discussion: #4521 (comment) Original discussion: #2243 |
} | ||
|
||
func isPrettyPrint(req *http.Request) bool { | ||
pp := req.URL.Query().Get("pp") |
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.
We don't abbreviate in the API. I suggest "indent".
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 also suggest that we pretty print in the case that User-Agent is "curl/.*"
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 "pretty" rather than "indent".
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.
done. Added user agents for modern browsers and cli clients.
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.
Did you push the new code yet?
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.
just pushed... Sorry, I was 'done-ing' comments as I came to them, and I needed to add the swagger docs you asked for...
Users are going to want to know that this query parameter exists. We should document it in the swagger. I put some pointers here: |
@smarterclayton Why do you think go-restful would be more efficient? Or are you just suggesting that we marshal and indent in the same step, as go-restful does? We could pass the pretty flag to Encode, or factor out marshaling, which we'd also have to do if we were going to call go-restful's Write function. |
|
Comments addressed and code pushed, ptal. --brendan |
ugh, something in the pre-check borked... hang on. |
Yeah, deep copy vaporized. |
ok, should be fixed now. Sorry about that. |
EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded. |
@smarterclayton - should I add this to our list of items to cherry pick? Seems useful |
EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded. |
@@ -496,6 +502,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag | |||
route := ws.GET(action.Path).To(ListResource(lister, watcher, reqScope, true, a.minRequestTimeout)). | |||
Filter(m). | |||
Doc("watch changes to an object of kind "+kind). | |||
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")). |
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.
We should add Param to WATCHLIST, also, for consistency.
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.
done (it's marked deprecated so I skipped it...)
Thanks. Just a couple minor details to address. Also, PR #9388 was merged, so you'll need to update the generated swagger in order to merge. |
And, if #9389 is merged, you'll need to rebase and regenerate the swagger again. |
Rebased, and regenerated swagger. ptal. Thanks! |
EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded. |
LGTM, thanks. |
Don't pretty-print by default. Saves an allocation (or more) and a copy.
@smarterclayton @wojtek-t @fgrzadkowski @lavalamp