xref: /aosp_15_r20/external/googleapis/google/cloud/billing/budgets/v1beta1/budget_model.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 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.cloud.billing.budgets.v1beta1;
18
19import "google/api/field_behavior.proto";
20import "google/api/resource.proto";
21import "google/protobuf/struct.proto";
22import "google/type/date.proto";
23import "google/type/money.proto";
24
25option go_package = "cloud.google.com/go/billing/budgets/apiv1beta1/budgetspb;budgetspb";
26option java_multiple_files = true;
27option java_package = "com.google.cloud.billing.budgets.v1beta1";
28
29// A budget is a plan that describes what you expect to spend on Cloud
30// projects, plus the rules to execute as spend is tracked against that plan,
31// (for example, send an alert when 90% of the target spend is met).
32// The budget time period is configurable, with options such as month (default),
33// quarter, year, or custom time period.
34message Budget {
35  option (google.api.resource) = {
36    type: "billingbudgets.googleapis.com/Budget"
37    pattern: "billingAccounts/{billing_account}/budgets/{budget}"
38  };
39
40  // Output only. Resource name of the budget.
41  // The resource name implies the scope of a budget. Values are of the form
42  // `billingAccounts/{billingAccountId}/budgets/{budgetId}`.
43  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
44
45  // User data for display name in UI.
46  // Validation: <= 60 chars.
47  string display_name = 2;
48
49  // Optional. Filters that define which resources are used to compute the
50  // actual spend against the budget amount, such as projects, services, and the
51  // budget's time period, as well as other filters.
52  Filter budget_filter = 3 [(google.api.field_behavior) = OPTIONAL];
53
54  // Required. Budgeted amount.
55  BudgetAmount amount = 4 [(google.api.field_behavior) = REQUIRED];
56
57  // Optional. Rules that trigger alerts (notifications of thresholds
58  // being crossed) when spend exceeds the specified percentages of the budget.
59  //
60  // Optional for `pubsubTopic` notifications.
61  //
62  // Required if using email notifications.
63  repeated ThresholdRule threshold_rules = 5
64      [(google.api.field_behavior) = OPTIONAL];
65
66  // Optional. Rules to apply to notifications sent based on budget spend and
67  // thresholds.
68  AllUpdatesRule all_updates_rule = 6 [(google.api.field_behavior) = OPTIONAL];
69
70  // Optional. Etag to validate that the object is unchanged for a
71  // read-modify-write operation.
72  // An empty etag will cause an update to overwrite other changes.
73  string etag = 7 [(google.api.field_behavior) = OPTIONAL];
74}
75
76// The budgeted amount for each usage period.
77message BudgetAmount {
78  // Specification for what amount to use as the budget.
79  oneof budget_amount {
80    // A specified amount to use as the budget.
81    // `currency_code` is optional. If specified when creating a budget, it must
82    // match the currency of the billing account. If specified when updating a
83    // budget, it must match the currency_code of the existing budget.
84    // The `currency_code` is provided on output.
85    google.type.Money specified_amount = 1;
86
87    // Use the last period's actual spend as the budget for the present period.
88    // LastPeriodAmount can only be set when the budget's time period is a
89    // [Filter.calendar_period][google.cloud.billing.budgets.v1beta1.Filter.calendar_period].
90    // It cannot be set in combination with
91    // [Filter.custom_period][google.cloud.billing.budgets.v1beta1.Filter.custom_period].
92    LastPeriodAmount last_period_amount = 2;
93  }
94}
95
96// Describes a budget amount targeted to the last
97// [Filter.calendar_period][google.cloud.billing.budgets.v1beta1.Filter.calendar_period]
98// spend. At this time, the amount is automatically 100% of the last calendar
99// period's spend; that is, there are no other options yet.
100// Future configuration options will be described here (for example, configuring
101// a percentage of last period's spend).
102// LastPeriodAmount cannot be set for a budget configured with
103// a
104// [Filter.custom_period][google.cloud.billing.budgets.v1beta1.Filter.custom_period].
105message LastPeriodAmount {}
106
107// ThresholdRule contains the definition of a threshold. Threshold rules define
108// the triggering events used to generate a budget notification email. When a
109// threshold is crossed (spend exceeds the specified percentages of the
110// budget), budget alert emails are sent to the email recipients you specify
111// in the
112// [NotificationsRule](#notificationsrule).
113//
114// Threshold rules also affect the fields included in the
115// [JSON data
116// object](https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format)
117// sent to a Pub/Sub topic.
118//
119// Threshold rules are _required_ if using email notifications.
120//
121// Threshold rules are _optional_ if only setting a
122// [`pubsubTopic` NotificationsRule](#NotificationsRule),
123// unless you want your JSON data object to include data about the thresholds
124// you set.
125//
126// For more information, see
127// [set budget threshold rules and
128// actions](https://cloud.google.com/billing/docs/how-to/budgets#budget-actions).
129message ThresholdRule {
130  // The type of basis used to determine if spend has passed the threshold.
131  enum Basis {
132    // Unspecified threshold basis.
133    BASIS_UNSPECIFIED = 0;
134
135    // Use current spend as the basis for comparison against the threshold.
136    CURRENT_SPEND = 1;
137
138    // Use forecasted spend for the period as the basis for comparison against
139    // the threshold.
140    // FORECASTED_SPEND can only be set when the budget's time period is a
141    // [Filter.calendar_period][google.cloud.billing.budgets.v1beta1.Filter.calendar_period].
142    // It cannot be set in combination with
143    // [Filter.custom_period][google.cloud.billing.budgets.v1beta1.Filter.custom_period].
144    FORECASTED_SPEND = 2;
145  }
146
147  // Required. Send an alert when this threshold is exceeded.
148  // This is a 1.0-based percentage, so 0.5 = 50%.
149  // Validation: non-negative number.
150  double threshold_percent = 1 [(google.api.field_behavior) = REQUIRED];
151
152  // Optional. The type of basis used to determine if spend has passed the
153  // threshold. Behavior defaults to CURRENT_SPEND if not set.
154  Basis spend_basis = 2 [(google.api.field_behavior) = OPTIONAL];
155}
156
157// AllUpdatesRule defines notifications that are sent based on budget spend
158// and thresholds.
159message AllUpdatesRule {
160  // Optional. The name of the Pub/Sub topic where budget related messages will
161  // be published, in the form `projects/{project_id}/topics/{topic_id}`.
162  // Updates are sent at regular intervals to the topic. The topic needs to be
163  // created before the budget is created; see
164  // https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications
165  // for more details.
166  // Caller is expected to have
167  // `pubsub.topics.setIamPolicy` permission on the topic when it's set for a
168  // budget, otherwise, the API call will fail with PERMISSION_DENIED. See
169  // https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#permissions_required_for_this_task
170  // for more details on Pub/Sub roles and permissions.
171  string pubsub_topic = 1 [(google.api.field_behavior) = OPTIONAL];
172
173  // Optional. Required when
174  // [AllUpdatesRule.pubsub_topic][google.cloud.billing.budgets.v1beta1.AllUpdatesRule.pubsub_topic]
175  // is set. The schema version of the notification sent to
176  // [AllUpdatesRule.pubsub_topic][google.cloud.billing.budgets.v1beta1.AllUpdatesRule.pubsub_topic].
177  // Only "1.0" is accepted. It represents the JSON schema as defined in
178  // https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format.
179  string schema_version = 2 [(google.api.field_behavior) = OPTIONAL];
180
181  // Optional. Targets to send notifications to when a threshold is exceeded.
182  // This is in addition to default recipients who have billing account IAM
183  // roles. The value is the full REST resource name of a monitoring
184  // notification channel with the form
185  // `projects/{project_id}/notificationChannels/{channel_id}`. A maximum of 5
186  // channels are allowed. See
187  // https://cloud.google.com/billing/docs/how-to/budgets-notification-recipients
188  // for more details.
189  repeated string monitoring_notification_channels = 3
190      [(google.api.field_behavior) = OPTIONAL];
191
192  // Optional. When set to true, disables default notifications sent when a
193  // threshold is exceeded. Default notifications are sent to those with Billing
194  // Account Administrator and Billing Account User IAM roles for the target
195  // account.
196  bool disable_default_iam_recipients = 4
197      [(google.api.field_behavior) = OPTIONAL];
198
199  // Optional. When set to true, and when the budget has a single project
200  // configured, notifications will be sent to project level recipients of that
201  // project. This field will be ignored if the budget has multiple or no
202  // project configured.
203  //
204  // Currently, project level recipients are the users with `Owner` role on a
205  // cloud project.
206  bool enable_project_level_recipients = 5
207      [(google.api.field_behavior) = OPTIONAL];
208}
209
210// A filter for a budget, limiting the scope of the cost to calculate.
211message Filter {
212  // Specifies how credits are applied when determining the spend for
213  // threshold calculations. Budgets track the total cost minus any applicable
214  // selected credits.
215  // [See the documentation for a list of credit
216  // types](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type).
217  enum CreditTypesTreatment {
218    CREDIT_TYPES_TREATMENT_UNSPECIFIED = 0;
219
220    // All types of credit are subtracted from the gross cost to determine the
221    // spend for threshold calculations.
222    INCLUDE_ALL_CREDITS = 1;
223
224    // All types of credit are added to the net cost to determine the spend for
225    // threshold calculations.
226    EXCLUDE_ALL_CREDITS = 2;
227
228    // [Credit
229    // types](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type)
230    // specified in the credit_types field are subtracted from the
231    // gross cost to determine the spend for threshold calculations.
232    INCLUDE_SPECIFIED_CREDITS = 3;
233  }
234
235  // Optional. A set of projects of the form `projects/{project}`,
236  // specifying that usage from only this set of projects should be
237  // included in the budget. If omitted, the report will include all usage for
238  // the billing account, regardless of which project the usage occurred on.
239  repeated string projects = 1 [(google.api.field_behavior) = OPTIONAL];
240
241  // Optional. A set of folder and organization names of the form
242  // `folders/{folderId}` or `organizations/{organizationId}`, specifying that
243  // usage from only this set of folders and organizations should be included in
244  // the budget. If omitted, the budget includes all usage that the billing
245  // account pays for. If the folder or organization contains projects that are
246  // paid for by a different Cloud Billing account, the budget *doesn't* apply
247  // to those projects.
248  repeated string resource_ancestors = 2
249      [(google.api.field_behavior) = OPTIONAL];
250
251  // Optional. If
252  // [Filter.credit_types_treatment][google.cloud.billing.budgets.v1beta1.Filter.credit_types_treatment]
253  // is INCLUDE_SPECIFIED_CREDITS, this is a list of credit types to be
254  // subtracted from gross cost to determine the spend for threshold
255  // calculations. See [a list of acceptable credit type
256  // values](https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables#credits-type).
257  //
258  // If
259  // [Filter.credit_types_treatment][google.cloud.billing.budgets.v1beta1.Filter.credit_types_treatment]
260  // is **not** INCLUDE_SPECIFIED_CREDITS, this field must be empty.
261  repeated string credit_types = 7 [(google.api.field_behavior) = OPTIONAL];
262
263  // Optional. If not set, default behavior is `INCLUDE_ALL_CREDITS`.
264  CreditTypesTreatment credit_types_treatment = 4
265      [(google.api.field_behavior) = OPTIONAL];
266
267  // Optional. A set of services of the form `services/{service_id}`,
268  // specifying that usage from only this set of services should be
269  // included in the budget. If omitted, the report will include usage for
270  // all the services.
271  // The service names are available through the Catalog API:
272  // https://cloud.google.com/billing/v1/how-tos/catalog-api.
273  repeated string services = 3 [(google.api.field_behavior) = OPTIONAL];
274
275  // Optional. A set of subaccounts of the form `billingAccounts/{account_id}`,
276  // specifying that usage from only this set of subaccounts should be included
277  // in the budget. If a subaccount is set to the name of the parent account,
278  // usage from the parent account will be included. If omitted, the
279  // report will include usage from the parent account and all
280  // subaccounts, if they exist.
281  repeated string subaccounts = 5 [(google.api.field_behavior) = OPTIONAL];
282
283  // Optional. A single label and value pair specifying that usage from only
284  // this set of labeled resources should be included in the budget. If omitted,
285  // the report will include all labeled and unlabeled usage.
286  //
287  // An object containing a single `"key": value` pair. Example: `{ "name":
288  // "wrench" }`.
289  //
290  //  _Currently, multiple entries or multiple values per entry are not
291  //  allowed._
292  map<string, google.protobuf.ListValue> labels = 6
293      [(google.api.field_behavior) = OPTIONAL];
294
295  // Multiple options to choose the budget's time period, specifying that only
296  // usage that occurs during this time period should be included in the budget.
297  // If not set, the <code>usage_period</code> defaults to CalendarPeriod.MONTH.
298  oneof usage_period {
299    // Optional. Specifies to track usage for recurring calendar period.
300    // For example, assume that CalendarPeriod.QUARTER is set. The budget will
301    // track usage from April 1 to June 30, when the current calendar month is
302    // April, May, June. After that, it will track usage from July 1 to
303    // September 30 when the current calendar month is July, August, September,
304    // so on.
305    CalendarPeriod calendar_period = 8 [(google.api.field_behavior) = OPTIONAL];
306
307    // Optional. Specifies to track usage from any start date (required) to any
308    // end date (optional). This time period is static, it does not recur.
309    CustomPeriod custom_period = 9 [(google.api.field_behavior) = OPTIONAL];
310  }
311}
312
313// All date times begin at 12 AM US and Canadian Pacific Time (UTC-8).
314message CustomPeriod {
315  // Required. The start date must be after January 1, 2017.
316  google.type.Date start_date = 1 [(google.api.field_behavior) = REQUIRED];
317
318  // Optional. The end date of the time period. Budgets with elapsed end date
319  // won't be processed. If unset, specifies to track all usage incurred since
320  // the start_date.
321  google.type.Date end_date = 2 [(google.api.field_behavior) = OPTIONAL];
322}
323
324// A `CalendarPeriod` represents the abstract concept of a time period that
325// has a canonical start. Grammatically, "the start of the current
326// `CalendarPeriod`". All calendar times begin at 12 AM US and Canadian
327// Pacific Time (UTC-8).
328enum CalendarPeriod {
329  // Calendar period is unset. This is the default if the budget is for a
330  // custom time period (CustomPeriod).
331  CALENDAR_PERIOD_UNSPECIFIED = 0;
332
333  // A month. Month starts on the first day of each month, such as January 1,
334  // February 1, March 1, and so on.
335  MONTH = 1;
336
337  // A quarter. Quarters start on dates January 1, April 1, July 1, and October
338  // 1 of each year.
339  QUARTER = 2;
340
341  // A year. Year starts on January 1.
342  YEAR = 3;
343}
344