protoc-gen-consul-rate-limit

command module
v0.0.0-...-a706f41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

protoc-gen-consul-rate-limit This protoc plugin maintains the mapping of gRPC method names to a specification of how they should be rate-limited. This is used by the gRPC InTapHandle function (see agent/grpc-middleware/rate.go) to enforce relevant limits without having to call the handler. It works in two phases:

Phase 1

Buf/protoc invokes this plugin for each .proto file. We extract the rate limit
specification from an annotation on the RPC:

	service Foo {
		rpc Bar(BarRequest) returns (BarResponse) {
			option (hashicorp.consul.internal.ratelimit.spec) = {
				operation_type: OPERATION_TYPE_WRITE,
				operation_category: OPERATION_CATEGORY_ACL
			};
		}
	}

We write a JSON array of the limits to protobuf/package/path/.ratelimit.tmp:

[
	{
		"MethodName": "/Foo/Bar",
		"OperationType": "OPERATION_TYPE_WRITE",
		"OperationCategory": "OPERATION_CATEGORY_ACL"
	}
]

Phase 2

The protobuf.sh script (invoked by make proto) runs our postprocess script which reads all of the .ratelimit.tmp files in proto and proto-public and generates a single Go map in agent/grpc-middleware/rate_limit_mappings.gen.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址