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

Commit

Permalink
chore: update protos and Makefile (#211)
Browse files Browse the repository at this point in the history
* chore: update protos and Makefile

* update buf.gen.yaml

* update versions and run buf mod update and make proto

* remove dep

* fix version of gateway

* buf mod update

* generate reverse proxy for peers v1
  • Loading branch information
miparnisari authored Feb 23, 2024
1 parent a312ed7 commit 68f7715
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pb.go linguist-generated=true
*.pb.*.go linguist-generated=true
go.sum linguist-generated=true
buf.lock linguist-generated=true
38 changes: 24 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
.DEFAULT_GOAL := release
.DEFAULT_GOAL := build
VERSION=$(shell cat version)
LDFLAGS="-X main.Version=$(VERSION)"
GOLANGCI_LINT = $(GOPATH)/bin/golangci-lint
GOLANGCI_LINT_VERSION = 1.56.2

$(GOLANGCI_LINT):
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

$(GOLANGCI_LINT): ## Download Go linter
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run
lint: $(GOLANGCI_LINT) ## Run Go linter
$(GOLANGCI_LINT) run -v --fix -c .golangci.yml ./...

.PHONY: test
test:
test: ## Run unit tests and measure code coverage
(go test -v -race -p=1 -count=1 -tags holster_test_mode -coverprofile coverage.out ./...; ret=$$?; \
go tool cover -func coverage.out; \
go tool cover -html coverage.out -o coverage.html; \
exit $$ret)

.PHONY: bench
bench:
bench: ## Run Go benchmarks
go test ./... -bench . -benchtime 5s -timeout 0 -run=XXX -benchmem

.PHONY: docker
docker:
docker: ## Build Docker image
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:
.PHONY: build
build: proto ## Build binary
go build -v -ldflags $(LDFLAGS) -o gubernator ./cmd/gubernator/main.go

.PHONY: clean
clean:
clean: ## Clean binaries
rm -f gubernator gubernator-cli

.PHONY: clean-proto
clean-proto: ## Clean the generated source files from the protobuf sources
@echo "==> Cleaning up the go generated files from proto"
@find . -name "*.pb.go" -type f -delete
@find . -name "*.pb.*.go" -type f -delete


.PHONY: proto
proto:
# Install buf: https://buf.build/docs/installation
buf generate
proto: ## Build protos
./buf.gen.yaml

.PHONY: certs
certs:
certs: ## Generate SSL certificates
rm certs/*.key || rm certs/*.srl || rm certs/*.csr || rm certs/*.pem || rm certs/*.cert || true
openssl genrsa -out certs/ca.key 4096
openssl req -new -x509 -key certs/ca.key -sha256 -subj "/C=US/ST=TX/O=Mailgun Technologies, Inc." -days 3650 -out certs/ca.cert
Expand Down
10 changes: 9 additions & 1 deletion buf.gen.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/usr/bin/env -S buf generate --debug --template
---
version: v1
plugins:
- name: go
- plugin: buf.build/protocolbuffers/go:v1.32.0
out: ./
opt: paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
out: ./
opt:
- paths=source_relative
- require_unimplemented_servers=false
- plugin: buf.build/grpc-ecosystem/gateway:v2.18.0 # same version in go.mod
out: ./
opt:
- paths=source_relative
- logtostderr=true
- generate_unbound_methods=true
- plugin: buf.build/grpc/python:v1.57.0
out: ./python/gubernator
- plugin: buf.build/protocolbuffers/python
Expand Down
4 changes: 2 additions & 2 deletions buf.lock

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

8 changes: 4 additions & 4 deletions gubernator.pb.go

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

2 changes: 1 addition & 1 deletion gubernator.pb.gw.go

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

8 changes: 4 additions & 4 deletions gubernator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum Behavior {
// distributed to each peer and cached locally. A rate limit request received from any peer in the
// cluster will first check the local cache for a rate limit answer, if it exists the peer will
// immediately return the answer to the client and asynchronously forward the aggregate hits to
// the peer coordinator. Because of GLOBALS async nature we lose some accuracy in rate limit
// the owner peer. Because of GLOBALS async nature we lose some accuracy in rate limit
// reporting, which may result in allowing some requests beyond the chosen rate limit. However we
// gain massive performance as every request coming into the system does not have to wait for a
// single peer to decide if the rate limit has been reached.
Expand Down Expand Up @@ -178,15 +178,15 @@ enum Status {
message RateLimitResp {
// The status of the rate limit.
Status status = 1;
// The currently configured request limit (Identical to RateLimitRequest.rate_limit_config.limit).
// The currently configured request limit (Identical to [[RateLimitReq.limit]]).
int64 limit = 2;
// This is the number of requests remaining before the limit is hit.
// This is the number of requests remaining before the rate limit is hit but after subtracting the hits from the current request
int64 remaining = 3;
// This is the time when the rate limit span will be reset, provided as a unix timestamp in milliseconds.
int64 reset_time = 4;
// Contains the error; If set all other values should be ignored
string error = 5;
// This is additional metadata that a client might find useful. (IE: Additional headers, corrdinator ownership, etc..)
// This is additional metadata that a client might find useful. (IE: Additional headers, coordinator ownership, etc..)
map<string, string> metadata = 6;
}

Expand Down
2 changes: 1 addition & 1 deletion peers.pb.gw.go

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

4 changes: 2 additions & 2 deletions peers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import "gubernator.proto";

// NOTE: For use by gubernator peers only
service PeersV1 {
// Used by peers to relay batches of requests to an authoritative peer
// Used by peers to relay batches of requests to an owner peer
rpc GetPeerRateLimits (GetPeerRateLimitsReq) returns (GetPeerRateLimitsResp) {}

// Used by peers send global rate limit updates to other peers
// Used by owner peers to send global rate limit updates to non-owner peers
rpc UpdatePeerGlobals (UpdatePeerGlobalsReq) returns (UpdatePeerGlobalsResp) {}
}

Expand Down
8 changes: 4 additions & 4 deletions peers_grpc.pb.go

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

2 changes: 1 addition & 1 deletion python/gubernator/gubernator_pb2.py

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

2 changes: 1 addition & 1 deletion python/gubernator/peers_pb2.py

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

4 changes: 2 additions & 2 deletions python/gubernator/peers_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class PeersV1Servicer(object):
"""

def GetPeerRateLimits(self, request, context):
"""Used by peers to relay batches of requests to an authoritative peer
"""Used by peers to relay batches of requests to an owner peer
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def UpdatePeerGlobals(self, request, context):
"""Used by peers send global rate limit updates to other peers
"""Used by owner peers to send global rate limit updates to non-owner peers
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
Expand Down

0 comments on commit 68f7715

Please sign in to comment.