Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #120 from mailgun/PIP-1490-hashring
Browse files Browse the repository at this point in the history
Improve concurrent request processing
  • Loading branch information
thrawn01 authored Jan 24, 2022
2 parents 3081495 + 091a76f commit 0feb47f
Show file tree
Hide file tree
Showing 67 changed files with 3,497 additions and 573 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gubernator
gubernator-cli
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gubernator.egg-info/
.DS_Store
*.iml
googleapis/
coverage.out
coverage.html
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0-rc.13] - 2022-01-19
## Changes
* Added Opentracing support in gRPC service and various critical functions.
* Added many more useful Prometheus metrics.
* Refactored GetRateCheck calls to use a hash ring for parallel processing,
instead of locking a shared mutex to process requests sequentially.
* Rate checks now respect client's context deadline and will abort processing
immediately if canceled.
* Fixed stack overflow panic in token bucket ratelimit checking.
* Fixed leaky bucket ratelimits expiring prematurely.

## [2.0.0-rc.12] - 2021-12-28
## Changes
* Include s.conf.Behaviors in Config for NewV1Instance
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# These owners will be the default owners for everything in the repo.
* @thrawn01
* @Baliedge
30 changes: 30 additions & 0 deletions Dockerfile-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build image
FROM golang:1.17 as build

WORKDIR /go/src

# This should create cached layer of our dependencies for subsequent builds to use
COPY go.mod /go/src
COPY go.sum /go/src
RUN go mod download

# Copy the local package files to the container
ADD . /go/src

ARG VERSION

# Build the server inside the container
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo \
-ldflags "-w -s -X main.Version=$VERSION" -o /gubernator-cli /go/src/cmd/gubernator-cli/main.go

# Create our deploy image
FROM scratch

# Certs for ssl
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy our static executable.
COPY --from=build /gubernator-cli /gubernator-cli

# Run the server
ENTRYPOINT ["/gubernator-cli"]
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
.PHONY: release docker proto certs
.DEFAULT_GOAL := release

VERSION=$(shell cat version)

LDFLAGS="-X main.Version=$(VERSION)"

.PHONY: test
test:
go test ./... -v -race -p=1 -count=1
(go test -v -race -p=1 -count=1 -coverprofile coverage.out ./...; ret=$$?; \
go tool cover -func coverage.out; \
go tool cover -html coverage.out -o coverage.html; \
exit $$ret)

.PHONY: docker
docker:
docker build --build-arg VERSION=$(VERSION) -t ghcr.io/mailgun/gubernator:$(VERSION) .
docker tag ghcr.io/mailgun/gubernator:$(VERSION) ghcr.io/mailgun/gubernator:latest

.PHONY: release
release:
GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -o gubernator.darwin ./cmd/gubernator/main.go
GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -o gubernator.linux ./cmd/gubernator/main.go
go build -v -ldflags $(LDFLAGS) -o gubernator ./cmd/gubernator/main.go

.PHONY: clean
clean:
rm -f gubernator gubernator-cli

.PHONY: proto
proto:
scripts/proto.sh

.PHONY: certs
certs:
rm certs/*.key certs/*.srl certs/*.csr certs/*.pem
openssl genrsa -out certs/ca.key 4096
Expand All @@ -32,4 +40,3 @@ certs:
openssl req -sha1 -key certs/client-auth.key -new -out certs/client-auth.req -subj "/C=US/ST=TX/O=Mailgun Technologies, Inc./CN=client.com/[email protected]"
openssl x509 -req -days 3650 -in certs/client-auth.req -CA certs/client-auth-ca.pem -CAkey certs/client-auth-ca.key -passin pass:test -out certs/client-auth.pem
openssl x509 -extfile certs/client-auth.conf -extensions ssl_client -req -days 3650 -in certs/client-auth.req -CA certs/client-auth-ca.pem -CAkey certs/client-auth-ca.key -passin pass:test -out certs/client-auth.pem

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ Examples when using `Behavior = DURATION_IS_GREGORIAN`
* If `Duration = 0` (Minutes) then the rate limit will reset to `Current = 0` at the end of the minute the rate limit was created.
* If `Duration = 4` (Months) then the rate limit will reset to `Current = 0` at the end of the month the rate limit was created.

## Reset Remaining Behavior
Users may add behavior `Behavior_RESET_REMAINING` to the rate check request.
This will reset the rate limit as if created new on first use.

When using Reset Remaining, the `Hits` field should be 0.

## Gubernator as a library
If you are using golang, you can use Gubernator as a library. This is useful if
you wish to implement a rate limit service with your own company specific model
Expand Down Expand Up @@ -324,3 +330,10 @@ See the `example.conf` for all available config options and their descriptions.
See [architecture.md](/architecture.md) for a full description of the architecture and the inner
workings of gubernator.

## Monitoring
Gubernator publishes Prometheus metrics for realtime monitoring. See
[prometheus.md](prometheus.md) for details.

## Jaeger Tracing
Gubernator supports tracing using Jaeger Tracing tools. See
[jaegertracing.md](jaegertracing.md) for details.
Loading

0 comments on commit 0feb47f

Please sign in to comment.