From 43c41836466be9209b63a32d69a4e41cffad8f58 Mon Sep 17 00:00:00 2001 From: Nelz Date: Mon, 9 Oct 2017 17:00:43 -0700 Subject: [PATCH] Downstream usages of ratelimit package --- examples/addsvc/pkg/addendpoint/set.go | 8 +++++--- examples/addsvc/pkg/addtransport/grpc.go | 4 ++-- examples/addsvc/pkg/addtransport/http.go | 5 +++-- examples/addsvc/pkg/addtransport/thrift.go | 5 +++-- examples/stringsvc3/proxying.go | 5 +++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/addsvc/pkg/addendpoint/set.go b/examples/addsvc/pkg/addendpoint/set.go index 3a65b083b..e4acaff47 100644 --- a/examples/addsvc/pkg/addendpoint/set.go +++ b/examples/addsvc/pkg/addendpoint/set.go @@ -2,8 +2,10 @@ package addendpoint import ( "context" + "time" + + "golang.org/x/time/rate" - rl "github.com/juju/ratelimit" stdopentracing "github.com/opentracing/opentracing-go" "github.com/sony/gobreaker" @@ -31,7 +33,7 @@ func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram, var sumEndpoint endpoint.Endpoint { sumEndpoint = MakeSumEndpoint(svc) - sumEndpoint = ratelimit.NewTokenBucketLimiter(rl.NewBucketWithRate(1, 1))(sumEndpoint) + sumEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 1))(sumEndpoint) sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(sumEndpoint) sumEndpoint = opentracing.TraceServer(trace, "Sum")(sumEndpoint) sumEndpoint = LoggingMiddleware(log.With(logger, "method", "Sum"))(sumEndpoint) @@ -40,7 +42,7 @@ func New(svc addservice.Service, logger log.Logger, duration metrics.Histogram, var concatEndpoint endpoint.Endpoint { concatEndpoint = MakeConcatEndpoint(svc) - concatEndpoint = ratelimit.NewTokenBucketLimiter(rl.NewBucketWithRate(100, 100))(concatEndpoint) + concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100))(concatEndpoint) concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(concatEndpoint) concatEndpoint = opentracing.TraceServer(trace, "Concat")(concatEndpoint) concatEndpoint = LoggingMiddleware(log.With(logger, "method", "Concat"))(concatEndpoint) diff --git a/examples/addsvc/pkg/addtransport/grpc.go b/examples/addsvc/pkg/addtransport/grpc.go index ec05baa82..6ec58d7f4 100644 --- a/examples/addsvc/pkg/addtransport/grpc.go +++ b/examples/addsvc/pkg/addtransport/grpc.go @@ -7,10 +7,10 @@ import ( "google.golang.org/grpc" - jujuratelimit "github.com/juju/ratelimit" stdopentracing "github.com/opentracing/opentracing-go" "github.com/sony/gobreaker" oldcontext "golang.org/x/net/context" + "golang.org/x/time/rate" "github.com/go-kit/kit/circuitbreaker" "github.com/go-kit/kit/endpoint" @@ -76,7 +76,7 @@ func NewGRPCClient(conn *grpc.ClientConn, tracer stdopentracing.Tracer, logger l // construct per-endpoint circuitbreaker middlewares to demonstrate how // that's done, although they could easily be combined into a single breaker // for the entire remote instance, too. - limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(100, 100)) + limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) // Each individual endpoint is an http/transport.Client (which implements // endpoint.Endpoint) that gets wrapped with various middlewares. If you diff --git a/examples/addsvc/pkg/addtransport/http.go b/examples/addsvc/pkg/addtransport/http.go index ecdee9288..3819c6d87 100644 --- a/examples/addsvc/pkg/addtransport/http.go +++ b/examples/addsvc/pkg/addtransport/http.go @@ -11,7 +11,8 @@ import ( "strings" "time" - jujuratelimit "github.com/juju/ratelimit" + "golang.org/x/time/rate" + stdopentracing "github.com/opentracing/opentracing-go" "github.com/sony/gobreaker" @@ -68,7 +69,7 @@ func NewHTTPClient(instance string, tracer stdopentracing.Tracer, logger log.Log // construct per-endpoint circuitbreaker middlewares to demonstrate how // that's done, although they could easily be combined into a single breaker // for the entire remote instance, too. - limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(100, 100)) + limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) // Each individual endpoint is an http/transport.Client (which implements // endpoint.Endpoint) that gets wrapped with various middlewares. If you diff --git a/examples/addsvc/pkg/addtransport/thrift.go b/examples/addsvc/pkg/addtransport/thrift.go index c6797ecbd..485840fe0 100644 --- a/examples/addsvc/pkg/addtransport/thrift.go +++ b/examples/addsvc/pkg/addtransport/thrift.go @@ -4,7 +4,8 @@ import ( "context" "time" - jujuratelimit "github.com/juju/ratelimit" + "golang.org/x/time/rate" + "github.com/sony/gobreaker" "github.com/go-kit/kit/circuitbreaker" @@ -58,7 +59,7 @@ func NewThriftClient(client *addthrift.AddServiceClient) addservice.Service { // construct per-endpoint circuitbreaker middlewares to demonstrate how // that's done, although they could easily be combined into a single breaker // for the entire remote instance, too. - limiter := ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(100, 100)) + limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) // Each individual endpoint is an http/transport.Client (which implements // endpoint.Endpoint) that gets wrapped with various middlewares. If you diff --git a/examples/stringsvc3/proxying.go b/examples/stringsvc3/proxying.go index 8b1013f31..0f6780776 100644 --- a/examples/stringsvc3/proxying.go +++ b/examples/stringsvc3/proxying.go @@ -8,7 +8,8 @@ import ( "strings" "time" - jujuratelimit "github.com/juju/ratelimit" + "golang.org/x/time/rate" + "github.com/sony/gobreaker" "github.com/go-kit/kit/circuitbreaker" @@ -47,7 +48,7 @@ func proxyingMiddleware(ctx context.Context, instances string, logger log.Logger var e endpoint.Endpoint e = makeUppercaseProxy(ctx, instance) e = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(e) - e = ratelimit.NewTokenBucketLimiter(jujuratelimit.NewBucketWithRate(float64(qps), int64(qps)))(e) + e = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), qps))(e) endpointer = append(endpointer, e) }