quota_controller.proto 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.api.servicecontrol.v1;
  16. import "google/api/annotations.proto";
  17. import "google/api/servicecontrol/v1/metric_value.proto";
  18. import "google/rpc/status.proto";
  19. import "google/api/client.proto";
  20. option cc_enable_arenas = true;
  21. option csharp_namespace = "Google.Cloud.ServiceControl.V1";
  22. option go_package = "google.golang.org/genproto/googleapis/api/servicecontrol/v1;servicecontrol";
  23. option java_multiple_files = true;
  24. option java_outer_classname = "QuotaControllerProto";
  25. option java_package = "com.google.api.servicecontrol.v1";
  26. option php_namespace = "Google\\Cloud\\ServiceControl\\V1";
  27. option ruby_package = "Google::Cloud::ServiceControl::V1";
  28. // [Google Quota Control API](/service-control/overview)
  29. //
  30. // Allows clients to allocate and release quota against a [managed
  31. // service](https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService).
  32. service QuotaController {
  33. option (google.api.default_host) = "servicecontrol.googleapis.com";
  34. option (google.api.oauth_scopes) =
  35. "https://www.googleapis.com/auth/cloud-platform,"
  36. "https://www.googleapis.com/auth/servicecontrol";
  37. // Attempts to allocate quota for the specified consumer. It should be called
  38. // before the operation is executed.
  39. //
  40. // This method requires the `servicemanagement.services.quota`
  41. // permission on the specified service. For more information, see
  42. // [Cloud IAM](https://cloud.google.com/iam).
  43. //
  44. // **NOTE:** The client **must** fail-open on server errors `INTERNAL`,
  45. // `UNKNOWN`, `DEADLINE_EXCEEDED`, and `UNAVAILABLE`. To ensure system
  46. // reliability, the server may inject these errors to prohibit any hard
  47. // dependency on the quota functionality.
  48. rpc AllocateQuota(AllocateQuotaRequest) returns (AllocateQuotaResponse) {
  49. option (google.api.http) = {
  50. post: "/v1/services/{service_name}:allocateQuota"
  51. body: "*"
  52. };
  53. }
  54. }
  55. // Request message for the AllocateQuota method.
  56. message AllocateQuotaRequest {
  57. // Name of the service as specified in the service configuration. For example,
  58. // `"pubsub.googleapis.com"`.
  59. //
  60. // See [google.api.Service][google.api.Service] for the definition of a service name.
  61. string service_name = 1;
  62. // Operation that describes the quota allocation.
  63. QuotaOperation allocate_operation = 2;
  64. // Specifies which version of service configuration should be used to process
  65. // the request. If unspecified or no matching version can be found, the latest
  66. // one will be used.
  67. string service_config_id = 4;
  68. }
  69. // Represents information regarding a quota operation.
  70. message QuotaOperation {
  71. // Supported quota modes.
  72. enum QuotaMode {
  73. // Guard against implicit default. Must not be used.
  74. UNSPECIFIED = 0;
  75. // For AllocateQuota request, allocates quota for the amount specified in
  76. // the service configuration or specified using the quota metrics. If the
  77. // amount is higher than the available quota, allocation error will be
  78. // returned and no quota will be allocated.
  79. // If multiple quotas are part of the request, and one fails, none of the
  80. // quotas are allocated or released.
  81. NORMAL = 1;
  82. // The operation allocates quota for the amount specified in the service
  83. // configuration or specified using the quota metrics. If the amount is
  84. // higher than the available quota, request does not fail but all available
  85. // quota will be allocated.
  86. // For rate quota, BEST_EFFORT will continue to deduct from other groups
  87. // even if one does not have enough quota. For allocation, it will find the
  88. // minimum available amount across all groups and deduct that amount from
  89. // all the affected groups.
  90. BEST_EFFORT = 2;
  91. // For AllocateQuota request, only checks if there is enough quota
  92. // available and does not change the available quota. No lock is placed on
  93. // the available quota either.
  94. CHECK_ONLY = 3;
  95. // Unimplemented. When used in AllocateQuotaRequest, this returns the
  96. // effective quota limit(s) in the response, and no quota check will be
  97. // performed. Not supported for other requests, and even for
  98. // AllocateQuotaRequest, this is currently supported only for allowlisted
  99. // services.
  100. QUERY_ONLY = 4;
  101. // The operation allocates quota for the amount specified in the service
  102. // configuration or specified using the quota metrics. If the requested
  103. // amount is higher than the available quota, request does not fail and
  104. // remaining quota would become negative (going over the limit).
  105. // Not supported for Rate Quota.
  106. ADJUST_ONLY = 5;
  107. }
  108. // Identity of the operation. This is expected to be unique within the scope
  109. // of the service that generated the operation, and guarantees idempotency in
  110. // case of retries.
  111. //
  112. // In order to ensure best performance and latency in the Quota backends,
  113. // operation_ids are optimally associated with time, so that related
  114. // operations can be accessed fast in storage. For this reason, the
  115. // recommended token for services that intend to operate at a high QPS is
  116. // Unix time in nanos + UUID
  117. string operation_id = 1;
  118. // Fully qualified name of the API method for which this quota operation is
  119. // requested. This name is used for matching quota rules or metric rules and
  120. // billing status rules defined in service configuration.
  121. //
  122. // This field should not be set if any of the following is true:
  123. // (1) the quota operation is performed on non-API resources.
  124. // (2) quota_metrics is set because the caller is doing quota override.
  125. //
  126. //
  127. // Example of an RPC method name:
  128. // google.example.library.v1.LibraryService.CreateShelf
  129. string method_name = 2;
  130. // Identity of the consumer for whom this quota operation is being performed.
  131. //
  132. // This can be in one of the following formats:
  133. // project:<project_id>,
  134. // project_number:<project_number>,
  135. // api_key:<api_key>.
  136. string consumer_id = 3;
  137. // Labels describing the operation.
  138. map<string, string> labels = 4;
  139. // Represents information about this operation. Each MetricValueSet
  140. // corresponds to a metric defined in the service configuration.
  141. // The data type used in the MetricValueSet must agree with
  142. // the data type specified in the metric definition.
  143. //
  144. // Within a single operation, it is not allowed to have more than one
  145. // MetricValue instances that have the same metric names and identical
  146. // label value combinations. If a request has such duplicated MetricValue
  147. // instances, the entire request is rejected with
  148. // an invalid argument error.
  149. //
  150. // This field is mutually exclusive with method_name.
  151. repeated MetricValueSet quota_metrics = 5;
  152. // Quota mode for this operation.
  153. QuotaMode quota_mode = 6;
  154. }
  155. // Response message for the AllocateQuota method.
  156. message AllocateQuotaResponse {
  157. // The same operation_id value used in the AllocateQuotaRequest. Used for
  158. // logging and diagnostics purposes.
  159. string operation_id = 1;
  160. // Indicates the decision of the allocate.
  161. repeated QuotaError allocate_errors = 2;
  162. // Quota metrics to indicate the result of allocation. Depending on the
  163. // request, one or more of the following metrics will be included:
  164. //
  165. // 1. Per quota group or per quota metric incremental usage will be specified
  166. // using the following delta metric :
  167. // "serviceruntime.googleapis.com/api/consumer/quota_used_count"
  168. //
  169. // 2. The quota limit reached condition will be specified using the following
  170. // boolean metric :
  171. // "serviceruntime.googleapis.com/quota/exceeded"
  172. repeated MetricValueSet quota_metrics = 3;
  173. // ID of the actual config used to process the request.
  174. string service_config_id = 4;
  175. }
  176. // Represents error information for [QuotaOperation][google.api.servicecontrol.v1.QuotaOperation].
  177. message QuotaError {
  178. // Error codes related to project config validations are deprecated since the
  179. // quota controller methods do not perform these validations. Instead services
  180. // have to call the Check method, without quota_properties field, to perform
  181. // these validations before calling the quota controller methods. These
  182. // methods check only for project deletion to be wipe out compliant.
  183. enum Code {
  184. // This is never used.
  185. UNSPECIFIED = 0;
  186. // Quota allocation failed.
  187. // Same as [google.rpc.Code.RESOURCE_EXHAUSTED][google.rpc.Code.RESOURCE_EXHAUSTED].
  188. RESOURCE_EXHAUSTED = 8;
  189. // Consumer cannot access the service because the service requires active
  190. // billing.
  191. BILLING_NOT_ACTIVE = 107;
  192. // Consumer's project has been marked as deleted (soft deletion).
  193. PROJECT_DELETED = 108;
  194. // Specified API key is invalid.
  195. API_KEY_INVALID = 105;
  196. // Specified API Key has expired.
  197. API_KEY_EXPIRED = 112;
  198. }
  199. // Error code.
  200. Code code = 1;
  201. // Subject to whom this error applies. See the specific enum for more details
  202. // on this field. For example, "clientip:<ip address of client>" or
  203. // "project:<Google developer project id>".
  204. string subject = 2;
  205. // Free-form text that provides details on the cause of the error.
  206. string description = 3;
  207. // Contains additional information about the quota error.
  208. // If available, `status.code` will be non zero.
  209. google.rpc.Status status = 4;
  210. }