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

chore: update protos and Makefile #211

Merged
merged 9 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
.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 -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: ## 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: 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
4 changes: 3 additions & 1 deletion buf.gen.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env -S buf generate --template
---
version: v1
plugins:
- name: go
- plugin: buf.build/protocolbuffers/go:v1.28.1
out: ./
opt: paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
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.

10 changes: 5 additions & 5 deletions gubernator.pb.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.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
Loading