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