From 4d0838125b8ff11a564b5bb46b835e9e2f4ecd8d Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Sun, 21 Jan 2024 22:09:54 -0300 Subject: [PATCH 1/7] chore: update protos and Makefile --- .gitattributes | 4 ++ Makefile | 30 ++++++----- buf.gen.yaml | 4 +- buf.lock | 4 +- gubernator.pb.go | 21 ++++---- gubernator.proto | 8 +-- gubernator_grpc.pb.go | 9 ++-- peers.pb.go | 7 ++- peers.proto | 4 +- peers_grpc.pb.go | 17 +++---- python/gubernator/gubernator_pb2.py | 79 +++++++++++++++-------------- python/gubernator/peers_pb2.py | 39 +++++++------- python/gubernator/peers_pb2_grpc.py | 4 +- 13 files changed, 117 insertions(+), 113 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..5ca46841 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.pb.go linguist-generated=true +*.pb.*.go linguist-generated=true +go.sum linguist-generated=true +buf.lock linguist-generated=true \ No newline at end of file diff --git a/Makefile b/Makefile index fde55c98..850102d1 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +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.54.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: - scripts/proto.sh +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 diff --git a/buf.gen.yaml b/buf.gen.yaml index 65a065c5..9366c73f 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -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 diff --git a/buf.lock b/buf.lock index 3435191d..4144ecf5 100644 --- a/buf.lock +++ b/buf.lock @@ -4,5 +4,5 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 711e289f6a384c4caeebaff7c6931ade - digest: shake256:e08fb55dad7469f69df00304eed31427d2d1576e9aab31e6bf86642688e04caaf0372f15fe6974cf79432779a635b3ea401ca69c943976dc42749524e4c25d94 + commit: a86849a25cc04f4dbe9b15ddddfbc488 + digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943 diff --git a/gubernator.pb.go b/gubernator.pb.go index 1e902315..5756c5ce 100644 --- a/gubernator.pb.go +++ b/gubernator.pb.go @@ -16,18 +16,17 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v3.21.7 +// protoc (unknown) // source: gubernator.proto package gubernator import ( - reflect "reflect" - sync "sync" - _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -110,7 +109,7 @@ const ( // 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. @@ -473,15 +472,15 @@ type RateLimitResp struct { // The status of the rate limit. Status Status `protobuf:"varint,1,opt,name=status,proto3,enum=pb.gubernator.Status" json:"status,omitempty"` - // The currently configured request limit (Identical to RateLimitRequest.rate_limit_config.limit). + // The currently configured request limit (Identical to [[RateLimitReq.limit]]). Limit int64 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` - // This is the number of requests remaining before the limit is hit. + // This is the number of requests remaining after the rate limiting is applied Remaining int64 `protobuf:"varint,3,opt,name=remaining,proto3" json:"remaining,omitempty"` // This is the time when the rate limit span will be reset, provided as a unix timestamp in milliseconds. ResetTime int64 `protobuf:"varint,4,opt,name=reset_time,json=resetTime,proto3" json:"reset_time,omitempty"` // Contains the error; If set all other values should be ignored Error string `protobuf:"bytes,5,opt,name=error,proto3" json:"error,omitempty"` - // 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..) Metadata map[string]string `protobuf:"bytes,6,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } @@ -750,9 +749,9 @@ var file_gubernator_proto_rawDesc = []byte{ 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x20, 0x2e, 0x70, 0x62, 0x2e, 0x67, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x22, 0x11, 0x2f, 0x76, 0x31, - 0x2f, 0x47, 0x65, 0x74, 0x52, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x73, 0x3a, 0x01, - 0x2a, 0x12, 0x65, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, + 0x65, 0x73, 0x70, 0x22, 0x1c, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x16, 0x3a, 0x01, 0x2a, 0x22, 0x11, + 0x2f, 0x76, 0x31, 0x2f, 0x47, 0x65, 0x74, 0x52, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x6d, 0x69, 0x74, + 0x73, 0x12, 0x65, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x12, 0x1d, 0x2e, 0x70, 0x62, 0x2e, 0x67, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x1a, 0x1e, 0x2e, 0x70, 0x62, 0x2e, 0x67, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x6f, 0x72, 0x2e, diff --git a/gubernator.proto b/gubernator.proto index c8f237e8..4b52e6ad 100644 --- a/gubernator.proto +++ b/gubernator.proto @@ -86,7 +86,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. @@ -174,15 +174,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 metadata = 6; } diff --git a/gubernator_grpc.pb.go b/gubernator_grpc.pb.go index 20b4c442..209b75aa 100644 --- a/gubernator_grpc.pb.go +++ b/gubernator_grpc.pb.go @@ -16,14 +16,13 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v3.21.7 +// - protoc (unknown) // source: gubernator.proto package gubernator import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -77,7 +76,7 @@ func (c *v1Client) HealthCheck(ctx context.Context, in *HealthCheckReq, opts ... } // V1Server is the server API for V1 service. -// All implementations must embed UnimplementedV1Server +// All implementations should embed UnimplementedV1Server // for forward compatibility type V1Server interface { // Given a list of rate limit requests, return the rate limits of each. @@ -85,10 +84,9 @@ type V1Server interface { // This method is for round trip benchmarking and can be used by // the client to determine connectivity to the server HealthCheck(context.Context, *HealthCheckReq) (*HealthCheckResp, error) - mustEmbedUnimplementedV1Server() } -// UnimplementedV1Server must be embedded to have forward compatible implementations. +// UnimplementedV1Server should be embedded to have forward compatible implementations. type UnimplementedV1Server struct { } @@ -98,7 +96,6 @@ func (UnimplementedV1Server) GetRateLimits(context.Context, *GetRateLimitsReq) ( func (UnimplementedV1Server) HealthCheck(context.Context, *HealthCheckReq) (*HealthCheckResp, error) { return nil, status.Errorf(codes.Unimplemented, "method HealthCheck not implemented") } -func (UnimplementedV1Server) mustEmbedUnimplementedV1Server() {} // UnsafeV1Server may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to V1Server will diff --git a/peers.pb.go b/peers.pb.go index 597cd02a..c46650b7 100644 --- a/peers.pb.go +++ b/peers.pb.go @@ -16,17 +16,16 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v3.21.7 +// protoc (unknown) // source: peers.proto package gubernator import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( diff --git a/peers.proto b/peers.proto index 5caefae4..1ce2a431 100644 --- a/peers.proto +++ b/peers.proto @@ -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) {} } diff --git a/peers_grpc.pb.go b/peers_grpc.pb.go index 355c43d6..e74a7d16 100644 --- a/peers_grpc.pb.go +++ b/peers_grpc.pb.go @@ -16,14 +16,13 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v3.21.7 +// - protoc (unknown) // source: peers.proto package gubernator import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -43,9 +42,9 @@ const ( // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type PeersV1Client interface { - // Used by peers to relay batches of requests to an authoritative peer + // Used by peers to relay batches of requests to an owner peer GetPeerRateLimits(ctx context.Context, in *GetPeerRateLimitsReq, opts ...grpc.CallOption) (*GetPeerRateLimitsResp, error) - // 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 UpdatePeerGlobals(ctx context.Context, in *UpdatePeerGlobalsReq, opts ...grpc.CallOption) (*UpdatePeerGlobalsResp, error) } @@ -76,17 +75,16 @@ func (c *peersV1Client) UpdatePeerGlobals(ctx context.Context, in *UpdatePeerGlo } // PeersV1Server is the server API for PeersV1 service. -// All implementations must embed UnimplementedPeersV1Server +// All implementations should embed UnimplementedPeersV1Server // for forward compatibility type PeersV1Server interface { - // Used by peers to relay batches of requests to an authoritative peer + // Used by peers to relay batches of requests to an owner peer GetPeerRateLimits(context.Context, *GetPeerRateLimitsReq) (*GetPeerRateLimitsResp, error) - // 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 UpdatePeerGlobals(context.Context, *UpdatePeerGlobalsReq) (*UpdatePeerGlobalsResp, error) - mustEmbedUnimplementedPeersV1Server() } -// UnimplementedPeersV1Server must be embedded to have forward compatible implementations. +// UnimplementedPeersV1Server should be embedded to have forward compatible implementations. type UnimplementedPeersV1Server struct { } @@ -96,7 +94,6 @@ func (UnimplementedPeersV1Server) GetPeerRateLimits(context.Context, *GetPeerRat func (UnimplementedPeersV1Server) UpdatePeerGlobals(context.Context, *UpdatePeerGlobalsReq) (*UpdatePeerGlobalsResp, error) { return nil, status.Errorf(codes.Unimplemented, "method UpdatePeerGlobals not implemented") } -func (UnimplementedPeersV1Server) mustEmbedUnimplementedPeersV1Server() {} // UnsafePeersV1Server may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to PeersV1Server will diff --git a/python/gubernator/gubernator_pb2.py b/python/gubernator/gubernator_pb2.py index ed3b2695..51749b92 100644 --- a/python/gubernator/gubernator_pb2.py +++ b/python/gubernator/gubernator_pb2.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: gubernator.proto +# Protobuf Python Version: 4.25.2 """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -14,44 +15,44 @@ from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10gubernator.proto\x12\rpb.gubernator\x1a\x1cgoogle/api/annotations.proto\"A\n\x10GetRateLimitsReq\x12-\n\x08requests\x18\x01 \x03(\x0b\x32\x1b.pb.gubernator.RateLimitReq\"D\n\x11GetRateLimitsResp\x12/\n\tresponses\x18\x01 \x03(\x0b\x32\x1c.pb.gubernator.RateLimitResp\"\xb4\x02\n\x0cRateLimitReq\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x12\n\nunique_key\x18\x02 \x01(\t\x12\x0c\n\x04hits\x18\x03 \x01(\x03\x12\r\n\x05limit\x18\x04 \x01(\x03\x12\x10\n\x08\x64uration\x18\x05 \x01(\x03\x12+\n\talgorithm\x18\x06 \x01(\x0e\x32\x18.pb.gubernator.Algorithm\x12)\n\x08\x62\x65havior\x18\x07 \x01(\x0e\x32\x17.pb.gubernator.Behavior\x12\r\n\x05\x62urst\x18\x08 \x01(\x03\x12;\n\x08metadata\x18\t \x03(\x0b\x32).pb.gubernator.RateLimitReq.MetadataEntry\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xea\x01\n\rRateLimitResp\x12%\n\x06status\x18\x01 \x01(\x0e\x32\x15.pb.gubernator.Status\x12\r\n\x05limit\x18\x02 \x01(\x03\x12\x11\n\tremaining\x18\x03 \x01(\x03\x12\x12\n\nreset_time\x18\x04 \x01(\x03\x12\r\n\x05\x65rror\x18\x05 \x01(\t\x12<\n\x08metadata\x18\x06 \x03(\x0b\x32*.pb.gubernator.RateLimitResp.MetadataEntry\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x10\n\x0eHealthCheckReq\"F\n\x0fHealthCheckResp\x12\x0e\n\x06status\x18\x01 \x01(\t\x12\x0f\n\x07message\x18\x02 \x01(\t\x12\x12\n\npeer_count\x18\x03 \x01(\x05*/\n\tAlgorithm\x12\x10\n\x0cTOKEN_BUCKET\x10\x00\x12\x10\n\x0cLEAKY_BUCKET\x10\x01*w\n\x08\x42\x65havior\x12\x0c\n\x08\x42\x41TCHING\x10\x00\x12\x0f\n\x0bNO_BATCHING\x10\x01\x12\n\n\x06GLOBAL\x10\x02\x12\x19\n\x15\x44URATION_IS_GREGORIAN\x10\x04\x12\x13\n\x0fRESET_REMAINING\x10\x08\x12\x10\n\x0cMULTI_REGION\x10\x10*)\n\x06Status\x12\x0f\n\x0bUNDER_LIMIT\x10\x00\x12\x0e\n\nOVER_LIMIT\x10\x01\x32\xdd\x01\n\x02V1\x12p\n\rGetRateLimits\x12\x1f.pb.gubernator.GetRateLimitsReq\x1a .pb.gubernator.GetRateLimitsResp\"\x1c\x82\xd3\xe4\x93\x02\x16\"\x11/v1/GetRateLimits:\x01*\x12\x65\n\x0bHealthCheck\x12\x1d.pb.gubernator.HealthCheckReq\x1a\x1e.pb.gubernator.HealthCheckResp\"\x17\x82\xd3\xe4\x93\x02\x11\x12\x0f/v1/HealthCheckB\"Z\x1dgithub.com/mailgun/gubernator\x80\x01\x01\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x10gubernator.proto\x12\rpb.gubernator\x1a\x1cgoogle/api/annotations.proto\"K\n\x10GetRateLimitsReq\x12\x37\n\x08requests\x18\x01 \x03(\x0b\x32\x1b.pb.gubernator.RateLimitReqR\x08requests\"O\n\x11GetRateLimitsResp\x12:\n\tresponses\x18\x01 \x03(\x0b\x32\x1c.pb.gubernator.RateLimitRespR\tresponses\"\x8e\x03\n\x0cRateLimitReq\x12\x12\n\x04name\x18\x01 \x01(\tR\x04name\x12\x1d\n\nunique_key\x18\x02 \x01(\tR\tuniqueKey\x12\x12\n\x04hits\x18\x03 \x01(\x03R\x04hits\x12\x14\n\x05limit\x18\x04 \x01(\x03R\x05limit\x12\x1a\n\x08\x64uration\x18\x05 \x01(\x03R\x08\x64uration\x12\x36\n\talgorithm\x18\x06 \x01(\x0e\x32\x18.pb.gubernator.AlgorithmR\talgorithm\x12\x33\n\x08\x62\x65havior\x18\x07 \x01(\x0e\x32\x17.pb.gubernator.BehaviorR\x08\x62\x65havior\x12\x14\n\x05\x62urst\x18\x08 \x01(\x03R\x05\x62urst\x12\x45\n\x08metadata\x18\t \x03(\x0b\x32).pb.gubernator.RateLimitReq.MetadataEntryR\x08metadata\x1a;\n\rMetadataEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01\"\xac\x02\n\rRateLimitResp\x12-\n\x06status\x18\x01 \x01(\x0e\x32\x15.pb.gubernator.StatusR\x06status\x12\x14\n\x05limit\x18\x02 \x01(\x03R\x05limit\x12\x1c\n\tremaining\x18\x03 \x01(\x03R\tremaining\x12\x1d\n\nreset_time\x18\x04 \x01(\x03R\tresetTime\x12\x14\n\x05\x65rror\x18\x05 \x01(\tR\x05\x65rror\x12\x46\n\x08metadata\x18\x06 \x03(\x0b\x32*.pb.gubernator.RateLimitResp.MetadataEntryR\x08metadata\x1a;\n\rMetadataEntry\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n\x05value\x18\x02 \x01(\tR\x05value:\x02\x38\x01\"\x10\n\x0eHealthCheckReq\"b\n\x0fHealthCheckResp\x12\x16\n\x06status\x18\x01 \x01(\tR\x06status\x12\x18\n\x07message\x18\x02 \x01(\tR\x07message\x12\x1d\n\npeer_count\x18\x03 \x01(\x05R\tpeerCount*/\n\tAlgorithm\x12\x10\n\x0cTOKEN_BUCKET\x10\x00\x12\x10\n\x0cLEAKY_BUCKET\x10\x01*w\n\x08\x42\x65havior\x12\x0c\n\x08\x42\x41TCHING\x10\x00\x12\x0f\n\x0bNO_BATCHING\x10\x01\x12\n\n\x06GLOBAL\x10\x02\x12\x19\n\x15\x44URATION_IS_GREGORIAN\x10\x04\x12\x13\n\x0fRESET_REMAINING\x10\x08\x12\x10\n\x0cMULTI_REGION\x10\x10*)\n\x06Status\x12\x0f\n\x0bUNDER_LIMIT\x10\x00\x12\x0e\n\nOVER_LIMIT\x10\x01\x32\xdd\x01\n\x02V1\x12p\n\rGetRateLimits\x12\x1f.pb.gubernator.GetRateLimitsReq\x1a .pb.gubernator.GetRateLimitsResp\"\x1c\x82\xd3\xe4\x93\x02\x16\"\x11/v1/GetRateLimits:\x01*\x12\x65\n\x0bHealthCheck\x12\x1d.pb.gubernator.HealthCheckReq\x1a\x1e.pb.gubernator.HealthCheckResp\"\x17\x82\xd3\xe4\x93\x02\x11\x12\x0f/v1/HealthCheckB\"Z\x1dgithub.com/mailgun/gubernator\x80\x01\x01\x62\x06proto3') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'gubernator_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'gubernator_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z\035github.com/mailgun/gubernator\200\001\001' - _RATELIMITREQ_METADATAENTRY._options = None - _RATELIMITREQ_METADATAENTRY._serialized_options = b'8\001' - _RATELIMITRESP_METADATAENTRY._options = None - _RATELIMITRESP_METADATAENTRY._serialized_options = b'8\001' - _V1.methods_by_name['GetRateLimits']._options = None - _V1.methods_by_name['GetRateLimits']._serialized_options = b'\202\323\344\223\002\026\"\021/v1/GetRateLimits:\001*' - _V1.methods_by_name['HealthCheck']._options = None - _V1.methods_by_name['HealthCheck']._serialized_options = b'\202\323\344\223\002\021\022\017/v1/HealthCheck' - _ALGORITHM._serialized_start=840 - _ALGORITHM._serialized_end=887 - _BEHAVIOR._serialized_start=889 - _BEHAVIOR._serialized_end=1008 - _STATUS._serialized_start=1010 - _STATUS._serialized_end=1051 - _GETRATELIMITSREQ._serialized_start=65 - _GETRATELIMITSREQ._serialized_end=130 - _GETRATELIMITSRESP._serialized_start=132 - _GETRATELIMITSRESP._serialized_end=200 - _RATELIMITREQ._serialized_start=203 - _RATELIMITREQ._serialized_end=511 - _RATELIMITREQ_METADATAENTRY._serialized_start=464 - _RATELIMITREQ_METADATAENTRY._serialized_end=511 - _RATELIMITRESP._serialized_start=514 - _RATELIMITRESP._serialized_end=748 - _RATELIMITRESP_METADATAENTRY._serialized_start=464 - _RATELIMITRESP_METADATAENTRY._serialized_end=511 - _HEALTHCHECKREQ._serialized_start=750 - _HEALTHCHECKREQ._serialized_end=766 - _HEALTHCHECKRESP._serialized_start=768 - _HEALTHCHECKRESP._serialized_end=838 - _V1._serialized_start=1054 - _V1._serialized_end=1275 + _globals['DESCRIPTOR']._options = None + _globals['DESCRIPTOR']._serialized_options = b'Z\035github.com/mailgun/gubernator\200\001\001' + _globals['_RATELIMITREQ_METADATAENTRY']._options = None + _globals['_RATELIMITREQ_METADATAENTRY']._serialized_options = b'8\001' + _globals['_RATELIMITRESP_METADATAENTRY']._options = None + _globals['_RATELIMITRESP_METADATAENTRY']._serialized_options = b'8\001' + _globals['_V1'].methods_by_name['GetRateLimits']._options = None + _globals['_V1'].methods_by_name['GetRateLimits']._serialized_options = b'\202\323\344\223\002\026\"\021/v1/GetRateLimits:\001*' + _globals['_V1'].methods_by_name['HealthCheck']._options = None + _globals['_V1'].methods_by_name['HealthCheck']._serialized_options = b'\202\323\344\223\002\021\022\017/v1/HealthCheck' + _globals['_ALGORITHM']._serialized_start=1045 + _globals['_ALGORITHM']._serialized_end=1092 + _globals['_BEHAVIOR']._serialized_start=1094 + _globals['_BEHAVIOR']._serialized_end=1213 + _globals['_STATUS']._serialized_start=1215 + _globals['_STATUS']._serialized_end=1256 + _globals['_GETRATELIMITSREQ']._serialized_start=65 + _globals['_GETRATELIMITSREQ']._serialized_end=140 + _globals['_GETRATELIMITSRESP']._serialized_start=142 + _globals['_GETRATELIMITSRESP']._serialized_end=221 + _globals['_RATELIMITREQ']._serialized_start=224 + _globals['_RATELIMITREQ']._serialized_end=622 + _globals['_RATELIMITREQ_METADATAENTRY']._serialized_start=563 + _globals['_RATELIMITREQ_METADATAENTRY']._serialized_end=622 + _globals['_RATELIMITRESP']._serialized_start=625 + _globals['_RATELIMITRESP']._serialized_end=925 + _globals['_RATELIMITRESP_METADATAENTRY']._serialized_start=563 + _globals['_RATELIMITRESP_METADATAENTRY']._serialized_end=622 + _globals['_HEALTHCHECKREQ']._serialized_start=927 + _globals['_HEALTHCHECKREQ']._serialized_end=943 + _globals['_HEALTHCHECKRESP']._serialized_start=945 + _globals['_HEALTHCHECKRESP']._serialized_end=1043 + _globals['_V1']._serialized_start=1259 + _globals['_V1']._serialized_end=1480 # @@protoc_insertion_point(module_scope) diff --git a/python/gubernator/peers_pb2.py b/python/gubernator/peers_pb2.py index 98ade704..116ee6eb 100644 --- a/python/gubernator/peers_pb2.py +++ b/python/gubernator/peers_pb2.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: peers.proto +# Protobuf Python Version: 4.25.2 """Generated protocol buffer code.""" -from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -14,24 +15,24 @@ import gubernator_pb2 as gubernator__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bpeers.proto\x12\rpb.gubernator\x1a\x10gubernator.proto\"E\n\x14GetPeerRateLimitsReq\x12-\n\x08requests\x18\x01 \x03(\x0b\x32\x1b.pb.gubernator.RateLimitReq\"J\n\x15GetPeerRateLimitsResp\x12\x31\n\x0brate_limits\x18\x01 \x03(\x0b\x32\x1c.pb.gubernator.RateLimitResp\"H\n\x14UpdatePeerGlobalsReq\x12\x30\n\x07globals\x18\x01 \x03(\x0b\x32\x1f.pb.gubernator.UpdatePeerGlobal\"z\n\x10UpdatePeerGlobal\x12\x0b\n\x03key\x18\x01 \x01(\t\x12,\n\x06status\x18\x02 \x01(\x0b\x32\x1c.pb.gubernator.RateLimitResp\x12+\n\talgorithm\x18\x03 \x01(\x0e\x32\x18.pb.gubernator.Algorithm\"\x17\n\x15UpdatePeerGlobalsResp2\xcd\x01\n\x07PeersV1\x12`\n\x11GetPeerRateLimits\x12#.pb.gubernator.GetPeerRateLimitsReq\x1a$.pb.gubernator.GetPeerRateLimitsResp\"\x00\x12`\n\x11UpdatePeerGlobals\x12#.pb.gubernator.UpdatePeerGlobalsReq\x1a$.pb.gubernator.UpdatePeerGlobalsResp\"\x00\x42\"Z\x1dgithub.com/mailgun/gubernator\x80\x01\x01\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bpeers.proto\x12\rpb.gubernator\x1a\x10gubernator.proto\"O\n\x14GetPeerRateLimitsReq\x12\x37\n\x08requests\x18\x01 \x03(\x0b\x32\x1b.pb.gubernator.RateLimitReqR\x08requests\"V\n\x15GetPeerRateLimitsResp\x12=\n\x0brate_limits\x18\x01 \x03(\x0b\x32\x1c.pb.gubernator.RateLimitRespR\nrateLimits\"Q\n\x14UpdatePeerGlobalsReq\x12\x39\n\x07globals\x18\x01 \x03(\x0b\x32\x1f.pb.gubernator.UpdatePeerGlobalR\x07globals\"\x92\x01\n\x10UpdatePeerGlobal\x12\x10\n\x03key\x18\x01 \x01(\tR\x03key\x12\x34\n\x06status\x18\x02 \x01(\x0b\x32\x1c.pb.gubernator.RateLimitRespR\x06status\x12\x36\n\talgorithm\x18\x03 \x01(\x0e\x32\x18.pb.gubernator.AlgorithmR\talgorithm\"\x17\n\x15UpdatePeerGlobalsResp2\xcd\x01\n\x07PeersV1\x12`\n\x11GetPeerRateLimits\x12#.pb.gubernator.GetPeerRateLimitsReq\x1a$.pb.gubernator.GetPeerRateLimitsResp\"\x00\x12`\n\x11UpdatePeerGlobals\x12#.pb.gubernator.UpdatePeerGlobalsReq\x1a$.pb.gubernator.UpdatePeerGlobalsResp\"\x00\x42\"Z\x1dgithub.com/mailgun/gubernator\x80\x01\x01\x62\x06proto3') -_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) -_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'peers_pb2', globals()) +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'peers_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z\035github.com/mailgun/gubernator\200\001\001' - _GETPEERRATELIMITSREQ._serialized_start=48 - _GETPEERRATELIMITSREQ._serialized_end=117 - _GETPEERRATELIMITSRESP._serialized_start=119 - _GETPEERRATELIMITSRESP._serialized_end=193 - _UPDATEPEERGLOBALSREQ._serialized_start=195 - _UPDATEPEERGLOBALSREQ._serialized_end=267 - _UPDATEPEERGLOBAL._serialized_start=269 - _UPDATEPEERGLOBAL._serialized_end=391 - _UPDATEPEERGLOBALSRESP._serialized_start=393 - _UPDATEPEERGLOBALSRESP._serialized_end=416 - _PEERSV1._serialized_start=419 - _PEERSV1._serialized_end=624 + _globals['DESCRIPTOR']._options = None + _globals['DESCRIPTOR']._serialized_options = b'Z\035github.com/mailgun/gubernator\200\001\001' + _globals['_GETPEERRATELIMITSREQ']._serialized_start=48 + _globals['_GETPEERRATELIMITSREQ']._serialized_end=127 + _globals['_GETPEERRATELIMITSRESP']._serialized_start=129 + _globals['_GETPEERRATELIMITSRESP']._serialized_end=215 + _globals['_UPDATEPEERGLOBALSREQ']._serialized_start=217 + _globals['_UPDATEPEERGLOBALSREQ']._serialized_end=298 + _globals['_UPDATEPEERGLOBAL']._serialized_start=301 + _globals['_UPDATEPEERGLOBAL']._serialized_end=447 + _globals['_UPDATEPEERGLOBALSRESP']._serialized_start=449 + _globals['_UPDATEPEERGLOBALSRESP']._serialized_end=472 + _globals['_PEERSV1']._serialized_start=475 + _globals['_PEERSV1']._serialized_end=680 # @@protoc_insertion_point(module_scope) diff --git a/python/gubernator/peers_pb2_grpc.py b/python/gubernator/peers_pb2_grpc.py index 7b8f4c99..9ebb860d 100644 --- a/python/gubernator/peers_pb2_grpc.py +++ b/python/gubernator/peers_pb2_grpc.py @@ -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!') From 3ca0510756eef8d1c2a44beb802d1f7925705dff Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Mon, 19 Feb 2024 19:06:16 -0300 Subject: [PATCH 2/7] update buf.gen.yaml --- Makefile | 9 +- buf.gen.yaml | 7 +- peers.pb.gw.go | 256 ------------------------------------------------- 3 files changed, 14 insertions(+), 258 deletions(-) delete mode 100644 peers.pb.gw.go diff --git a/Makefile b/Makefile index 5267e466..10c48762 100644 --- a/Makefile +++ b/Makefile @@ -32,13 +32,20 @@ docker: ## Build Docker image docker tag ghcr.io/mailgun/gubernator:$(VERSION) ghcr.io/mailgun/gubernator:latest .PHONY: build -build: ## Build binary +build: proto ## Build binary go build -v -ldflags $(LDFLAGS) -o gubernator ./cmd/gubernator/main.go .PHONY: 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: ## Build protos ./buf.gen.yaml diff --git a/buf.gen.yaml b/buf.gen.yaml index 9366c73f..a3c4a178 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,4 +1,4 @@ -#!/usr/bin/env -S buf generate --template +#!/usr/bin/env -S buf generate --debug --template --- version: v1 plugins: @@ -10,6 +10,11 @@ plugins: opt: - paths=source_relative - require_unimplemented_servers=false + - plugin: buf.build/grpc-ecosystem/gateway:v2.15.0 + out: ./ + opt: + - paths=source_relative + - logtostderr=true - plugin: buf.build/grpc/python:v1.57.0 out: ./python/gubernator - plugin: buf.build/protocolbuffers/python diff --git a/peers.pb.gw.go b/peers.pb.gw.go deleted file mode 100644 index 41f7d6e5..00000000 --- a/peers.pb.gw.go +++ /dev/null @@ -1,256 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: peers.proto - -/* -Package gubernator is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package gubernator - -import ( - "context" - "io" - "net/http" - - "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" - "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - "google.golang.org/protobuf/proto" -) - -// Suppress "imported and not used" errors -var _ codes.Code -var _ io.Reader -var _ status.Status -var _ = runtime.String -var _ = utilities.NewDoubleArray -var _ = metadata.Join - -func request_PeersV1_GetPeerRateLimits_0(ctx context.Context, marshaler runtime.Marshaler, client PeersV1Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetPeerRateLimitsReq - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetPeerRateLimits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_PeersV1_GetPeerRateLimits_0(ctx context.Context, marshaler runtime.Marshaler, server PeersV1Server, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq GetPeerRateLimitsReq - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.GetPeerRateLimits(ctx, &protoReq) - return msg, metadata, err - -} - -func request_PeersV1_UpdatePeerGlobals_0(ctx context.Context, marshaler runtime.Marshaler, client PeersV1Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq UpdatePeerGlobalsReq - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.UpdatePeerGlobals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_PeersV1_UpdatePeerGlobals_0(ctx context.Context, marshaler runtime.Marshaler, server PeersV1Server, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq UpdatePeerGlobalsReq - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.UpdatePeerGlobals(ctx, &protoReq) - return msg, metadata, err - -} - -// RegisterPeersV1HandlerServer registers the http handlers for service PeersV1 to "mux". -// UnaryRPC :call PeersV1Server directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPeersV1HandlerFromEndpoint instead. -func RegisterPeersV1HandlerServer(ctx context.Context, mux *runtime.ServeMux, server PeersV1Server) error { - - mux.Handle("POST", pattern_PeersV1_GetPeerRateLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/pb.gubernator.PeersV1/GetPeerRateLimits", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/GetPeerRateLimits")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_PeersV1_GetPeerRateLimits_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_PeersV1_GetPeerRateLimits_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_PeersV1_UpdatePeerGlobals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/pb.gubernator.PeersV1/UpdatePeerGlobals", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/UpdatePeerGlobals")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_PeersV1_UpdatePeerGlobals_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_PeersV1_UpdatePeerGlobals_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -// RegisterPeersV1HandlerFromEndpoint is same as RegisterPeersV1Handler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterPeersV1HandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - - return RegisterPeersV1Handler(ctx, mux, conn) -} - -// RegisterPeersV1Handler registers the http handlers for service PeersV1 to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterPeersV1Handler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterPeersV1HandlerClient(ctx, mux, NewPeersV1Client(conn)) -} - -// RegisterPeersV1HandlerClient registers the http handlers for service PeersV1 -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PeersV1Client". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PeersV1Client" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "PeersV1Client" to call the correct interceptors. -func RegisterPeersV1HandlerClient(ctx context.Context, mux *runtime.ServeMux, client PeersV1Client) error { - - mux.Handle("POST", pattern_PeersV1_GetPeerRateLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/pb.gubernator.PeersV1/GetPeerRateLimits", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/GetPeerRateLimits")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_PeersV1_GetPeerRateLimits_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_PeersV1_GetPeerRateLimits_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_PeersV1_UpdatePeerGlobals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/pb.gubernator.PeersV1/UpdatePeerGlobals", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/UpdatePeerGlobals")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_PeersV1_UpdatePeerGlobals_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_PeersV1_UpdatePeerGlobals_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - return nil -} - -var ( - pattern_PeersV1_GetPeerRateLimits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"pb.gubernator.PeersV1", "GetPeerRateLimits"}, "")) - - pattern_PeersV1_UpdatePeerGlobals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"pb.gubernator.PeersV1", "UpdatePeerGlobals"}, "")) -) - -var ( - forward_PeersV1_GetPeerRateLimits_0 = runtime.ForwardResponseMessage - - forward_PeersV1_UpdatePeerGlobals_0 = runtime.ForwardResponseMessage -) From 8ced86f797c201c069cfcf753398c353ff1560f1 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Mon, 19 Feb 2024 19:22:39 -0300 Subject: [PATCH 3/7] update versions and run buf mod update and make proto --- buf.gen.yaml | 4 ++-- buf.lock | 9 +++++++-- buf.yaml | 1 + gubernator.pb.go | 2 +- gubernator.pb.gw.go | 14 +++----------- peers.pb.go | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index a3c4a178..e33825e3 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -2,7 +2,7 @@ --- version: v1 plugins: - - plugin: buf.build/protocolbuffers/go:v1.28.1 + - plugin: buf.build/protocolbuffers/go:v1.32.0 out: ./ opt: paths=source_relative - plugin: buf.build/grpc/go:v1.3.0 @@ -10,7 +10,7 @@ plugins: opt: - paths=source_relative - require_unimplemented_servers=false - - plugin: buf.build/grpc-ecosystem/gateway:v2.15.0 + - plugin: buf.build/grpc-ecosystem/gateway:v2.19.1 out: ./ opt: - paths=source_relative diff --git a/buf.lock b/buf.lock index 4144ecf5..ac0a444b 100644 --- a/buf.lock +++ b/buf.lock @@ -4,5 +4,10 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: a86849a25cc04f4dbe9b15ddddfbc488 - digest: shake256:e19143328f8cbfe13fc226aeee5e63773ca494693a72740a7560664270039a380d94a1344234b88c7691311460df9a9b1c2982190d0a2612eae80368718e1943 + commit: 7e6f6e774e29406da95bd61cdcdbc8bc + digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73 + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + commit: 3f42134f4c564983838425bc43c7a65f + digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92 diff --git a/buf.yaml b/buf.yaml index b6d13510..ab338221 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,6 +1,7 @@ version: v1 deps: - buf.build/googleapis/googleapis + - buf.build/grpc-ecosystem/grpc-gateway build: excludes: [] breaking: diff --git a/gubernator.pb.go b/gubernator.pb.go index 310635f6..808a8814 100644 --- a/gubernator.pb.go +++ b/gubernator.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 +// protoc-gen-go v1.32.0 // protoc (unknown) // source: gubernator.proto diff --git a/gubernator.pb.gw.go b/gubernator.pb.gw.go index 1c67924b..19c0ddab 100644 --- a/gubernator.pb.gw.go +++ b/gubernator.pb.gw.go @@ -35,11 +35,7 @@ func request_V1_GetRateLimits_0(ctx context.Context, marshaler runtime.Marshaler var protoReq GetRateLimitsReq var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -52,11 +48,7 @@ func local_request_V1_GetRateLimits_0(ctx context.Context, marshaler runtime.Mar var protoReq GetRateLimitsReq var metadata runtime.ServerMetadata - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -145,7 +137,7 @@ func RegisterV1HandlerServer(ctx context.Context, mux *runtime.ServeMux, server // RegisterV1HandlerFromEndpoint is same as RegisterV1Handler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterV1HandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.Dial(endpoint, opts...) + conn, err := grpc.DialContext(ctx, endpoint, opts...) if err != nil { return err } diff --git a/peers.pb.go b/peers.pb.go index c46650b7..a805b29a 100644 --- a/peers.pb.go +++ b/peers.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.28.1 +// protoc-gen-go v1.32.0 // protoc (unknown) // source: peers.proto From 41e8d1f5f1c5952e9c0f6ef6bc9e5e73ed4d5a12 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Mon, 19 Feb 2024 21:21:20 -0300 Subject: [PATCH 4/7] remove dep --- buf.gen.yaml | 2 +- buf.yaml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index e33825e3..976f5647 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,4 +1,4 @@ -#!/usr/bin/env -S buf generate --debug --template +#!/usr/bin/env -S buf generate --debug --template --- version: v1 plugins: diff --git a/buf.yaml b/buf.yaml index ab338221..b6d13510 100644 --- a/buf.yaml +++ b/buf.yaml @@ -1,7 +1,6 @@ version: v1 deps: - buf.build/googleapis/googleapis - - buf.build/grpc-ecosystem/grpc-gateway build: excludes: [] breaking: From 91815788c989cd9cff4ec7846c87068b359eec34 Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Mon, 19 Feb 2024 21:24:55 -0300 Subject: [PATCH 5/7] fix version of gateway --- buf.gen.yaml | 2 +- gubernator.pb.gw.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/buf.gen.yaml b/buf.gen.yaml index 976f5647..c89ac9b6 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -10,7 +10,7 @@ plugins: opt: - paths=source_relative - require_unimplemented_servers=false - - plugin: buf.build/grpc-ecosystem/gateway:v2.19.1 + - plugin: buf.build/grpc-ecosystem/gateway:v2.18.0 # same version in go.mod out: ./ opt: - paths=source_relative diff --git a/gubernator.pb.gw.go b/gubernator.pb.gw.go index 19c0ddab..bb460598 100644 --- a/gubernator.pb.gw.go +++ b/gubernator.pb.gw.go @@ -35,7 +35,11 @@ func request_V1_GetRateLimits_0(ctx context.Context, marshaler runtime.Marshaler var protoReq GetRateLimitsReq var metadata runtime.ServerMetadata - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } @@ -48,7 +52,11 @@ func local_request_V1_GetRateLimits_0(ctx context.Context, marshaler runtime.Mar var protoReq GetRateLimitsReq var metadata runtime.ServerMetadata - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } From 45640d10c43356a0077bcfae75c9264b4de62f6f Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Mon, 19 Feb 2024 21:27:06 -0300 Subject: [PATCH 6/7] buf mod update --- buf.lock | 5 ----- 1 file changed, 5 deletions(-) diff --git a/buf.lock b/buf.lock index ac0a444b..b46be110 100644 --- a/buf.lock +++ b/buf.lock @@ -6,8 +6,3 @@ deps: repository: googleapis commit: 7e6f6e774e29406da95bd61cdcdbc8bc digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73 - - remote: buf.build - owner: grpc-ecosystem - repository: grpc-gateway - commit: 3f42134f4c564983838425bc43c7a65f - digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92 From 7d8dc662b1622ce1a3327326d6bfca8fdbcb480d Mon Sep 17 00:00:00 2001 From: Maria Ines Parnisari Date: Fri, 23 Feb 2024 10:25:37 -0300 Subject: [PATCH 7/7] generate reverse proxy for peers v1 --- buf.gen.yaml | 1 + peers.pb.gw.go | 256 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 peers.pb.gw.go diff --git a/buf.gen.yaml b/buf.gen.yaml index c89ac9b6..5c62f51f 100755 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -15,6 +15,7 @@ plugins: 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 diff --git a/peers.pb.gw.go b/peers.pb.gw.go new file mode 100644 index 00000000..f0929765 --- /dev/null +++ b/peers.pb.gw.go @@ -0,0 +1,256 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: peers.proto + +/* +Package gubernator is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package gubernator + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_PeersV1_GetPeerRateLimits_0(ctx context.Context, marshaler runtime.Marshaler, client PeersV1Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetPeerRateLimitsReq + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetPeerRateLimits(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_PeersV1_GetPeerRateLimits_0(ctx context.Context, marshaler runtime.Marshaler, server PeersV1Server, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetPeerRateLimitsReq + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetPeerRateLimits(ctx, &protoReq) + return msg, metadata, err + +} + +func request_PeersV1_UpdatePeerGlobals_0(ctx context.Context, marshaler runtime.Marshaler, client PeersV1Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdatePeerGlobalsReq + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.UpdatePeerGlobals(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_PeersV1_UpdatePeerGlobals_0(ctx context.Context, marshaler runtime.Marshaler, server PeersV1Server, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdatePeerGlobalsReq + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.UpdatePeerGlobals(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterPeersV1HandlerServer registers the http handlers for service PeersV1 to "mux". +// UnaryRPC :call PeersV1Server directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPeersV1HandlerFromEndpoint instead. +func RegisterPeersV1HandlerServer(ctx context.Context, mux *runtime.ServeMux, server PeersV1Server) error { + + mux.Handle("POST", pattern_PeersV1_GetPeerRateLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/pb.gubernator.PeersV1/GetPeerRateLimits", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/GetPeerRateLimits")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_PeersV1_GetPeerRateLimits_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PeersV1_GetPeerRateLimits_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_PeersV1_UpdatePeerGlobals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/pb.gubernator.PeersV1/UpdatePeerGlobals", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/UpdatePeerGlobals")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_PeersV1_UpdatePeerGlobals_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PeersV1_UpdatePeerGlobals_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterPeersV1HandlerFromEndpoint is same as RegisterPeersV1Handler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterPeersV1HandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterPeersV1Handler(ctx, mux, conn) +} + +// RegisterPeersV1Handler registers the http handlers for service PeersV1 to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterPeersV1Handler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterPeersV1HandlerClient(ctx, mux, NewPeersV1Client(conn)) +} + +// RegisterPeersV1HandlerClient registers the http handlers for service PeersV1 +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PeersV1Client". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PeersV1Client" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "PeersV1Client" to call the correct interceptors. +func RegisterPeersV1HandlerClient(ctx context.Context, mux *runtime.ServeMux, client PeersV1Client) error { + + mux.Handle("POST", pattern_PeersV1_GetPeerRateLimits_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/pb.gubernator.PeersV1/GetPeerRateLimits", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/GetPeerRateLimits")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_PeersV1_GetPeerRateLimits_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PeersV1_GetPeerRateLimits_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_PeersV1_UpdatePeerGlobals_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/pb.gubernator.PeersV1/UpdatePeerGlobals", runtime.WithHTTPPathPattern("/pb.gubernator.PeersV1/UpdatePeerGlobals")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_PeersV1_UpdatePeerGlobals_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_PeersV1_UpdatePeerGlobals_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_PeersV1_GetPeerRateLimits_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"pb.gubernator.PeersV1", "GetPeerRateLimits"}, "")) + + pattern_PeersV1_UpdatePeerGlobals_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"pb.gubernator.PeersV1", "UpdatePeerGlobals"}, "")) +) + +var ( + forward_PeersV1_GetPeerRateLimits_0 = runtime.ForwardResponseMessage + + forward_PeersV1_UpdatePeerGlobals_0 = runtime.ForwardResponseMessage +)