| 1 |
// Copyright 2026 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 |
|
| 15 |
syntax = "proto3"; |
| 16 |
|
| 17 |
package google.api; |
| 18 |
|
| 19 |
option go_package = "google.golang.org/genproto/googleapis/api/serviceconfig;serviceconfig"; |
| 20 |
option java_multiple_files = true; |
| 21 |
option java_outer_classname = "QuotaProto"; |
| 22 |
option java_package = "com.google.api"; |
| 23 |
option objc_class_prefix = "GAPI"; |
| 24 |
|
| 25 |
// Quota configuration helps to achieve fairness and budgeting in service |
| 26 |
// usage. |
| 27 |
// |
| 28 |
// The metric based quota configuration works this way: |
| 29 |
// - The service configuration defines a set of metrics. |
| 30 |
// - For API calls, the quota.metric_rules maps methods to metrics with |
| 31 |
// corresponding costs. |
| 32 |
// - The quota.limits defines limits on the metrics, which will be used for |
| 33 |
// quota checks at runtime. |
| 34 |
// |
| 35 |
// An example quota configuration in yaml format: |
| 36 |
// |
| 37 |
// quota: |
| 38 |
// limits: |
| 39 |
// |
| 40 |
// - name: apiWriteQpsPerProject |
| 41 |
// metric: library.googleapis.com/write_calls |
| 42 |
// unit: "1/min/{project}" # rate limit for consumer projects |
| 43 |
// values: |
| 44 |
// STANDARD: 10000 |
| 45 |
// |
| 46 |
// |
| 47 |
// (The metric rules bind all methods to the read_calls metric, |
| 48 |
// except for the UpdateBook and DeleteBook methods. These two methods |
| 49 |
// are mapped to the write_calls metric, with the UpdateBook method |
| 50 |
// consuming at twice rate as the DeleteBook method.) |
| 51 |
// metric_rules: |
| 52 |
// - selector: "*" |
| 53 |
// metric_costs: |
| 54 |
// library.googleapis.com/read_calls: 1 |
| 55 |
// - selector: google.example.library.v1.LibraryService.UpdateBook |
| 56 |
// metric_costs: |
| 57 |
// library.googleapis.com/write_calls: 2 |
| 58 |
// - selector: google.example.library.v1.LibraryService.DeleteBook |
| 59 |
// metric_costs: |
| 60 |
// library.googleapis.com/write_calls: 1 |
| 61 |
// |
| 62 |
// Corresponding Metric definition: |
| 63 |
// |
| 64 |
// metrics: |
| 65 |
// - name: library.googleapis.com/read_calls |
| 66 |
// display_name: Read requests |
| 67 |
// metric_kind: DELTA |
| 68 |
// value_type: INT64 |
| 69 |
// |
| 70 |
// - name: library.googleapis.com/write_calls |
| 71 |
// display_name: Write requests |
| 72 |
// metric_kind: DELTA |
| 73 |
// value_type: INT64 |
| 74 |
// |
| 75 |
// |
| 76 |
message Quota { |
| 77 |
// List of QuotaLimit definitions for the service. |
| 78 |
repeated QuotaLimit limits = 3; |
| 79 |
|
| 80 |
// List of MetricRule definitions, each one mapping a selected method to one |
| 81 |
// or more metrics. |
| 82 |
repeated MetricRule metric_rules = 4; |
| 83 |
} |
| 84 |
|
| 85 |
// Bind API methods to metrics. Binding a method to a metric causes that |
| 86 |
// metric's configured quota behaviors to apply to the method call. |
| 87 |
message MetricRule { |
| 88 |
// Selects the methods to which this rule applies. |
| 89 |
// |
| 90 |
// Refer to [selector][google.api.DocumentationRule.selector] for syntax |
| 91 |
// details. |
| 92 |
string selector = 1; |
| 93 |
|
| 94 |
// Metrics to update when the selected methods are called, and the associated |
| 95 |
// cost applied to each metric. |
| 96 |
// |
| 97 |
// The key of the map is the metric name, and the values are the amount |
| 98 |
// increased for the metric against which the quota limits are defined. |
| 99 |
// The value must not be negative. |
| 100 |
map<string, int64> metric_costs = 2; |
| 101 |
} |
| 102 |
|
| 103 |
// `QuotaLimit` defines a specific limit that applies over a specified duration |
| 104 |
// for a limit type. There can be at most one limit for a duration and limit |
| 105 |
// type combination defined within a `QuotaGroup`. |
| 106 |
message QuotaLimit { |
| 107 |
// Name of the quota limit. |
| 108 |
// |
| 109 |
// The name must be provided, and it must be unique within the service. The |
| 110 |
// name can only include alphanumeric characters as well as '-'. |
| 111 |
// |
| 112 |
// The maximum length of the limit name is 64 characters. |
| 113 |
string name = 6; |
| 114 |
|
| 115 |
// Optional. User-visible, extended description for this quota limit. |
| 116 |
// Should be used only when more context is needed to understand this limit |
| 117 |
// than provided by the limit's display name (see: `display_name`). |
| 118 |
string description = 2; |
| 119 |
|
| 120 |
// Default number of tokens that can be consumed during the specified |
| 121 |
// duration. This is the number of tokens assigned when a client |
| 122 |
// application developer activates the service for his/her project. |
| 123 |
// |
| 124 |
// Specifying a value of 0 will block all requests. This can be used if you |
| 125 |
// are provisioning quota to selected consumers and blocking others. |
| 126 |
// Similarly, a value of -1 will indicate an unlimited quota. No other |
| 127 |
// negative values are allowed. |
| 128 |
// |
| 129 |
// Used by group-based quotas only. |
| 130 |
int64 default_limit = 3; |
| 131 |
|
| 132 |
// Maximum number of tokens that can be consumed during the specified |
| 133 |
// duration. Client application developers can override the default limit up |
| 134 |
// to this maximum. If specified, this value cannot be set to a value less |
| 135 |
// than the default limit. If not specified, it is set to the default limit. |
| 136 |
// |
| 137 |
// To allow clients to apply overrides with no upper bound, set this to -1, |
| 138 |
// indicating unlimited maximum quota. |
| 139 |
// |
| 140 |
// Used by group-based quotas only. |
| 141 |
int64 max_limit = 4; |
| 142 |
|
| 143 |
// Free tier value displayed in the Developers Console for this limit. |
| 144 |
// The free tier is the number of tokens that will be subtracted from the |
| 145 |
// billed amount when billing is enabled. |
| 146 |
// This field can only be set on a limit with duration "1d", in a billable |
| 147 |
// group; it is invalid on any other limit. If this field is not set, it |
| 148 |
// defaults to 0, indicating that there is no free tier for this service. |
| 149 |
// |
| 150 |
// Used by group-based quotas only. |
| 151 |
int64 free_tier = 7; |
| 152 |
|
| 153 |
// Duration of this limit in textual notation. Must be "100s" or "1d". |
| 154 |
// |
| 155 |
// Used by group-based quotas only. |
| 156 |
string duration = 5; |
| 157 |
|
| 158 |
// The name of the metric this quota limit applies to. The quota limits with |
| 159 |
// the same metric will be checked together during runtime. The metric must be |
| 160 |
// defined within the service config. |
| 161 |
string metric = 8; |
| 162 |
|
| 163 |
// Specify the unit of the quota limit. It uses the same syntax as |
| 164 |
// [MetricDescriptor.unit][google.api.MetricDescriptor.unit]. The supported |
| 165 |
// unit kinds are determined by the quota backend system. |
| 166 |
// |
| 167 |
// Here are some examples: |
| 168 |
// * "1/min/{project}" for quota per minute per project. |
| 169 |
// |
| 170 |
// Note: the order of unit components is insignificant. |
| 171 |
// The "1" at the beginning is required to follow the metric unit syntax. |
| 172 |
string unit = 9; |
| 173 |
|
| 174 |
// Tiered limit values. You must specify this as a key:value pair, with an |
| 175 |
// integer value that is the maximum number of requests allowed for the |
| 176 |
// specified unit. Currently only STANDARD is supported. |
| 177 |
map<string, int64> values = 10; |
| 178 |
|
| 179 |
// User-visible display name for this limit. |
| 180 |
// Optional. If not set, the UI will provide a default display name based on |
| 181 |
// the quota configuration. This field can be used to override the default |
| 182 |
// display name generated from the configuration. |
| 183 |
string display_name = 12; |
| 184 |
} |