Skip to content

Commit

Permalink
Clarify rate limiter expressions in addsvc example
Browse files Browse the repository at this point in the history
Rate limiting examples might be a bit confusing when Every
method is used #698.
One could expect to see throttling expressed as
a number of requests per unit of time whereas another would see it
as an interval between requests.
  • Loading branch information
marselester committed Dec 29, 2019
1 parent c0f8510 commit c5151f9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/addsvc/pkg/addendpoint/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram,
var sumEndpoint endpoint.Endpoint
{
sumEndpoint = MakeSumEndpoint(svc)
// Sum is limited to 1 request per second with burst of 1 request.
// Note, rate is defined as a time interval between requests.
sumEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 1))(sumEndpoint)
sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(sumEndpoint)
sumEndpoint = opentracing.TraceServer(otTracer, "Sum")(sumEndpoint)
Expand All @@ -47,7 +49,9 @@ func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram,
var concatEndpoint endpoint.Endpoint
{
concatEndpoint = MakeConcatEndpoint(svc)
concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100))(concatEndpoint)
// Concat is limited to 1 request per second with burst of 100 requests.
// Note, rate is defined as a number of requests per second.
concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Limit(1), 100))(concatEndpoint)
concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(concatEndpoint)
concatEndpoint = opentracing.TraceServer(otTracer, "Concat")(concatEndpoint)
if zipkinTracer != nil {
Expand Down

0 comments on commit c5151f9

Please sign in to comment.