quota.proto 7.2 KB

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