Skip to content

Commit 2e0387b

Browse files
authored
proto: use the proto defined in data-plane-api (#39)
1 parent 0ded92a commit 2e0387b

27 files changed

Lines changed: 1023 additions & 217 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cover.out
33
bin/
44
.idea/
55
vendor
6+
proto/envoy

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
sudo: required
22
language: go
3-
go: 1.7.5
3+
go: "1.10"
44
services: redis-server
55
env:
66
- REDIS_SOCKET_TYPE=tcp REDIS_URL="localhost:6379"

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ GOREPO := ${GOPATH}/src/github.com/lyft/ratelimit
88
.PHONY: bootstrap
99
bootstrap:
1010
script/install-glide
11+
script/install-protoc
1112
glide install
1213

1314
.PHONY: bootstrap_tests
@@ -28,7 +29,7 @@ check_format: docs_format
2829
@gofmt -l $(shell glide nv | sed 's/\.\.\.//g') | tee /dev/stderr | read && echo "Files failed gofmt" && exit 1 || true
2930

3031
.PHONY: compile
31-
compile:
32+
compile: proto
3233
mkdir -p ${GOREPO}/bin
3334
cd ${GOREPO}/src/service_cmd && go build -o ratelimit ./ && mv ./ratelimit ${GOREPO}/bin
3435
cd ${GOREPO}/src/client_cmd && go build -o ratelimit_client ./ && mv ./ratelimit_client ${GOREPO}/bin

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
44

55
- [Overview](#overview)
6+
- [Deprecation of Legacy Ratelimit Proto](#deprecation-of-legacy-ratelimit-proto)
7+
- [Deprecation Schedule](#deprecation-schedule)
68
- [Building and Testing](#building-and-testing)
79
- [Configuration](#configuration)
810
- [The configuration format](#the-configuration-format)
@@ -29,6 +31,28 @@ applications. Applications request a rate limit decision based on a domain and a
2931
reads the configuration from disk via [runtime](https://github.com/lyft/goruntime), composes a cache key, and talks to the redis cache. A
3032
decision is then returned to the caller.
3133

34+
# Deprecation of Legacy Ratelimit Proto
35+
36+
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).
37+
Logically the data-plane-api [rls](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v2/rls.proto)
38+
is equivalent to the [ratelimit.proto](https://github.com/lyft/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto)
39+
defined in this repo. However, due
40+
to the namespace differences and how gRPC routing works it is not possible to transparently route the
41+
legacy ratelimit (ones based in the [ratelimit.proto](https://github.com/lyft/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto)
42+
defined in this repo) requests to the data-plane-api
43+
definitions. Therefore, the ratelimit service will upgrade the requests, process them internally as it would
44+
process a data-plane-api ratelimit request, and then downgrade the response to send back to the client. This means that,
45+
for a slight performance hit for clients using the legacy proto, ratelimit is backwards compatible with the legacy proto.
46+
47+
## Deprecation Schedule
48+
49+
1. `v1.0.0` tagged on commit `0ded92a2af8261d43096eba4132e45b99a3b8b14`. Ratelimit has been in production
50+
use at Lyft for over 2 years.
51+
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).
52+
3. `v2.0.0` deletes support for the legacy [ratelimit.proto](https://github.com/lyft/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto). This version will be tagged by the end of 2018Q3 (~September 2018)
53+
to give time to community members running ratelimit off of `master`.
54+
55+
3256
# Building and Testing
3357

3458
* Install redis-server.

glide.lock

Lines changed: 37 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ import:
2626
- package: github.com/stretchr/testify
2727
version: v1.1.3
2828
- package: google.golang.org/grpc
29-
version: v1.3.0
29+
version: v1.12.0
3030
- package: github.com/kavu/go_reuseport
3131
version: v1.2.0
32-
32+
- package: github.com/envoyproxy/data-plane-api
33+
version: 0f8a2a3d456de4d3a29f4e8f7a641fef011d1394
34+
- package: github.com/lyft/protoc-gen-validate
35+
version: cae364899cd8c08b83bfdcabf4ce4dd4a68ca6da
36+
- package: github.com/google/protobuf
37+
version: v3.5.1
38+
- package: github.com/golang/protobuf/proto
39+
version: v1.1.0

proto/ratelimit/ratelimit.pb.go

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/generate_proto

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/usr/bin/env bash
22

3-
cd proto/ratelimit
4-
protoc --go_out=plugins=grpc:. *.proto
3+
protoc=$(which protoc)
4+
$protoc --version
5+
6+
# Legacy ratelimit proto
7+
protoc --go_out=plugins=grpc:. proto/ratelimit/*.proto
8+
9+
# Data-plane-api proto
10+
data_plane_cmd="protoc --go_out=plugins=grpc,Menvoy/api/v2/ratelimit/ratelimit.proto=github.com/lyft/ratelimit/proto/envoy/api/v2/ratelimit:proto/. --proto_path=vendor/github.com/envoyproxy/data-plane-api --proto_path=vendor/github.com/lyft/protoc-gen-validate --proto_path=vendor/github.com/google/protobuf/src "
11+
${data_plane_cmd} vendor/github.com/envoyproxy/data-plane-api/envoy/service/ratelimit/v2/rls.proto
12+
${data_plane_cmd} vendor/github.com/envoyproxy/data-plane-api/envoy/api/v2/ratelimit/ratelimit.proto

script/install-protoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
PROTOC_VER=3.5.1
4+
PROTOC_REL=protoc-"${PROTOC_VER}"-linux-x86_64.zip
5+
pushd /tmp
6+
wget https://github.com/google/protobuf/releases/download/v"${PROTOC_VER}/${PROTOC_REL}"
7+
unzip "${PROTOC_REL}" -d protoc
8+
9+
if which sudo >/dev/null;
10+
then sudo mv protoc /usr/local && sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin
11+
else
12+
mv mv protoc /usr/local && ln -s /usr/local/protoc/bin/protoc /usr/local/bin
13+
fi
14+
popd
15+
go get -u github.com/golang/protobuf/protoc-gen-go

src/client_cmd/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"os"
88
"strings"
99

10-
pb "github.com/lyft/ratelimit/proto/ratelimit"
10+
pb_struct "github.com/lyft/ratelimit/proto/envoy/api/v2/ratelimit"
11+
pb "github.com/lyft/ratelimit/proto/envoy/service/ratelimit/v2"
1112
"golang.org/x/net/context"
1213
"google.golang.org/grpc"
1314
)
1415

1516
type descriptorValue struct {
16-
descriptor *pb.RateLimitDescriptor
17+
descriptor *pb_struct.RateLimitDescriptor
1718
}
1819

1920
func (this *descriptorValue) Set(arg string) error {
@@ -25,7 +26,7 @@ func (this *descriptorValue) Set(arg string) error {
2526
}
2627

2728
this.descriptor.Entries = append(
28-
this.descriptor.Entries, &pb.RateLimitDescriptor_Entry{Key: parts[0], Value: parts[1]})
29+
this.descriptor.Entries, &pb_struct.RateLimitDescriptor_Entry{Key: parts[0], Value: parts[1]})
2930
}
3031

3132
return nil
@@ -39,7 +40,7 @@ func main() {
3940
dialString := flag.String(
4041
"dial_string", "localhost:8081", "url of ratelimit server in <host>:<port> form")
4142
domain := flag.String("domain", "", "rate limit configuration domain to query")
42-
descriptorValue := descriptorValue{&pb.RateLimitDescriptor{}}
43+
descriptorValue := descriptorValue{&pb_struct.RateLimitDescriptor{}}
4344
flag.Var(
4445
&descriptorValue, "descriptors",
4546
"descriptor list to query in <key>=<value>,<key>=<value>,... form")
@@ -59,7 +60,11 @@ func main() {
5960
c := pb.NewRateLimitServiceClient(conn)
6061
response, err := c.ShouldRateLimit(
6162
context.Background(),
62-
&pb.RateLimitRequest{*domain, []*pb.RateLimitDescriptor{descriptorValue.descriptor}, 1})
63+
&pb.RateLimitRequest{
64+
Domain: *domain,
65+
Descriptors: []*pb_struct.RateLimitDescriptor{descriptorValue.descriptor},
66+
HitsAddend: 1,
67+
})
6368
if err != nil {
6469
fmt.Printf("request error: %s\n", err.Error())
6570
os.Exit(1)

0 commit comments

Comments
 (0)