runutil: add Exhaust* fns, initial users#1302
Conversation
|
@bwplotka do you agree with this direction? If yes, then I will convert the other users where this is applicable. |
|
@bwplotka PTAL again when you'll have some time before merging. Thanks! 😄 |
bwplotka
left a comment
There was a problem hiding this comment.
I think we could potentially reduce number of methods here e.g by having just Close that accepts io.Closer but tries to cast to io.Reader and then optionally Copies? I think it is solid behavior. (:
What do you think? (:
pkg/runutil/runutil.go
Outdated
|
|
||
| // ExhaustCloseWithLogOnErr closes the io.ReadCloser with a log message on error but exhausts the reader before. | ||
| func ExhaustCloseWithLogOnErr(logger log.Logger, r io.ReadCloser, format string, a ...interface{}) { | ||
| _, _ = io.Copy(ioutil.Discard, r) |
There was a problem hiding this comment.
Technically log on error might mean checking err here as well (: But I think it's fine for now.
There was a problem hiding this comment.
That's true but such an error message would be harmless and users would just ignore it, no?
There was a problem hiding this comment.
No if you want to exhaust and that failed, right?
There was a problem hiding this comment.
Yeah but I'm not sure what an user could do. Plus, if that doesn't have any negative consequences besides just a little bit lower performance then I'm not sure that it's that important. I will add checking here as well, I just hope that it will not lead to unnecessary noise in logs 😄
It is a thing that we could do but the question here is do we want to force that behavior onto the external users of this package? IMHO it's not always useful to discard all of the input because you could never be sure what is actually in the |
|
True you are right. (: |
* master: Fix typos (thanos-io#1350) pool: add pool raciness tests, fix p.usedTotal house-keeping (thanos-io#1340) runutil: add Exhaust* fns, initial users (thanos-io#1302) Further docs rename to new org; Improved docker login. (thanos-io#1344) Moved CI to thanos-io org and docker image to quay.io/thanos/thanos (thanos-io#1342) thanos-io (thanos-io#1343) website: migrate to new Github Org (thanos-io#1341)
* master: Fix typos (thanos-io#1350) pool: add pool raciness tests, fix p.usedTotal house-keeping (thanos-io#1340) runutil: add Exhaust* fns, initial users (thanos-io#1302) Further docs rename to new org; Improved docker login. (thanos-io#1344) Moved CI to thanos-io org and docker image to quay.io/thanos/thanos (thanos-io#1342) thanos-io (thanos-io#1343) website: migrate to new Github Org (thanos-io#1341)
Changes
runutilpackage now has an extra family of functions which exhaust anio.ReadCloserbefore closing themresp.Bodyis used a.k.a. HTTP connectionsI think that the old functions can still be there because we might have external users of this package and in some cases it just doesn't make sense to use them.
Rationale
Lets us reuse keep-alive connections efficiently. Ticket: #1206