From c806c4c2ec10d2bdea1ed2202b8ba96610dd02a2 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Tue, 30 Jun 2020 15:23:39 -0700 Subject: [PATCH] Drop support for legacy ratelimit.proto and upgrade to v3 rls.proto Signed-off-by: Petr Pchelko --- Dockerfile | 1 - README.md | 34 +- go.mod | 4 +- go.sum | 18 + proto/ratelimit/ratelimit.pb.go | 538 -------------------------- proto/ratelimit/ratelimit.proto | 102 ----- src/client_cmd/main.go | 4 +- src/config/config.go | 4 +- src/config/config_impl.go | 4 +- src/limiter/cache.go | 2 +- src/limiter/cache_key.go | 4 +- src/redis/cache_impl.go | 2 +- src/server/server.go | 2 +- src/server/server_impl.go | 2 +- src/service/ratelimit.go | 2 +- src/service/ratelimit_legacy.go | 6 +- src/service_cmd/runner/runner.go | 8 +- test/common/common.go | 11 +- test/config/config_test.go | 4 +- test/integration/integration_test.go | 16 +- test/mocks/config/config.go | 2 +- test/mocks/limiter/limiter.go | 2 +- test/mocks/rls/rls.go | 2 +- test/redis/bench_test.go | 2 +- test/redis/cache_impl_test.go | 2 +- test/server/server_impl_test.go | 2 +- test/service/ratelimit_legacy_test.go | 27 +- test/service/ratelimit_test.go | 2 +- 28 files changed, 94 insertions(+), 715 deletions(-) delete mode 100644 proto/ratelimit/ratelimit.pb.go delete mode 100644 proto/ratelimit/ratelimit.proto diff --git a/Dockerfile b/Dockerfile index 706cefaa8..b0bdb0bd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ RUN go mod download COPY src src COPY script script -COPY proto proto RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/ratelimit -ldflags="-w -s" -v github.com/envoyproxy/ratelimit/src/service_cmd diff --git a/README.md b/README.md index 746c5f5a9..179d5c084 100644 --- a/README.md +++ b/README.md @@ -38,27 +38,27 @@ applications. Applications request a rate limit decision based on a domain and a reads the configuration from disk via [runtime](https://github.com/lyft/goruntime), composes a cache key, and talks to the Redis cache. A decision is then returned to the caller. -# Deprecation of Legacy Ratelimit Proto - -Envoy's data-plane-api defines a ratelimit service proto [rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto). -Logically the data-plane-api [rls](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto) -is equivalent to the [ratelimit.proto](https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto) -defined in this repo. However, due -to the namespace differences and how gRPC routing works it is not possible to transparently route the -legacy ratelimit (ones based in the [ratelimit.proto](https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto) -defined in this repo) requests to the data-plane-api -definitions. Therefore, the ratelimit service will upgrade the requests, process them internally as it would -process a data-plane-api ratelimit request, and then downgrade the response to send back to the client. This means that, +# Deprecation of Legacy Ratelimit Proto and v2 Ratelimit proto + +Envoy's data-plane-api defines a ratelimit service proto v3 [rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto). +Logically the data-plane-api rls [v3](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) +is equivalent to the rls [v2](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) +However, due to the namespace differences and how gRPC routing works it is not possible to transparently route the +legacy v2 ratelimit requests to the v3 definitions. Therefore, the ratelimit service will upgrade the requests, process them internally as it would +process a v3 ratelimit request, and then downgrade the response to send back to the client. This means that, for a slight performance hit for clients using the legacy proto, ratelimit is backwards compatible with the legacy proto. +Prior to version 2.0.0 ratelimit service contained a protocol definition that used to be supported in a legacy mode, +but support for it and was removed in 2.0.0. ## Deprecation Schedule -1. `v1.0.0` tagged on commit `0ded92a2af8261d43096eba4132e45b99a3b8b14`. Ratelimit has been in production -use at Lyft for over 2 years. +1. `v1.0.0` tagged on commit `0ded92a2af8261d43096eba4132e45b99a3b8b14`. Ratelimit has been in production use at Lyft for over 2 years. 2. `v1.1.0` introduces the data-plane-api proto and initiates the deprecation of the legacy [ratelimit.proto](https://github.com/lyft/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto). -3. `v2.0.0` deletes support for the legacy [ratelimit.proto](https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto). This version will be tagged by the end of 2018Q3 (~September 2018) -to give time to community members running ratelimit off of `master`. - +3. `v2.0.0` deleted support for the legacy [ratelimit.proto](https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto). +The current version of ratelimit protocol is changed to [v3 rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) +while [v2 rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) is still supported +as a legacy protocol. +4. `v3.0.0` deletes support for legacy [v2 rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) # Building and Testing @@ -331,7 +331,7 @@ For more information on how runtime works you can read its [README](https://gith # Request Fields For information on the fields of a Ratelimit gRPC request please read the information -on the RateLimitRequest message type in the Ratelimit [proto file.](https://github.com/envoyproxy/ratelimit/blob/master/proto/ratelimit/ratelimit.proto) +on the RateLimitRequest message type in the Ratelimit [proto file.](https://github.com/envoyproxy/envoy/blob/master/api/envoy/service/ratelimit/v3/rls.proto) # Statistics diff --git a/go.mod b/go.mod index fb228646f..90a8cb84b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/alicebob/miniredis/v2 v2.11.4 github.com/cespare/xxhash v1.1.0 // indirect github.com/coocood/freecache v1.1.0 - github.com/envoyproxy/go-control-plane v0.6.9 + github.com/envoyproxy/go-control-plane v0.9.5 github.com/gogo/protobuf v1.3.1 // indirect github.com/golang/mock v1.4.1 github.com/golang/protobuf v1.3.2 @@ -27,7 +27,7 @@ require ( golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect golang.org/x/text v0.3.3-0.20191122225017-cbf43d21aaeb // indirect google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f // indirect - google.golang.org/grpc v1.19.0 + google.golang.org/grpc v1.25.1 gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect gopkg.in/yaml.v2 v2.3.0 diff --git a/go.sum b/go.sum index ba1d3c07f..c8b595dc3 100644 --- a/go.sum +++ b/go.sum @@ -7,12 +7,15 @@ github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGn github.com/alicebob/miniredis v2.5.0+incompatible h1:yBHoLpsyjupjz3NL3MhKMVkR41j82Yjf3KFv7ApYzUI= github.com/alicebob/miniredis/v2 v2.11.4 h1:GsuyeunTx7EllZBU3/6Ji3dhMQZDpC9rLf1luJ+6M5M= github.com/alicebob/miniredis/v2 v2.11.4/go.mod h1:VL3UDEfAH59bSa7MuHMuFToxkqyHh69s/WUbYlOAuyg= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533 h1:8wZizuKuZVu5COB7EsBYxBQz8nRcXXn5d4Gt91eJLvU= +github.com/cncf/udpa/go v0.0.0-20200313221541-5f7e5dd04533/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/coocood/freecache v1.1.0 h1:ENiHOsWdj1BrrlPwblhbn4GdAsMymK3pZORJ+bJGAjA= github.com/coocood/freecache v1.1.0/go.mod h1:ePwxCDzOYvARfHdr1pByNct1at3CoKnsipOHwKlNbzI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -20,6 +23,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.6.9 h1:deEH9W8ZAUGNbCdX+9iNzBOGrAOrnpJGoy0PcTqk/tE= github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.5 h1:lRJIqDD8yjV1YyPRqecMdytjDLs2fTXq363aCib5xPU= +github.com/envoyproxy/go-control-plane v0.9.5/go.mod h1:OXl5to++W0ctG+EHWTFUjiypVxC/Y4VLc/KFU+al13s= +github.com/envoyproxy/protoc-gen-validate v0.1.0 h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= @@ -33,6 +41,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/gomodule/redigo v1.7.1-0.20190322064113-39e2c31b7ca3/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/gorilla/mux v1.7.4-0.20191121170500-49c01487a141 h1:VQjjMh+uElTfioy6GnUrVrTMAiLTNF3xsrAlSwC+g8o= github.com/gorilla/mux v1.7.4-0.20191121170500-49c01487a141/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= @@ -63,6 +72,7 @@ github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/sirupsen/logrus v1.0.4 h1:gzbtLsZC3Ic5PptoRG+kQj4L60qjK7H7XszrU163JNQ= github.com/sirupsen/logrus v1.0.4/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= @@ -86,6 +96,7 @@ golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -117,8 +128,10 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= @@ -126,10 +139,14 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f h1:0RYv5T9ZdroAqqfM2taEB0nJrArv0X1JpIdgUmY4xg8= google.golang.org/genproto v0.0.0-20191216205247-b31c10ee225f/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= @@ -147,5 +164,6 @@ gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/proto/ratelimit/ratelimit.pb.go b/proto/ratelimit/ratelimit.pb.go deleted file mode 100644 index 77f41dbbd..000000000 --- a/proto/ratelimit/ratelimit.pb.go +++ /dev/null @@ -1,538 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: proto/ratelimit/ratelimit.proto - -package ratelimit - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type RateLimit_Unit int32 - -const ( - RateLimit_UNKNOWN RateLimit_Unit = 0 - RateLimit_SECOND RateLimit_Unit = 1 - RateLimit_MINUTE RateLimit_Unit = 2 - RateLimit_HOUR RateLimit_Unit = 3 - RateLimit_DAY RateLimit_Unit = 4 -) - -var RateLimit_Unit_name = map[int32]string{ - 0: "UNKNOWN", - 1: "SECOND", - 2: "MINUTE", - 3: "HOUR", - 4: "DAY", -} -var RateLimit_Unit_value = map[string]int32{ - "UNKNOWN": 0, - "SECOND": 1, - "MINUTE": 2, - "HOUR": 3, - "DAY": 4, -} - -func (x RateLimit_Unit) String() string { - return proto.EnumName(RateLimit_Unit_name, int32(x)) -} -func (RateLimit_Unit) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{2, 0} -} - -type RateLimitResponse_Code int32 - -const ( - RateLimitResponse_UNKNOWN RateLimitResponse_Code = 0 - RateLimitResponse_OK RateLimitResponse_Code = 1 - RateLimitResponse_OVER_LIMIT RateLimitResponse_Code = 2 -) - -var RateLimitResponse_Code_name = map[int32]string{ - 0: "UNKNOWN", - 1: "OK", - 2: "OVER_LIMIT", -} -var RateLimitResponse_Code_value = map[string]int32{ - "UNKNOWN": 0, - "OK": 1, - "OVER_LIMIT": 2, -} - -func (x RateLimitResponse_Code) String() string { - return proto.EnumName(RateLimitResponse_Code_name, int32(x)) -} -func (RateLimitResponse_Code) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{3, 0} -} - -// Main message for a rate limit request. The rate limit service is designed to be fully generic -// in the sense that it can operate on arbitrary hierarchical key/value pairs. The loaded -// configuration will parse the request and find the most specific limit to apply. In addition, -// a RateLimitRequest can contain multiple "descriptors" to limit on. When multiple descriptors -// are provided, the server will limit on *ALL* of them and return an OVER_LIMIT response if any -// of them are over limit. This enables more complex application level rate limiting scenarios -// if desired. -type RateLimitRequest struct { - // All rate limit requests must specify a domain. This enables the configuration to be per - // application without fear of overlap. E.g., "envoy". - Domain string `protobuf:"bytes,1,opt,name=domain" json:"domain,omitempty"` - // All rate limit requests must specify at least one RateLimitDescriptor. Each descriptor is - // processed by the service (see below). If any of the descriptors are over limit, the entire - // request is considered to be over limit. - Descriptors []*RateLimitDescriptor `protobuf:"bytes,2,rep,name=descriptors" json:"descriptors,omitempty"` - // Rate limit requests can optionally specify the number of hits a request adds to the matched limit. If the - // value is not set in the message, a request increases the matched limit by 1. - HitsAddend uint32 `protobuf:"varint,3,opt,name=hits_addend,json=hitsAddend" json:"hits_addend,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimitRequest) Reset() { *m = RateLimitRequest{} } -func (m *RateLimitRequest) String() string { return proto.CompactTextString(m) } -func (*RateLimitRequest) ProtoMessage() {} -func (*RateLimitRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{0} -} -func (m *RateLimitRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimitRequest.Unmarshal(m, b) -} -func (m *RateLimitRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimitRequest.Marshal(b, m, deterministic) -} -func (dst *RateLimitRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimitRequest.Merge(dst, src) -} -func (m *RateLimitRequest) XXX_Size() int { - return xxx_messageInfo_RateLimitRequest.Size(m) -} -func (m *RateLimitRequest) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimitRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimitRequest proto.InternalMessageInfo - -func (m *RateLimitRequest) GetDomain() string { - if m != nil { - return m.Domain - } - return "" -} - -func (m *RateLimitRequest) GetDescriptors() []*RateLimitDescriptor { - if m != nil { - return m.Descriptors - } - return nil -} - -func (m *RateLimitRequest) GetHitsAddend() uint32 { - if m != nil { - return m.HitsAddend - } - return 0 -} - -// A RateLimitDescriptor is a list of hierarchical entries that are used by the service to -// determine the final rate limit key and overall allowed limit. Here are some examples of how -// they might be used for the domain "envoy". -// 1) ["authenticated": "false"], ["ip_address": "10.0.0.1"] -// What it does: Limits all unauthenticated traffic for the IP address 10.0.0.1. The -// configuration supplies a default limit for the ip_address field. If there is a desire to raise -// the limit for 10.0.0.1 or block it entirely it can be specified directly in the -// configuration. -// 2) ["authenticated": "false"], ["path": "/foo/bar"] -// What it does: Limits all unauthenticated traffic globally for a specific path (or prefix if -// configured that way in the service). -// 3) ["authenticated": "false"], ["path": "/foo/bar"], ["ip_address": "10.0.0.1"] -// What it does: Limits unauthenticated traffic to a specific path for a specific IP address. -// Like (1) we can raise/block specific IP addresses if we want with an override configuration. -// 4) ["authenticated": "true"], ["client_id": "foo"] -// What it does: Limits all traffic for an authenticated client "foo" -// 5) ["authenticated": "true"], ["client_id": "foo"], ["path": "/foo/bar"] -// What it does: Limits traffic to a specific path for an authenticated client "foo" -// -// The idea behind the API is that (1)/(2)/(3) and (4)/(5) can be sent in 1 request if desired. -// This enables building complex application scenarios with a generic backend. -type RateLimitDescriptor struct { - Entries []*RateLimitDescriptor_Entry `protobuf:"bytes,1,rep,name=entries" json:"entries,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimitDescriptor) Reset() { *m = RateLimitDescriptor{} } -func (m *RateLimitDescriptor) String() string { return proto.CompactTextString(m) } -func (*RateLimitDescriptor) ProtoMessage() {} -func (*RateLimitDescriptor) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{1} -} -func (m *RateLimitDescriptor) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimitDescriptor.Unmarshal(m, b) -} -func (m *RateLimitDescriptor) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimitDescriptor.Marshal(b, m, deterministic) -} -func (dst *RateLimitDescriptor) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimitDescriptor.Merge(dst, src) -} -func (m *RateLimitDescriptor) XXX_Size() int { - return xxx_messageInfo_RateLimitDescriptor.Size(m) -} -func (m *RateLimitDescriptor) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimitDescriptor.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimitDescriptor proto.InternalMessageInfo - -func (m *RateLimitDescriptor) GetEntries() []*RateLimitDescriptor_Entry { - if m != nil { - return m.Entries - } - return nil -} - -type RateLimitDescriptor_Entry struct { - Key string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimitDescriptor_Entry) Reset() { *m = RateLimitDescriptor_Entry{} } -func (m *RateLimitDescriptor_Entry) String() string { return proto.CompactTextString(m) } -func (*RateLimitDescriptor_Entry) ProtoMessage() {} -func (*RateLimitDescriptor_Entry) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{1, 0} -} -func (m *RateLimitDescriptor_Entry) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimitDescriptor_Entry.Unmarshal(m, b) -} -func (m *RateLimitDescriptor_Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimitDescriptor_Entry.Marshal(b, m, deterministic) -} -func (dst *RateLimitDescriptor_Entry) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimitDescriptor_Entry.Merge(dst, src) -} -func (m *RateLimitDescriptor_Entry) XXX_Size() int { - return xxx_messageInfo_RateLimitDescriptor_Entry.Size(m) -} -func (m *RateLimitDescriptor_Entry) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimitDescriptor_Entry.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimitDescriptor_Entry proto.InternalMessageInfo - -func (m *RateLimitDescriptor_Entry) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *RateLimitDescriptor_Entry) GetValue() string { - if m != nil { - return m.Value - } - return "" -} - -// Defines an actual rate limit in terms of requests per unit of time and the unit itself. -type RateLimit struct { - RequestsPerUnit uint32 `protobuf:"varint,1,opt,name=requests_per_unit,json=requestsPerUnit" json:"requests_per_unit,omitempty"` - Unit RateLimit_Unit `protobuf:"varint,2,opt,name=unit,enum=pb.lyft.ratelimit.RateLimit_Unit" json:"unit,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimit) Reset() { *m = RateLimit{} } -func (m *RateLimit) String() string { return proto.CompactTextString(m) } -func (*RateLimit) ProtoMessage() {} -func (*RateLimit) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{2} -} -func (m *RateLimit) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimit.Unmarshal(m, b) -} -func (m *RateLimit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimit.Marshal(b, m, deterministic) -} -func (dst *RateLimit) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimit.Merge(dst, src) -} -func (m *RateLimit) XXX_Size() int { - return xxx_messageInfo_RateLimit.Size(m) -} -func (m *RateLimit) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimit.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimit proto.InternalMessageInfo - -func (m *RateLimit) GetRequestsPerUnit() uint32 { - if m != nil { - return m.RequestsPerUnit - } - return 0 -} - -func (m *RateLimit) GetUnit() RateLimit_Unit { - if m != nil { - return m.Unit - } - return RateLimit_UNKNOWN -} - -// A response from a ShouldRateLimit call. -type RateLimitResponse struct { - // The overall response code which takes into account all of the descriptors that were passed - // in the RateLimitRequest message. - OverallCode RateLimitResponse_Code `protobuf:"varint,1,opt,name=overall_code,json=overallCode,enum=pb.lyft.ratelimit.RateLimitResponse_Code" json:"overall_code,omitempty"` - // A list of DescriptorStatus messages which matches the length of the descriptor list passed - // in the RateLimitRequest. This can be used by the caller to determine which individual - // descriptors failed and/or what the currently configured limits are for all of them. - Statuses []*RateLimitResponse_DescriptorStatus `protobuf:"bytes,2,rep,name=statuses" json:"statuses,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimitResponse) Reset() { *m = RateLimitResponse{} } -func (m *RateLimitResponse) String() string { return proto.CompactTextString(m) } -func (*RateLimitResponse) ProtoMessage() {} -func (*RateLimitResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{3} -} -func (m *RateLimitResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimitResponse.Unmarshal(m, b) -} -func (m *RateLimitResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimitResponse.Marshal(b, m, deterministic) -} -func (dst *RateLimitResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimitResponse.Merge(dst, src) -} -func (m *RateLimitResponse) XXX_Size() int { - return xxx_messageInfo_RateLimitResponse.Size(m) -} -func (m *RateLimitResponse) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimitResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimitResponse proto.InternalMessageInfo - -func (m *RateLimitResponse) GetOverallCode() RateLimitResponse_Code { - if m != nil { - return m.OverallCode - } - return RateLimitResponse_UNKNOWN -} - -func (m *RateLimitResponse) GetStatuses() []*RateLimitResponse_DescriptorStatus { - if m != nil { - return m.Statuses - } - return nil -} - -type RateLimitResponse_DescriptorStatus struct { - // The response code for an individual descriptor. - Code RateLimitResponse_Code `protobuf:"varint,1,opt,name=code,enum=pb.lyft.ratelimit.RateLimitResponse_Code" json:"code,omitempty"` - // The current limit as configured by the server. Useful for debugging, etc. - CurrentLimit *RateLimit `protobuf:"bytes,2,opt,name=current_limit,json=currentLimit" json:"current_limit,omitempty"` - // The limit remaining in the current time unit. - LimitRemaining uint32 `protobuf:"varint,3,opt,name=limit_remaining,json=limitRemaining" json:"limit_remaining,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *RateLimitResponse_DescriptorStatus) Reset() { *m = RateLimitResponse_DescriptorStatus{} } -func (m *RateLimitResponse_DescriptorStatus) String() string { return proto.CompactTextString(m) } -func (*RateLimitResponse_DescriptorStatus) ProtoMessage() {} -func (*RateLimitResponse_DescriptorStatus) Descriptor() ([]byte, []int) { - return fileDescriptor_ratelimit_8ec600a45de499be, []int{3, 0} -} -func (m *RateLimitResponse_DescriptorStatus) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_RateLimitResponse_DescriptorStatus.Unmarshal(m, b) -} -func (m *RateLimitResponse_DescriptorStatus) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_RateLimitResponse_DescriptorStatus.Marshal(b, m, deterministic) -} -func (dst *RateLimitResponse_DescriptorStatus) XXX_Merge(src proto.Message) { - xxx_messageInfo_RateLimitResponse_DescriptorStatus.Merge(dst, src) -} -func (m *RateLimitResponse_DescriptorStatus) XXX_Size() int { - return xxx_messageInfo_RateLimitResponse_DescriptorStatus.Size(m) -} -func (m *RateLimitResponse_DescriptorStatus) XXX_DiscardUnknown() { - xxx_messageInfo_RateLimitResponse_DescriptorStatus.DiscardUnknown(m) -} - -var xxx_messageInfo_RateLimitResponse_DescriptorStatus proto.InternalMessageInfo - -func (m *RateLimitResponse_DescriptorStatus) GetCode() RateLimitResponse_Code { - if m != nil { - return m.Code - } - return RateLimitResponse_UNKNOWN -} - -func (m *RateLimitResponse_DescriptorStatus) GetCurrentLimit() *RateLimit { - if m != nil { - return m.CurrentLimit - } - return nil -} - -func (m *RateLimitResponse_DescriptorStatus) GetLimitRemaining() uint32 { - if m != nil { - return m.LimitRemaining - } - return 0 -} - -func init() { - proto.RegisterType((*RateLimitRequest)(nil), "pb.lyft.ratelimit.RateLimitRequest") - proto.RegisterType((*RateLimitDescriptor)(nil), "pb.lyft.ratelimit.RateLimitDescriptor") - proto.RegisterType((*RateLimitDescriptor_Entry)(nil), "pb.lyft.ratelimit.RateLimitDescriptor.Entry") - proto.RegisterType((*RateLimit)(nil), "pb.lyft.ratelimit.RateLimit") - proto.RegisterType((*RateLimitResponse)(nil), "pb.lyft.ratelimit.RateLimitResponse") - proto.RegisterType((*RateLimitResponse_DescriptorStatus)(nil), "pb.lyft.ratelimit.RateLimitResponse.DescriptorStatus") - proto.RegisterEnum("pb.lyft.ratelimit.RateLimit_Unit", RateLimit_Unit_name, RateLimit_Unit_value) - proto.RegisterEnum("pb.lyft.ratelimit.RateLimitResponse_Code", RateLimitResponse_Code_name, RateLimitResponse_Code_value) -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for RateLimitService service - -type RateLimitServiceClient interface { - // Determine whether rate limiting should take place. - ShouldRateLimit(ctx context.Context, in *RateLimitRequest, opts ...grpc.CallOption) (*RateLimitResponse, error) -} - -type rateLimitServiceClient struct { - cc *grpc.ClientConn -} - -func NewRateLimitServiceClient(cc *grpc.ClientConn) RateLimitServiceClient { - return &rateLimitServiceClient{cc} -} - -func (c *rateLimitServiceClient) ShouldRateLimit(ctx context.Context, in *RateLimitRequest, opts ...grpc.CallOption) (*RateLimitResponse, error) { - out := new(RateLimitResponse) - err := grpc.Invoke(ctx, "/pb.lyft.ratelimit.RateLimitService/ShouldRateLimit", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for RateLimitService service - -type RateLimitServiceServer interface { - // Determine whether rate limiting should take place. - ShouldRateLimit(context.Context, *RateLimitRequest) (*RateLimitResponse, error) -} - -func RegisterRateLimitServiceServer(s *grpc.Server, srv RateLimitServiceServer) { - s.RegisterService(&_RateLimitService_serviceDesc, srv) -} - -func _RateLimitService_ShouldRateLimit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RateLimitRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(RateLimitServiceServer).ShouldRateLimit(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/pb.lyft.ratelimit.RateLimitService/ShouldRateLimit", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(RateLimitServiceServer).ShouldRateLimit(ctx, req.(*RateLimitRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _RateLimitService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "pb.lyft.ratelimit.RateLimitService", - HandlerType: (*RateLimitServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "ShouldRateLimit", - Handler: _RateLimitService_ShouldRateLimit_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "proto/ratelimit/ratelimit.proto", -} - -func init() { - proto.RegisterFile("proto/ratelimit/ratelimit.proto", fileDescriptor_ratelimit_8ec600a45de499be) -} - -var fileDescriptor_ratelimit_8ec600a45de499be = []byte{ - // 532 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0xdd, 0x8e, 0xd2, 0x40, - 0x14, 0xde, 0xa1, 0x5d, 0x58, 0x4e, 0x17, 0x28, 0xa3, 0x31, 0x84, 0x98, 0x2c, 0x56, 0xa3, 0xf8, - 0x93, 0x6e, 0x82, 0xd9, 0x4b, 0x4d, 0x70, 0xc1, 0x2c, 0x59, 0x16, 0x74, 0x58, 0x34, 0x7a, 0x61, - 0xd3, 0xa5, 0x47, 0xb7, 0xb1, 0xdb, 0xe2, 0xcc, 0x94, 0x84, 0x3b, 0x9f, 0xc0, 0x3b, 0x1f, 0xc0, - 0x17, 0xf0, 0x0d, 0x7c, 0x37, 0xd3, 0xa1, 0x14, 0xfc, 0x09, 0x21, 0x7b, 0x77, 0xfe, 0xbe, 0xef, - 0x9c, 0x9e, 0xef, 0x4c, 0xe1, 0x60, 0xca, 0x23, 0x19, 0x1d, 0x72, 0x57, 0x62, 0xe0, 0x5f, 0xf9, - 0x72, 0x65, 0xd9, 0x2a, 0x43, 0xab, 0xd3, 0x0b, 0x3b, 0x98, 0x7f, 0x94, 0x76, 0x96, 0xb0, 0xbe, - 0x13, 0x30, 0x99, 0x2b, 0xb1, 0x9f, 0x78, 0x0c, 0xbf, 0xc4, 0x28, 0x24, 0xbd, 0x05, 0x79, 0x2f, - 0xba, 0x72, 0xfd, 0xb0, 0x46, 0x1a, 0xa4, 0x59, 0x64, 0xa9, 0x47, 0x4f, 0xc0, 0xf0, 0x50, 0x4c, - 0xb8, 0x3f, 0x95, 0x11, 0x17, 0xb5, 0x5c, 0x43, 0x6b, 0x1a, 0xad, 0xfb, 0xf6, 0x3f, 0xac, 0x76, - 0xc6, 0xd8, 0xc9, 0xca, 0xd9, 0x3a, 0x94, 0x1e, 0x80, 0x71, 0xe9, 0x4b, 0xe1, 0xb8, 0x9e, 0x87, - 0xa1, 0x57, 0xd3, 0x1a, 0xa4, 0x59, 0x62, 0x90, 0x84, 0xda, 0x2a, 0x62, 0x7d, 0x23, 0x70, 0xe3, - 0x3f, 0x2c, 0xf4, 0x25, 0x14, 0x30, 0x94, 0xdc, 0x47, 0x51, 0x23, 0xaa, 0xfd, 0x93, 0xed, 0xda, - 0xdb, 0xdd, 0x50, 0xf2, 0x39, 0x5b, 0x82, 0xeb, 0x87, 0xb0, 0xab, 0x22, 0xd4, 0x04, 0xed, 0x33, - 0xce, 0xd3, 0x0f, 0x4d, 0x4c, 0x7a, 0x13, 0x76, 0x67, 0x6e, 0x10, 0x63, 0x2d, 0xa7, 0x62, 0x0b, - 0xc7, 0xfa, 0x49, 0xa0, 0x98, 0xf1, 0xd2, 0x47, 0x50, 0xe5, 0x8b, 0x65, 0x09, 0x67, 0x8a, 0xdc, - 0x89, 0x43, 0x5f, 0x2a, 0x8e, 0x12, 0xab, 0x2c, 0x13, 0xaf, 0x90, 0x8f, 0x43, 0x5f, 0xd2, 0x23, - 0xd0, 0x55, 0x3a, 0xa1, 0x2b, 0xb7, 0xee, 0x6c, 0x9a, 0xd7, 0x4e, 0x00, 0x4c, 0x95, 0x5b, 0xcf, - 0x41, 0x57, 0x70, 0x03, 0x0a, 0xe3, 0xc1, 0xe9, 0x60, 0xf8, 0x76, 0x60, 0xee, 0x50, 0x80, 0xfc, - 0xa8, 0x7b, 0x3c, 0x1c, 0x74, 0x4c, 0x92, 0xd8, 0x67, 0xbd, 0xc1, 0xf8, 0xbc, 0x6b, 0xe6, 0xe8, - 0x1e, 0xe8, 0x27, 0xc3, 0x31, 0x33, 0x35, 0x5a, 0x00, 0xad, 0xd3, 0x7e, 0x67, 0xea, 0xd6, 0x0f, - 0x0d, 0xaa, 0x6b, 0xca, 0x8a, 0x69, 0x14, 0x0a, 0xa4, 0x7d, 0xd8, 0x8f, 0x66, 0xc8, 0xdd, 0x20, - 0x70, 0x26, 0x91, 0x87, 0x6a, 0xe6, 0x72, 0xeb, 0xe1, 0xa6, 0xa1, 0x96, 0x58, 0xfb, 0x38, 0xf2, - 0x90, 0x19, 0x29, 0x3c, 0x71, 0xe8, 0x6b, 0xd8, 0x13, 0xd2, 0x95, 0xb1, 0xc0, 0xe5, 0x35, 0x1c, - 0x6d, 0xc5, 0xb4, 0xd2, 0x65, 0xa4, 0xe0, 0x2c, 0xa3, 0xa9, 0xff, 0x22, 0x60, 0xfe, 0x9d, 0xa6, - 0xcf, 0x40, 0xbf, 0xde, 0xb4, 0x0a, 0x46, 0xdb, 0x50, 0x9a, 0xc4, 0x9c, 0x63, 0x28, 0x1d, 0x55, - 0xad, 0xa4, 0x30, 0x5a, 0xb7, 0x37, 0xf2, 0xec, 0xa7, 0x90, 0x85, 0xe0, 0x0f, 0xa0, 0xa2, 0x0a, - 0x1c, 0x8e, 0xc9, 0x53, 0xf0, 0xc3, 0x4f, 0xe9, 0xd1, 0x96, 0x83, 0x45, 0xd7, 0x34, 0x6a, 0x3d, - 0x06, 0x5d, 0xad, 0xe6, 0x0f, 0xd9, 0xf2, 0x90, 0x1b, 0x9e, 0x9a, 0x84, 0x96, 0x01, 0x86, 0x6f, - 0xba, 0xcc, 0xe9, 0xf7, 0xce, 0x7a, 0xe7, 0x66, 0xae, 0xc5, 0xd7, 0x1e, 0xdf, 0x08, 0xf9, 0xcc, - 0x9f, 0x20, 0xfd, 0x00, 0x95, 0xd1, 0x65, 0x14, 0x07, 0xde, 0xea, 0xda, 0xee, 0x6e, 0xfe, 0x60, - 0x75, 0x6e, 0xf5, 0x7b, 0xdb, 0x6c, 0xc5, 0xda, 0x79, 0x51, 0x7e, 0x5f, 0xcc, 0x0a, 0xbe, 0x12, - 0x72, 0x91, 0x57, 0xff, 0x86, 0xa7, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x0e, 0xa0, 0x99, - 0x3e, 0x04, 0x00, 0x00, -} diff --git a/proto/ratelimit/ratelimit.proto b/proto/ratelimit/ratelimit.proto deleted file mode 100644 index 7e1ee60fa..000000000 --- a/proto/ratelimit/ratelimit.proto +++ /dev/null @@ -1,102 +0,0 @@ -syntax = "proto3"; - -option go_package = "ratelimit"; - -option cc_generic_services = true; - -package pb.lyft.ratelimit; - -service RateLimitService { - // Determine whether rate limiting should take place. - rpc ShouldRateLimit (RateLimitRequest) returns (RateLimitResponse) {} -} - -// Main message for a rate limit request. The rate limit service is designed to be fully generic -// in the sense that it can operate on arbitrary hierarchical key/value pairs. The loaded -// configuration will parse the request and find the most specific limit to apply. In addition, -// a RateLimitRequest can contain multiple "descriptors" to limit on. When multiple descriptors -// are provided, the server will limit on *ALL* of them and return an OVER_LIMIT response if any -// of them are over limit. This enables more complex application level rate limiting scenarios -// if desired. -message RateLimitRequest { - // All rate limit requests must specify a domain. This enables the configuration to be per - // application without fear of overlap. E.g., "envoy". - string domain = 1; - // All rate limit requests must specify at least one RateLimitDescriptor. Each descriptor is - // processed by the service (see below). If any of the descriptors are over limit, the entire - // request is considered to be over limit. - repeated RateLimitDescriptor descriptors = 2; - // Rate limit requests can optionally specify the number of hits a request adds to the matched limit. If the - // value is not set in the message, a request increases the matched limit by 1. - uint32 hits_addend = 3; -} - -// A RateLimitDescriptor is a list of hierarchical entries that are used by the service to -// determine the final rate limit key and overall allowed limit. Here are some examples of how -// they might be used for the domain "envoy". -// 1) ["authenticated": "false"], ["ip_address": "10.0.0.1"] -// What it does: Limits all unauthenticated traffic for the IP address 10.0.0.1. The -// configuration supplies a default limit for the ip_address field. If there is a desire to raise -// the limit for 10.0.0.1 or block it entirely it can be specified directly in the -// configuration. -// 2) ["authenticated": "false"], ["path": "/foo/bar"] -// What it does: Limits all unauthenticated traffic globally for a specific path (or prefix if -// configured that way in the service). -// 3) ["authenticated": "false"], ["path": "/foo/bar"], ["ip_address": "10.0.0.1"] -// What it does: Limits unauthenticated traffic to a specific path for a specific IP address. -// Like (1) we can raise/block specific IP addresses if we want with an override configuration. -// 4) ["authenticated": "true"], ["client_id": "foo"] -// What it does: Limits all traffic for an authenticated client "foo" -// 5) ["authenticated": "true"], ["client_id": "foo"], ["path": "/foo/bar"] -// What it does: Limits traffic to a specific path for an authenticated client "foo" -// -// The idea behind the API is that (1)/(2)/(3) and (4)/(5) can be sent in 1 request if desired. -// This enables building complex application scenarios with a generic backend. -message RateLimitDescriptor { - message Entry { - string key = 1; - string value = 2; - } - - repeated Entry entries = 1; -} - -// Defines an actual rate limit in terms of requests per unit of time and the unit itself. -message RateLimit { - enum Unit { - UNKNOWN = 0; - SECOND = 1; - MINUTE = 2; - HOUR = 3; - DAY = 4; - } - - uint32 requests_per_unit = 1; - Unit unit = 2; -} - -// A response from a ShouldRateLimit call. -message RateLimitResponse { - enum Code { - UNKNOWN = 0; - OK = 1; - OVER_LIMIT = 2; - } - - message DescriptorStatus { - // The response code for an individual descriptor. - Code code = 1; - // The current limit as configured by the server. Useful for debugging, etc. - RateLimit current_limit = 2; - // The limit remaining in the current time unit. - uint32 limit_remaining = 3; - } - - // The overall response code which takes into account all of the descriptors that were passed - // in the RateLimitRequest message. - Code overall_code = 1; - // A list of DescriptorStatus messages which matches the length of the descriptor list passed - // in the RateLimitRequest. This can be used by the caller to determine which individual - // descriptors failed and/or what the currently configured limits are for all of them. - repeated DescriptorStatus statuses = 2; -} \ No newline at end of file diff --git a/src/client_cmd/main.go b/src/client_cmd/main.go index 37d1f5fd0..d65b025ff 100644 --- a/src/client_cmd/main.go +++ b/src/client_cmd/main.go @@ -7,8 +7,8 @@ import ( "os" "strings" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "golang.org/x/net/context" "google.golang.org/grpc" ) diff --git a/src/config/config.go b/src/config/config.go index 70f3b9730..8f94715c9 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -1,8 +1,8 @@ package config import ( - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" stats "github.com/lyft/gostats" "golang.org/x/net/context" ) diff --git a/src/config/config_impl.go b/src/config/config_impl.go index a0ad1ff4f..02c74633c 100644 --- a/src/config/config_impl.go +++ b/src/config/config_impl.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" stats "github.com/lyft/gostats" logger "github.com/sirupsen/logrus" "golang.org/x/net/context" diff --git a/src/limiter/cache.go b/src/limiter/cache.go index 2ca16956f..9408126ca 100644 --- a/src/limiter/cache.go +++ b/src/limiter/cache.go @@ -1,7 +1,7 @@ package limiter import ( - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" "golang.org/x/net/context" ) diff --git a/src/limiter/cache_key.go b/src/limiter/cache_key.go index 65540fa22..a06087056 100644 --- a/src/limiter/cache_key.go +++ b/src/limiter/cache_key.go @@ -5,8 +5,8 @@ import ( "strconv" "sync" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" ) diff --git a/src/redis/cache_impl.go b/src/redis/cache_impl.go index 1beb0de43..ea4c52ee4 100644 --- a/src/redis/cache_impl.go +++ b/src/redis/cache_impl.go @@ -5,7 +5,7 @@ import ( "math/rand" "github.com/coocood/freecache" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/assert" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/limiter" diff --git a/src/server/server.go b/src/server/server.go index 38520092a..d0570868b 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -1,7 +1,7 @@ package server import ( - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "net/http" "github.com/lyft/goruntime/loader" diff --git a/src/server/server_impl.go b/src/server/server_impl.go index 8624f37d5..8652bf5d8 100644 --- a/src/server/server_impl.go +++ b/src/server/server_impl.go @@ -17,7 +17,7 @@ import ( "net" "github.com/coocood/freecache" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/limiter" "github.com/envoyproxy/ratelimit/src/settings" "github.com/golang/protobuf/jsonpb" diff --git a/src/service/ratelimit.go b/src/service/ratelimit.go index 1286e5510..08b392d21 100644 --- a/src/service/ratelimit.go +++ b/src/service/ratelimit.go @@ -4,7 +4,7 @@ import ( "strings" "sync" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/assert" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/limiter" diff --git a/src/service/ratelimit_legacy.go b/src/service/ratelimit_legacy.go index e4654783a..0396b6421 100644 --- a/src/service/ratelimit_legacy.go +++ b/src/service/ratelimit_legacy.go @@ -1,8 +1,8 @@ package ratelimit import ( - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" - pb_legacy "github.com/envoyproxy/ratelimit/proto/ratelimit" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" + pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" "github.com/golang/protobuf/jsonpb" "github.com/lyft/gostats" "golang.org/x/net/context" @@ -12,7 +12,7 @@ type RateLimitLegacyServiceServer interface { pb_legacy.RateLimitServiceServer } -// legacyService is used to implement ratelimit.proto (https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto) +// legacyService is used to implement v2 rls.proto (https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto) // the legacyService receives RateLimitRequests, converts the request, and calls the service's ShouldRateLimit method. type legacyService struct { s *service diff --git a/src/service_cmd/runner/runner.go b/src/service_cmd/runner/runner.go index 85c3f8991..3f5964efb 100644 --- a/src/service_cmd/runner/runner.go +++ b/src/service_cmd/runner/runner.go @@ -10,8 +10,8 @@ import ( "github.com/coocood/freecache" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" - pb_legacy "github.com/envoyproxy/ratelimit/proto/ratelimit" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" + pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/limiter" @@ -74,9 +74,9 @@ func (runner *Runner) Run() { srv.AddJsonHandler(service) // Ratelimit is compatible with two proto definitions - // 1. data-plane-api rls.proto: https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto + // 1. data-plane-api v3 rls.proto: https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto pb.RegisterRateLimitServiceServer(srv.GrpcServer(), service) - // 2. ratelimit.proto defined in this repository: https://github.com/envoyproxy/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto + // 1. data-plane-api v2 rls.proto: https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto pb_legacy.RegisterRateLimitServiceServer(srv.GrpcServer(), service.GetLegacyService()) // (1) is the current definition, and (2) is the legacy definition. diff --git a/test/common/common.go b/test/common/common.go index e3796f5de..159fb0689 100644 --- a/test/common/common.go +++ b/test/common/common.go @@ -3,9 +3,10 @@ package common import ( "sync" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" - pb_legacy "github.com/envoyproxy/ratelimit/proto/ratelimit" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" + pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct_legacy "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" ) type TestStatSink struct { @@ -57,11 +58,11 @@ func NewRateLimitRequestLegacy(domain string, descriptors [][][2]string, hitsAdd request := &pb_legacy.RateLimitRequest{} request.Domain = domain for _, descriptor := range descriptors { - newDescriptor := &pb_legacy.RateLimitDescriptor{} + newDescriptor := &pb_struct_legacy.RateLimitDescriptor{} for _, entry := range descriptor { newDescriptor.Entries = append( newDescriptor.Entries, - &pb_legacy.RateLimitDescriptor_Entry{Key: entry[0], Value: entry[1]}) + &pb_struct_legacy.RateLimitDescriptor_Entry{Key: entry[0], Value: entry[1]}) } request.Descriptors = append(request.Descriptors, newDescriptor) } diff --git a/test/config/config_test.go b/test/config/config_test.go index 791cc1098..a2e1d204c 100644 --- a/test/config/config_test.go +++ b/test/config/config_test.go @@ -4,8 +4,8 @@ import ( "io/ioutil" "testing" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" "github.com/lyft/gostats" "github.com/stretchr/testify/assert" diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index 9c9f01ea0..22582e2c4 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -14,8 +14,8 @@ import ( "testing" "time" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" - pb_legacy "github.com/envoyproxy/ratelimit/proto/ratelimit" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" + pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" "github.com/envoyproxy/ratelimit/src/service_cmd/runner" "github.com/envoyproxy/ratelimit/test/common" "github.com/stretchr/testify/assert" @@ -36,11 +36,11 @@ func newDescriptorStatus( func newDescriptorStatusLegacy( status pb_legacy.RateLimitResponse_Code, requestsPerUnit uint32, - unit pb_legacy.RateLimit_Unit, limitRemaining uint32) *pb_legacy.RateLimitResponse_DescriptorStatus { + unit pb_legacy.RateLimitResponse_RateLimit_Unit, limitRemaining uint32) *pb_legacy.RateLimitResponse_DescriptorStatus { return &pb_legacy.RateLimitResponse_DescriptorStatus{ Code: status, - CurrentLimit: &pb_legacy.RateLimit{RequestsPerUnit: requestsPerUnit, Unit: unit}, + CurrentLimit: &pb_legacy.RateLimitResponse_RateLimit{RequestsPerUnit: requestsPerUnit, Unit: unit}, LimitRemaining: limitRemaining, } } @@ -426,7 +426,7 @@ func TestBasicConfigLegacy(t *testing.T) { &pb_legacy.RateLimitResponse{ OverallCode: pb_legacy.RateLimitResponse_OK, Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{ - newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 50, pb_legacy.RateLimit_SECOND, 49)}}, + newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 50, pb_legacy.RateLimitResponse_RateLimit_SECOND, 49)}}, response) assert.NoError(err) @@ -450,7 +450,7 @@ func TestBasicConfigLegacy(t *testing.T) { &pb_legacy.RateLimitResponse{ OverallCode: status, Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{ - newDescriptorStatusLegacy(status, 20, pb_legacy.RateLimit_MINUTE, limitRemaining)}}, + newDescriptorStatusLegacy(status, 20, pb_legacy.RateLimitResponse_RateLimit_MINUTE, limitRemaining)}}, response) assert.NoError(err) } @@ -478,8 +478,8 @@ func TestBasicConfigLegacy(t *testing.T) { &pb_legacy.RateLimitResponse{ OverallCode: status, Statuses: []*pb_legacy.RateLimitResponse_DescriptorStatus{ - newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 20, pb_legacy.RateLimit_MINUTE, limitRemaining1), - newDescriptorStatusLegacy(status, 10, pb_legacy.RateLimit_HOUR, limitRemaining2)}}, + newDescriptorStatusLegacy(pb_legacy.RateLimitResponse_OK, 20, pb_legacy.RateLimitResponse_RateLimit_MINUTE, limitRemaining1), + newDescriptorStatusLegacy(status, 10, pb_legacy.RateLimitResponse_RateLimit_HOUR, limitRemaining2)}}, response) assert.NoError(err) } diff --git a/test/mocks/config/config.go b/test/mocks/config/config.go index 044b55ec9..6205f7c9c 100644 --- a/test/mocks/config/config.go +++ b/test/mocks/config/config.go @@ -6,7 +6,7 @@ package mock_config import ( context "context" - ratelimit "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" + ratelimit "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" config "github.com/envoyproxy/ratelimit/src/config" gomock "github.com/golang/mock/gomock" stats "github.com/lyft/gostats" diff --git a/test/mocks/limiter/limiter.go b/test/mocks/limiter/limiter.go index f5c9f8bfa..53c069232 100644 --- a/test/mocks/limiter/limiter.go +++ b/test/mocks/limiter/limiter.go @@ -6,7 +6,7 @@ package mock_limiter import ( context "context" - v2 "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + v2 "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" config "github.com/envoyproxy/ratelimit/src/config" gomock "github.com/golang/mock/gomock" reflect "reflect" diff --git a/test/mocks/rls/rls.go b/test/mocks/rls/rls.go index 77cd49ae9..6be8fda9c 100644 --- a/test/mocks/rls/rls.go +++ b/test/mocks/rls/rls.go @@ -6,7 +6,7 @@ package mock_v2 import ( context "context" - v2 "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + v2 "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" gomock "github.com/golang/mock/gomock" reflect "reflect" ) diff --git a/test/redis/bench_test.go b/test/redis/bench_test.go index b268de996..8945f8706 100644 --- a/test/redis/bench_test.go +++ b/test/redis/bench_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/limiter" "github.com/envoyproxy/ratelimit/src/redis" diff --git a/test/redis/cache_impl_test.go b/test/redis/cache_impl_test.go index 56811fb9c..7c7951e19 100644 --- a/test/redis/cache_impl_test.go +++ b/test/redis/cache_impl_test.go @@ -6,7 +6,7 @@ import ( "github.com/coocood/freecache" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/limiter" "github.com/envoyproxy/ratelimit/src/redis" diff --git a/test/server/server_impl_test.go b/test/server/server_impl_test.go index de058ecbc..b56465218 100644 --- a/test/server/server_impl_test.go +++ b/test/server/server_impl_test.go @@ -8,7 +8,7 @@ import ( "strings" "testing" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/server" mock_v2 "github.com/envoyproxy/ratelimit/test/mocks/rls" diff --git a/test/service/ratelimit_legacy_test.go b/test/service/ratelimit_legacy_test.go index 71689a6af..5ab32308d 100644 --- a/test/service/ratelimit_legacy_test.go +++ b/test/service/ratelimit_legacy_test.go @@ -3,9 +3,10 @@ package ratelimit_test import ( "testing" - pb_struct "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" - pb_legacy "github.com/envoyproxy/ratelimit/proto/ratelimit" + pb_struct "github.com/envoyproxy/go-control-plane/envoy/extensions/common/ratelimit/v3" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" + pb_legacy "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb_struct_legacy "github.com/envoyproxy/go-control-plane/envoy/api/v2/ratelimit" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/redis" "github.com/envoyproxy/ratelimit/src/service" @@ -17,7 +18,7 @@ import ( "golang.org/x/net/context" ) -func convertRatelimit(ratelimit *pb.RateLimitResponse_RateLimit) (*pb_legacy.RateLimit, error) { +func convertRatelimit(ratelimit *pb.RateLimitResponse_RateLimit) (*pb_legacy.RateLimitResponse_RateLimit, error) { if ratelimit == nil { return nil, nil } @@ -28,7 +29,7 @@ func convertRatelimit(ratelimit *pb.RateLimitResponse_RateLimit) (*pb_legacy.Rat return nil, err } - rl := &pb_legacy.RateLimit{} + rl := &pb_legacy.RateLimitResponse_RateLimit{} err = jsonpb.UnmarshalString(s, rl) if err != nil { return nil, err @@ -37,12 +38,12 @@ func convertRatelimit(ratelimit *pb.RateLimitResponse_RateLimit) (*pb_legacy.Rat return rl, nil } -func convertRatelimits(ratelimits []*config.RateLimit) ([]*pb_legacy.RateLimit, error) { +func convertRatelimits(ratelimits []*config.RateLimit) ([]*pb_legacy.RateLimitResponse_RateLimit, error) { if ratelimits == nil { return nil, nil } - ret := make([]*pb_legacy.RateLimit, 0) + ret := make([]*pb_legacy.RateLimitResponse_RateLimit, 0) for _, rl := range ratelimits { if rl == nil { ret = append(ret, nil) @@ -266,7 +267,7 @@ func TestConvertLegacyRequest(test *testing.T) { { request := &pb_legacy.RateLimitRequest{ Domain: "test", - Descriptors: []*pb_legacy.RateLimitDescriptor{}, + Descriptors: []*pb_struct_legacy.RateLimitDescriptor{}, HitsAddend: 10, } @@ -285,9 +286,9 @@ func TestConvertLegacyRequest(test *testing.T) { } { - descriptors := []*pb_legacy.RateLimitDescriptor{ + descriptors := []*pb_struct_legacy.RateLimitDescriptor{ { - Entries: []*pb_legacy.RateLimitDescriptor_Entry{ + Entries: []*pb_struct_legacy.RateLimitDescriptor_Entry{ { Key: "foo", Value: "foo_value", @@ -296,7 +297,7 @@ func TestConvertLegacyRequest(test *testing.T) { }, }, { - Entries: []*pb_legacy.RateLimitDescriptor_Entry{}, + Entries: []*pb_struct_legacy.RateLimitDescriptor_Entry{}, }, { Entries: nil, @@ -375,9 +376,9 @@ func TestConvertResponse(test *testing.T) { Statuses: statuses, } - expectedRl := &pb_legacy.RateLimit{ + expectedRl := &pb_legacy.RateLimitResponse_RateLimit{ RequestsPerUnit: 10, - Unit: pb_legacy.RateLimit_DAY, + Unit: pb_legacy.RateLimitResponse_RateLimit_DAY, } expectedStatuses := []*pb_legacy.RateLimitResponse_DescriptorStatus{ diff --git a/test/service/ratelimit_test.go b/test/service/ratelimit_test.go index a545f4f2e..5c862fbe5 100644 --- a/test/service/ratelimit_test.go +++ b/test/service/ratelimit_test.go @@ -4,7 +4,7 @@ import ( "sync" "testing" - pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2" + pb "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v3" "github.com/envoyproxy/ratelimit/src/config" "github.com/envoyproxy/ratelimit/src/redis" ratelimit "github.com/envoyproxy/ratelimit/src/service"