mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 05:45:46 +00:00
d4c435856b
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.
41 lines
1.3 KiB
Protocol Buffer
41 lines
1.3 KiB
Protocol Buffer
// Package serverdiscovery provides a service on Consul servers to discover the set of servers
|
|
// currently able to handle incoming requests.
|
|
|
|
syntax = "proto3";
|
|
|
|
package hashicorp.consul.serverdiscovery;
|
|
|
|
import "proto-public/annotations/ratelimit/ratelimit.proto";
|
|
|
|
service ServerDiscoveryService {
|
|
// WatchServers will stream back sets of ready servers as they change such as
|
|
// when new servers are added or older ones removed. A ready server is one that
|
|
// should be considered ready for sending general RPC requests towards that would
|
|
// catalog queries, xDS proxy configurations and similar services.
|
|
rpc WatchServers(WatchServersRequest) returns (stream WatchServersResponse) {
|
|
option (hashicorp.consul.internal.ratelimit.spec) = {
|
|
operation_type: OPERATION_TYPE_READ,
|
|
};
|
|
}
|
|
}
|
|
|
|
message WatchServersRequest {
|
|
// Wan being set to true will cause WAN addresses to be sent in the response
|
|
// instead of the LAN addresses which are the default
|
|
bool wan = 1;
|
|
}
|
|
|
|
message WatchServersResponse {
|
|
// Servers is the list of server address information.
|
|
repeated Server servers = 1;
|
|
}
|
|
|
|
message Server {
|
|
// id is the unique string identifying this server for all time.
|
|
string id = 1;
|
|
// address on the network of the server
|
|
string address = 2;
|
|
// the consul version of the server
|
|
string version = 3;
|
|
}
|