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

Don't pretty-print by default. Saves an allocation (or more) and a copy. #9361

Merged
merged 1 commit into from
Jun 9, 2015

Conversation

brendandburns
Copy link
Contributor

@k8s-bot
Copy link

k8s-bot commented Jun 6, 2015

EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded.

@smarterclayton
Copy link
Contributor

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

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).

Copy link
Contributor

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...

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to default true.

@bgrant0607
Copy link
Member

Ref. most recent discussion: #4521 (comment)

Original discussion: #2243

}

func isPrettyPrint(req *http.Request) bool {
pp := req.URL.Query().Get("pp")
Copy link
Member

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".

Copy link
Member

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/.*"

Copy link
Member

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".

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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...

@bgrant0607
Copy link
Member

Users are going to want to know that this query parameter exists. We should document it in the swagger. I put some pointers here:
#3714 (comment)

@bgrant0607
Copy link
Member

@smarterclayton Why do you think go-restful would be more efficient?
https://github.com/emicklei/go-restful/blob/5aeddab2ca153e662be4ff9efb82f6c6788466d0/response.go#L159

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.

@bgrant0607 bgrant0607 self-assigned this Jun 6, 2015
@smarterclayton
Copy link
Contributor

On Jun 6, 2015, at 12:59 PM, Brian Grant notifications@github.com wrote:

@smarterclayton Why do you think go-restful would be more efficient?
https://github.com/emicklei/go-restful/blob/5aeddab2ca153e662be4ff9efb82f6c6788466d0/response.go#L159

I just meant we should use gorestfuls library methods and improve them as needed - instead of us writing directly to the response use resp.WriteEntity etc.
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.

In the long run we want to factor marshaling out anyway (to support protobuf or similar). Not a short term thing though, just bringing up we we don't necessarily want to do all our own response writing forever.

Reply to this email directly or view it on GitHub.

@brendandburns
Copy link
Contributor Author

Comments addressed and code pushed, ptal.

--brendan

@brendandburns
Copy link
Contributor Author

ugh, something in the pre-check borked... hang on.

@bgrant0607
Copy link
Member

Yeah, deep copy vaporized.

@brendandburns
Copy link
Contributor Author

ok, should be fixed now. Sorry about that.

@k8s-bot
Copy link

k8s-bot commented Jun 8, 2015

EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded.

@derekwaynecarr
Copy link
Member

@smarterclayton - should I add this to our list of items to cherry pick? Seems useful

@k8s-bot
Copy link

k8s-bot commented Jun 8, 2015

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.")).
Copy link
Member

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.

Copy link
Contributor Author

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...)

@bgrant0607
Copy link
Member

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.

@bgrant0607
Copy link
Member

And, if #9389 is merged, you'll need to rebase and regenerate the swagger again.

cc @nikhiljindal @krousey

@brendandburns
Copy link
Contributor Author

Rebased, and regenerated swagger. ptal.

Thanks!
--brendan

@k8s-bot
Copy link

k8s-bot commented Jun 9, 2015

EXPERIMENTAL JENKINS PR BUILDER: e2e build succeeded.

@bgrant0607
Copy link
Member

LGTM, thanks.

@bgrant0607 bgrant0607 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 9, 2015
krousey added a commit that referenced this pull request Jun 9, 2015
Don't pretty-print by default.  Saves an allocation (or more) and a copy.
@krousey krousey merged commit cf19420 into kubernetes:master Jun 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants