Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable go modules #124

Merged
merged 7 commits into from
Mar 9, 2020
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ cover.out
bin/
.idea/
vendor
cert.pem
key.pem
private.pem
redis-per-second.conf
redis.conf
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.11"
go: "1.14"
services: redis-server
before_install: sudo apt-get update -y && sudo apt-get install stunnel4 -y
install: make bootstrap bootstrap_redis_tls
Expand Down
20 changes: 9 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
FROM golang:1.10.4 AS build
WORKDIR /go/src/github.com/lyft/ratelimit
FROM golang:1.14 AS build
WORKDIR /ratelimit

ENV GOPROXY=https://proxy.golang.org
Copy link
Member

Choose a reason for hiding this comment

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

sorry, not terribly familiar with go modules. Why is this needed in docker but not in the makefile for local builds?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a mirror that can be used to speed up module downloads. We use it in Contour.

COPY go.mod go.sum /ratelimit/
RUN go mod download

COPY src src
COPY script script
COPY vendor vendor
COPY glide.yaml glide.yaml
COPY glide.lock glide.lock
COPY proto proto

RUN script/install-glide
RUN glide install

RUN CGO_ENABLED=0 GOOS=linux go build -o /usr/local/bin/ratelimit -ldflags="-w -s" -v github.com/lyft/ratelimit/src/service_cmd
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/ratelimit -ldflags="-w -s" -v github.com/envoyproxy/ratelimit/src/service_cmd

FROM alpine:3.8 AS final
FROM alpine:3.11 AS final
RUN apk --no-cache add ca-certificates
COPY --from=build /usr/local/bin/ratelimit /bin/ratelimit
COPY --from=build /go/bin/ratelimit /bin/ratelimit
31 changes: 13 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
ifeq ("$(GOPATH)","")
$(error GOPATH must be set)
endif
export GO111MODULE=on
MODULE = github.com/envoyproxy/ratelimit

SHELL := /bin/bash
GOREPO := ${GOPATH}/src/github.com/lyft/ratelimit

.PHONY: bootstrap
bootstrap:
script/install-glide
glide install
go get github.com/golang/mock/[email protected]

.PHONY: bootstrap_tests
bootstrap_tests:
cd ./vendor/github.com/golang/mock/mockgen && go install
define REDIS_STUNNEL
cert = private.pem
pid = /var/run/stunnel.pid
Expand All @@ -33,6 +27,7 @@ redis.conf:
echo "$$REDIS_STUNNEL" >> $@
redis-per-second.conf:
echo "$$REDIS_PER_SECOND_STUNNEL" >> $@

.PHONY: bootstrap_redis_tls
bootstrap_redis_tls: redis.conf redis-per-second.conf
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
Expand All @@ -51,27 +46,27 @@ docs_format:
.PHONY: fix_format
fix_format:
script/docs_fix_format
go fmt $(shell glide nv)
go fmt $(MODULE)/...

.PHONY: check_format
check_format: docs_format
@gofmt -l $(shell glide nv | sed 's/\.\.\.//g') | tee /dev/stderr | read && echo "Files failed gofmt" && exit 1 || true
@gofmt -l $(shell go list -f '{{.Dir}}' ./...) | tee /dev/stderr | read && echo "Files failed gofmt" && exit 1 || true

.PHONY: compile
compile:
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
cd ${GOREPO}/src/config_check_cmd && go build -o ratelimit_config_check ./ && mv ./ratelimit_config_check ${GOREPO}/bin
mkdir -p ./bin
go build -mod=readonly -o ./bin/ratelimit $(MODULE)/src/service_cmd
go build -mod=readonly -o ./bin/ratelimit_client $(MODULE)/src/client_cmd
go build -mod=readonly -o ./bin/ratelimit_config_check $(MODULE)/src/config_check_cmd

.PHONY: tests_unit
tests_unit: compile
go test -race ./...
go test -race $(MODULE)/...

.PHONY: tests
tests: compile
go test -race -tags=integration ./...
go test -race -tags=integration $(MODULE)/...

.PHONY: docker
docker: tests
docker build . -t lyft/ratelimit:`git rev-parse HEAD`
docker build . -t envoyproxy/ratelimit:`git rev-parse HEAD`
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ decision is then returned to the caller.

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)
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/lyft/ratelimit/blob/0ded92a2af8261d43096eba4132e45b99a3b8b14/proto/ratelimit/ratelimit.proto)
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,
Expand All @@ -54,7 +54,7 @@ for a slight performance hit for clients using the legacy proto, ratelimit is ba
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)
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`.


Expand Down Expand Up @@ -97,7 +97,6 @@ go [here](https://golang.org/doc/install).
The docker-compose setup has three containers: redis, ratelimit-build, and ratelimit. In order to run the docker-compose setup from the root of the repo, run

```bash
glide install
docker-compose up
```

Expand Down Expand Up @@ -308,7 +307,7 @@ descriptors:
The Ratelimit service uses a library written by Lyft called [goruntime](https://github.com/lyft/goruntime) to do configuration loading. Goruntime monitors
a designated path, and watches for symlink swaps to files in the directory tree to reload configuration files.
The path to watch can be configured via the [settings](https://github.com/lyft/ratelimit/blob/master/src/settings/settings.go)
The path to watch can be configured via the [settings](https://github.com/envoyproxy/ratelimit/blob/master/src/settings/settings.go)
package with the following environment variables:
```
Expand All @@ -324,7 +323,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/lyft/ratelimit/blob/master/proto/ratelimit/ratelimit.proto)
on the RateLimitRequest message type in the Ratelimit [proto file.](https://github.com/envoyproxy/ratelimit/blob/master/proto/ratelimit/ratelimit.proto)

# Statistics

Expand Down Expand Up @@ -377,7 +376,7 @@ You can specify the debug port with the `DEBUG_PORT` environment variable. It de
# Local Cache

Ratelimit optionally uses [freecache](https://github.com/coocood/freecache) as its local caching layer, which stores the over-the-limit cache keys, and thus avoids reading the
redis cache again for the already over-the-limit keys. The local cache size can be configured via `LocalCacheSizeInBytes` in the [settings](https://github.com/lyft/ratelimit/blob/master/src/settings/settings.go).
redis cache again for the already over-the-limit keys. The local cache size can be configured via `LocalCacheSizeInBytes` in the [settings](https://github.com/envoyproxy/ratelimit/blob/master/src/settings/settings.go).
If `LocalCacheSizeInBytes` is 0, local cache is disabled.

# Redis
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ services:

# minimal container that builds the ratelimit service binary and exits.
ratelimit-build:
image: golang:1.10-alpine
working_dir: /go/src/github.com/lyft/ratelimit
command: go build -o /usr/local/bin/ratelimit /go/src/github.com/lyft/ratelimit/src/service_cmd/main.go
image: golang:1.14-alpine
working_dir: /go/src/github.com/envoyproxy/ratelimit
command: go build -o /usr/local/bin/ratelimit ./src/service_cmd/main.go
volumes:
- .:/go/src/github.com/lyft/ratelimit
- .:/go/src/github.com/envoyproxy/ratelimit
- binary:/usr/local/bin/

ratelimit:
Expand Down
142 changes: 0 additions & 142 deletions glide.lock

This file was deleted.

41 changes: 0 additions & 41 deletions glide.yaml

This file was deleted.

Loading