Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cover.out
bin/
.idea/
vendor
proto/envoy
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: required
language: go
go: 1.7.5
go: "1.10"
services: redis-server
env:
- REDIS_SOCKET_TYPE=tcp REDIS_URL="localhost:6379"
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ GOREPO := ${GOPATH}/src/github.com/lyft/ratelimit
.PHONY: bootstrap
bootstrap:
script/install-glide
script/install-protoc
glide install

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

.PHONY: compile
compile:
compile: proto
mkdir -p ${GOREPO}/bin
cd ${GOREPO}/src/service_cmd && go build -o ratelimit ./ && mv ./ratelimit ${GOREPO}/bin
cd ${GOREPO}/src/client_cmd && go build -o ratelimit_client ./ && mv ./ratelimit_client ${GOREPO}/bin
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Overview](#overview)
- [Deprecation of Legacy Ratelimit Proto](#deprecation-of-legacy-ratelimit-proto)
- [Deprecation Schedule](#deprecation-schedule)
- [Building and Testing](#building-and-testing)
- [Configuration](#configuration)
- [The configuration format](#the-configuration-format)
Expand All @@ -29,6 +31,28 @@ 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/lyft/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/lyft/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,
for a slight performance hit for clients using the legacy proto, ratelimit is backwards compatible with the legacy proto.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we supporting it long-term, or just for this release? IIRC, the discussions around this were to yank out the old proto support with next release, correct? If so, I'd recommend adding a note to that effect.


## Deprecation Schedule

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/lyft/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`.


# Building and Testing

* Install redis-server.
Expand Down
52 changes: 37 additions & 15 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ import:
- package: github.com/stretchr/testify
version: v1.1.3
- package: google.golang.org/grpc
version: v1.3.0
version: v1.12.0
- package: github.com/kavu/go_reuseport
version: v1.2.0

- package: github.com/envoyproxy/data-plane-api
version: 0f8a2a3d456de4d3a29f4e8f7a641fef011d1394
- package: github.com/lyft/protoc-gen-validate
version: cae364899cd8c08b83bfdcabf4ce4dd4a68ca6da
- package: github.com/google/protobuf
version: v3.5.1
- package: github.com/golang/protobuf/proto
version: v1.1.0
80 changes: 40 additions & 40 deletions proto/ratelimit/ratelimit.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions script/generate_proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#!/usr/bin/env bash

cd proto/ratelimit
protoc --go_out=plugins=grpc:. *.proto
protoc=$(which protoc)
$protoc --version

# Legacy ratelimit proto
protoc --go_out=plugins=grpc:. proto/ratelimit/*.proto

# Data-plane-api proto
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 "
${data_plane_cmd} vendor/github.com/envoyproxy/data-plane-api/envoy/service/ratelimit/v2/rls.proto
${data_plane_cmd} vendor/github.com/envoyproxy/data-plane-api/envoy/api/v2/ratelimit/ratelimit.proto
15 changes: 15 additions & 0 deletions script/install-protoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

PROTOC_VER=3.5.1
PROTOC_REL=protoc-"${PROTOC_VER}"-linux-x86_64.zip
pushd /tmp
wget https://github.com/google/protobuf/releases/download/v"${PROTOC_VER}/${PROTOC_REL}"
unzip "${PROTOC_REL}" -d protoc

if which sudo >/dev/null;
then sudo mv protoc /usr/local && sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin
else
mv mv protoc /usr/local && ln -s /usr/local/protoc/bin/protoc /usr/local/bin
fi
popd
go get -u github.com/golang/protobuf/protoc-gen-go
15 changes: 10 additions & 5 deletions src/client_cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"os"
"strings"

pb "github.com/lyft/ratelimit/proto/ratelimit"
pb_struct "github.com/lyft/ratelimit/proto/envoy/api/v2/ratelimit"
pb "github.com/lyft/ratelimit/proto/envoy/service/ratelimit/v2"
"golang.org/x/net/context"
"google.golang.org/grpc"
)

type descriptorValue struct {
descriptor *pb.RateLimitDescriptor
descriptor *pb_struct.RateLimitDescriptor
}

func (this *descriptorValue) Set(arg string) error {
Expand All @@ -25,7 +26,7 @@ func (this *descriptorValue) Set(arg string) error {
}

this.descriptor.Entries = append(
this.descriptor.Entries, &pb.RateLimitDescriptor_Entry{Key: parts[0], Value: parts[1]})
this.descriptor.Entries, &pb_struct.RateLimitDescriptor_Entry{Key: parts[0], Value: parts[1]})
}

return nil
Expand All @@ -39,7 +40,7 @@ func main() {
dialString := flag.String(
"dial_string", "localhost:8081", "url of ratelimit server in <host>:<port> form")
domain := flag.String("domain", "", "rate limit configuration domain to query")
descriptorValue := descriptorValue{&pb.RateLimitDescriptor{}}
descriptorValue := descriptorValue{&pb_struct.RateLimitDescriptor{}}
flag.Var(
&descriptorValue, "descriptors",
"descriptor list to query in <key>=<value>,<key>=<value>,... form")
Expand All @@ -59,7 +60,11 @@ func main() {
c := pb.NewRateLimitServiceClient(conn)
response, err := c.ShouldRateLimit(
context.Background(),
&pb.RateLimitRequest{*domain, []*pb.RateLimitDescriptor{descriptorValue.descriptor}, 1})
&pb.RateLimitRequest{
Domain: *domain,
Descriptors: []*pb_struct.RateLimitDescriptor{descriptorValue.descriptor},
HitsAddend: 1,
})
if err != nil {
fmt.Printf("request error: %s\n", err.Error())
os.Exit(1)
Expand Down
Loading