rls.proto 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. syntax = "proto3";
  2. package envoy.service.ratelimit.v2;
  3. import "envoy/api/v2/core/base.proto";
  4. import "envoy/api/v2/ratelimit/ratelimit.proto";
  5. import "udpa/annotations/migrate.proto";
  6. import "udpa/annotations/status.proto";
  7. option java_package = "io.envoyproxy.envoy.service.ratelimit.v2";
  8. option java_outer_classname = "RlsProto";
  9. option java_multiple_files = true;
  10. option go_package = "github.com/envoyproxy/go-control-plane/envoy/service/ratelimit/v2;ratelimitv2";
  11. option java_generic_services = true;
  12. option (udpa.annotations.file_status).package_version_status = FROZEN;
  13. // [#protodoc-title: Rate Limit Service (RLS)]
  14. service RateLimitService {
  15. // Determine whether rate limiting should take place.
  16. rpc ShouldRateLimit(RateLimitRequest) returns (RateLimitResponse) {
  17. }
  18. }
  19. // Main message for a rate limit request. The rate limit service is designed to be fully generic
  20. // in the sense that it can operate on arbitrary hierarchical key/value pairs. The loaded
  21. // configuration will parse the request and find the most specific limit to apply. In addition,
  22. // a RateLimitRequest can contain multiple "descriptors" to limit on. When multiple descriptors
  23. // are provided, the server will limit on *ALL* of them and return an OVER_LIMIT response if any
  24. // of them are over limit. This enables more complex application level rate limiting scenarios
  25. // if desired.
  26. message RateLimitRequest {
  27. // All rate limit requests must specify a domain. This enables the configuration to be per
  28. // application without fear of overlap. E.g., "envoy".
  29. string domain = 1;
  30. // All rate limit requests must specify at least one RateLimitDescriptor. Each descriptor is
  31. // processed by the service (see below). If any of the descriptors are over limit, the entire
  32. // request is considered to be over limit.
  33. repeated api.v2.ratelimit.RateLimitDescriptor descriptors = 2;
  34. // Rate limit requests can optionally specify the number of hits a request adds to the matched
  35. // limit. If the value is not set in the message, a request increases the matched limit by 1.
  36. uint32 hits_addend = 3;
  37. }
  38. // A response from a ShouldRateLimit call.
  39. message RateLimitResponse {
  40. enum Code {
  41. // The response code is not known.
  42. UNKNOWN = 0;
  43. // The response code to notify that the number of requests are under limit.
  44. OK = 1;
  45. // The response code to notify that the number of requests are over limit.
  46. OVER_LIMIT = 2;
  47. }
  48. // Defines an actual rate limit in terms of requests per unit of time and the unit itself.
  49. message RateLimit {
  50. enum Unit {
  51. // The time unit is not known.
  52. UNKNOWN = 0;
  53. // The time unit representing a second.
  54. SECOND = 1;
  55. // The time unit representing a minute.
  56. MINUTE = 2;
  57. // The time unit representing an hour.
  58. HOUR = 3;
  59. // The time unit representing a day.
  60. DAY = 4;
  61. }
  62. // A name or description of this limit.
  63. string name = 3;
  64. // The number of requests per unit of time.
  65. uint32 requests_per_unit = 1;
  66. // The unit of time.
  67. Unit unit = 2;
  68. }
  69. message DescriptorStatus {
  70. // The response code for an individual descriptor.
  71. Code code = 1;
  72. // The current limit as configured by the server. Useful for debugging, etc.
  73. RateLimit current_limit = 2;
  74. // The limit remaining in the current time unit.
  75. uint32 limit_remaining = 3;
  76. }
  77. // The overall response code which takes into account all of the descriptors that were passed
  78. // in the RateLimitRequest message.
  79. Code overall_code = 1;
  80. // A list of DescriptorStatus messages which matches the length of the descriptor list passed
  81. // in the RateLimitRequest. This can be used by the caller to determine which individual
  82. // descriptors failed and/or what the currently configured limits are for all of them.
  83. repeated DescriptorStatus statuses = 2;
  84. // A list of headers to add to the response
  85. repeated api.v2.core.HeaderValue headers = 3
  86. [(udpa.annotations.field_migrate).rename = "response_headers_to_add"];
  87. // A list of headers to add to the request when forwarded
  88. repeated api.v2.core.HeaderValue request_headers_to_add = 4;
  89. }