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