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

feat(reporter/http): uses an interface for http client #155

Merged
merged 2 commits into from
Nov 19, 2019

Conversation

jcchavezs
Copy link
Contributor

@jcchavezs jcchavezs commented Oct 21, 2019

This PR changes the interface for the http client being accepted in the http reporter which allows users to plug other clients (e.g. a client with resiliency patterns implemented) as in https://gist.github.com/jcchavezs/5d615ff7013311bea1555e448c4cce3e.

Questions to be addressed: Should this gist be part of the zipkin http reporter package?

Ping @basvanbeek @skaslev @pramodramdas

Closes #153

@jcchavezs jcchavezs changed the title feat(reporter/http): uses an interface for http client [DRAFT] feat(reporter/http): uses an interface for http client Oct 21, 2019
@jcchavezs jcchavezs force-pushed the uses_interface_for_http_client branch from b4d33f0 to 86b2068 Compare October 21, 2019 13:25
@jcchavezs jcchavezs force-pushed the uses_interface_for_http_client branch from 86b2068 to 32e9ef5 Compare October 21, 2019 13:35
@jcchavezs jcchavezs changed the title [DRAFT] feat(reporter/http): uses an interface for http client feat(reporter/http): uses an interface for http client Oct 21, 2019
@coveralls
Copy link

coveralls commented Oct 21, 2019

Coverage Status

Coverage increased (+2.7%) to 68.268% when pulling 5bb8a4b on uses_interface_for_http_client into bafd576 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.0%) to 72.473% when pulling 32e9ef5 on uses_interface_for_http_client into c29478e on master.

@skaslev
Copy link
Contributor

skaslev commented Oct 21, 2019

Looks good to me though I was intending to send a PR with go-retryablehttp baked in the HTTP Reporter.

Questions to be addressed: Should this gist be part of the zipkin http reporter package?

Maybe exposing the gist as RetriableClient reporter option?

func RetriableClient(waitMin, waitMax time.Duration, maxRetries int) ReporterOption {
  // ....
}

@jcchavezs
Copy link
Contributor Author

jcchavezs commented Oct 21, 2019

Hi @skaslev, my concern about exposing RetriableClient is that we then increase the surface of the API whereas accepting the client interface just provides an abstraction on top of standard library. Maybe that is also the answer for whether include the gist as part of the repo or not.

Copy link
Contributor

@skaslev skaslev left a comment

Choose a reason for hiding this comment

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

Makes sense.

Another idea that comes to mind for the gist is to have the code in the docs/FAQ/examples so users who need retyablehttp will be able to find how to use it with zipkin-go easily.

reporter/http/http.go Outdated Show resolved Hide resolved
@jcchavezs
Copy link
Contributor Author

jcchavezs commented Nov 5, 2019

This change was the only piece I was not sure about but I think it is OK to do this change for two reasons:

  1. From the documentation about the http.Client.Timeout:

// The Client cancels requests to the underlying Transport
// as if the Request's Context ended.
// ...
Timeout time.Duration

Which means that this produces the same effect as a context cancellation. What I am not sure if we should return the context.DeadlineExceeded error or a meaningful timeout error.

  1. I did some benchmarking and I concluded there won't be a big impact on this change (actually context deadline seems to perform better):
BenchmarkClientTimeoutTimesout-8   	     100	  11147329 ns/op	   17279 B/op	     119 allocs/op
BenchmarkCtxDeadlineTimesout-8     	     100	  10803295 ns/op	   15984 B/op	     101 allocs/op
BenchmarkClientTimeoutSuccess-8    	    5409	    219080 ns/op	    4462 B/op	      59 allocs/op
BenchmarkCtxDeadlineSuccess-8      	    5875	    212182 ns/op	    3747 B/op	      48 allocs/op

So I think this can be merged. Any concern @basvanbeek ?

Copy link
Member

@basvanbeek basvanbeek left a comment

Choose a reason for hiding this comment

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

Two minor nits otherwise LGTM

reporter/http/http.go Outdated Show resolved Hide resolved
reporter/http/http.go Outdated Show resolved Hide resolved
reporter/http/http.go Outdated Show resolved Hide resolved
@jcchavezs jcchavezs force-pushed the uses_interface_for_http_client branch from 3f77ee3 to 5bb8a4b Compare November 19, 2019 11:55
@basvanbeek basvanbeek merged commit d761b19 into master Nov 19, 2019
@basvanbeek
Copy link
Member

Thanks @jcchavezs!!!

@jcchavezs jcchavezs deleted the uses_interface_for_http_client branch November 19, 2019 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add exponential backoff logic to http reporter on failure to send data to the backend
4 participants