1d95609fb7
Adds automation for generating the map of `gRPC Method Name → Rate Limit Type` used by the middleware introduced in #15550, and will ensure we don't forget to add new endpoints. Engineers must annotate their RPCs in the proto file like so: ``` rpc Foo(FooRequest) returns (FooResponse) { option (consul.internal.ratelimit.spec) = { operation_type: READ, }; } ``` When they run `make proto` a protoc plugin `protoc-gen-consul-rate-limit` will be installed that writes rate-limit specs as a JSON array to a file called `.ratelimit.tmp` (one per protobuf package/directory). After running Buf, `make proto` will execute a post-process script that will ingest all of the `.ratelimit.tmp` files and generate a Go file containing the mappings in the `agent/grpc-middleware` package. In the enterprise repository, it will write an additional file with the enterprise-only endpoints. If an engineer forgets to add the annotation to a new RPC, the plugin will return an error like so: ``` RPC Foo is missing rate-limit specification, fix it with: import "proto-public/annotations/ratelimit/ratelimit.proto"; service Bar { rpc Foo(...) returns (...) { option (hashicorp.consul.internal.ratelimit.spec) = { operation_type: OPERATION_READ | OPERATION_WRITE | OPERATION_EXEMPT, }; } } ``` In the future, this annotation can be extended to support rate-limit category (e.g. KV vs Catalog) and to determine the retry policy.
28 lines
2.2 KiB
Go
28 lines
2.2 KiB
Go
// generated by protoc-gen-consul-rate-limit; DO NOT EDIT.
|
|
package middleware
|
|
|
|
import "github.com/hashicorp/consul/agent/consul/rate"
|
|
|
|
var rpcRateLimitSpecs = map[string]rate.OperationType{
|
|
"/hashicorp.consul.acl.ACLService/Login": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.acl.ACLService/Logout": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.connectca.ConnectCAService/Sign": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.connectca.ConnectCAService/WatchRoots": rate.OperationTypeRead,
|
|
"/hashicorp.consul.dataplane.DataplaneService/GetEnvoyBootstrapParams": rate.OperationTypeRead,
|
|
"/hashicorp.consul.dataplane.DataplaneService/GetSupportedDataplaneFeatures": rate.OperationTypeRead,
|
|
"/hashicorp.consul.dns.DNSService/Query": rate.OperationTypeRead,
|
|
"/hashicorp.consul.internal.operator.OperatorService/TransferLeader": rate.OperationTypeExempt,
|
|
"/hashicorp.consul.internal.peering.PeeringService/Establish": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.internal.peering.PeeringService/GenerateToken": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.internal.peering.PeeringService/PeeringDelete": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.internal.peering.PeeringService/PeeringList": rate.OperationTypeRead,
|
|
"/hashicorp.consul.internal.peering.PeeringService/PeeringRead": rate.OperationTypeRead,
|
|
"/hashicorp.consul.internal.peering.PeeringService/PeeringWrite": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.internal.peering.PeeringService/TrustBundleListByService": rate.OperationTypeRead,
|
|
"/hashicorp.consul.internal.peering.PeeringService/TrustBundleRead": rate.OperationTypeRead,
|
|
"/hashicorp.consul.internal.peerstream.PeerStreamService/ExchangeSecret": rate.OperationTypeWrite,
|
|
"/hashicorp.consul.internal.peerstream.PeerStreamService/StreamResources": rate.OperationTypeRead,
|
|
"/hashicorp.consul.serverdiscovery.ServerDiscoveryService/WatchServers": rate.OperationTypeRead,
|
|
"/subscribe.StateChangeSubscription/Subscribe": rate.OperationTypeRead,
|
|
}
|