Skip to content

Commit

Permalink
etcdserver: add rate limiter for Range
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcong committed Sep 12, 2020
1 parent faa9c0a commit e8b1507
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.etcd.io/etcd/v3/lease/leasehttp"
"go.etcd.io/etcd/v3/mvcc"
"go.etcd.io/etcd/v3/pkg/traceutil"
"go.etcd.io/etcd/v3/qos"
"go.etcd.io/etcd/v3/raft"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -114,7 +115,12 @@ func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeRe
traceutil.Field{Key: "range_end", Value: string(r.RangeEnd)},
)
ctx = context.WithValue(ctx, traceutil.TraceKey, trace)

object := &qos.RequestContext{GRPCMethod: "Range", Key: string(r.Key)}
if !s.qosStore.GetToken(object) {
s.lg.Warn("failed to Range due to rate limit", zap.String("key", string(r.Key)))
return nil, qos.ErrQoSRateExceeded
}
defer s.qosStore.PutToken(object)
var resp *pb.RangeResponse
var err error
defer func(start time.Time) {
Expand Down

0 comments on commit e8b1507

Please sign in to comment.