Skip to content

Commit 73377e6

Browse files
feat: Add resource_ancestors field to support filtering by folders & organizations (#11360)
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent de97d0d commit 73377e6

File tree

28 files changed

+2780
-56
lines changed

28 files changed

+2780
-56
lines changed

packages/google-cloud-billing-budgets/google/cloud/billing/budgets/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.10.0" # {x-release-please-version}
16+
__version__ = "0.1.0" # {x-release-please-version}

packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.10.0" # {x-release-please-version}
16+
__version__ = "0.1.0" # {x-release-please-version}

packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1/types/budget_model.py

Lines changed: 113 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class CalendarPeriod(proto.Enum):
4545
4646
Values:
4747
CALENDAR_PERIOD_UNSPECIFIED (0):
48-
No description available.
48+
Calendar period is unset. This is the default
49+
if the budget is for a custom time period
50+
(CustomPeriod).
4951
MONTH (1):
5052
A month. Month starts on the first day of
5153
each month, such as January 1, February 1, March
@@ -87,17 +89,20 @@ class Budget(proto.Message):
8789
amount (google.cloud.billing.budgets_v1.types.BudgetAmount):
8890
Required. Budgeted amount.
8991
threshold_rules (MutableSequence[google.cloud.billing.budgets_v1.types.ThresholdRule]):
90-
Optional. Rules that trigger alerts
91-
(notifications of thresholds being crossed) when
92-
spend exceeds the specified percentages of the
93-
budget.
92+
Optional. Rules that trigger alerts (notifications of
93+
thresholds being crossed) when spend exceeds the specified
94+
percentages of the budget.
95+
96+
Optional for ``pubsubTopic`` notifications.
97+
98+
Required if using email notifications.
9499
notifications_rule (google.cloud.billing.budgets_v1.types.NotificationsRule):
95100
Optional. Rules to apply to notifications
96101
sent based on budget spend and thresholds.
97102
etag (str):
98103
Optional. Etag to validate that the object is
99104
unchanged for a read-modify-write operation.
100-
An empty etag will cause an update to overwrite
105+
An empty etag causes an update to overwrite
101106
other changes.
102107
"""
103108

@@ -185,22 +190,32 @@ class LastPeriodAmount(proto.Message):
185190
[Filter.calendar_period][google.cloud.billing.budgets.v1.Filter.calendar_period]
186191
spend. At this time, the amount is automatically 100% of the last
187192
calendar period's spend; that is, there are no other options yet.
188-
Future configuration options will be described here (for example,
189-
configuring a percentage of last period's spend). LastPeriodAmount
190-
cannot be set for a budget configured with a
193+
LastPeriodAmount cannot be set for a budget configured with a
191194
[Filter.custom_period][google.cloud.billing.budgets.v1.Filter.custom_period].
192195
193196
"""
194197

195198

196199
class ThresholdRule(proto.Message):
197-
r"""ThresholdRule contains a definition of a threshold which triggers an
198-
alert (a notification of a threshold being crossed) to be sent when
199-
spend goes above the specified amount. Alerts are automatically
200-
e-mailed to users with the Billing Account Administrator role or the
201-
Billing Account User role. The thresholds here have no effect on
202-
notifications sent to anything configured under
203-
``Budget.all_updates_rule``.
200+
r"""ThresholdRule contains the definition of a threshold. Threshold
201+
rules define the triggering events used to generate a budget
202+
notification email. When a threshold is crossed (spend exceeds the
203+
specified percentages of the budget), budget alert emails are sent
204+
to the email recipients you specify in the
205+
`NotificationsRule <#notificationsrule>`__.
206+
207+
Threshold rules also affect the fields included in the `JSON data
208+
object <https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format>`__
209+
sent to a Pub/Sub topic.
210+
211+
Threshold rules are *required* if using email notifications.
212+
213+
Threshold rules are *optional* if only setting a ```pubsubTopic``
214+
NotificationsRule <#NotificationsRule>`__, unless you want your JSON
215+
data object to include data about the thresholds you set.
216+
217+
For more information, see `set budget threshold rules and
218+
actions <https://cloud.google.com/billing/docs/how-to/budgets#budget-actions>`__.
204219
205220
Attributes:
206221
threshold_percent (float):
@@ -252,18 +267,36 @@ class NotificationsRule(proto.Message):
252267
253268
Attributes:
254269
pubsub_topic (str):
255-
Optional. The name of the Pub/Sub topic where budget related
256-
messages will be published, in the form
270+
Optional. The name of the Pub/Sub topic where budget-related
271+
messages are published, in the form
257272
``projects/{project_id}/topics/{topic_id}``. Updates are
258-
sent at regular intervals to the topic. The topic needs to
259-
be created before the budget is created; see
260-
https://cloud.google.com/billing/docs/how-to/budgets#manage-notifications
261-
for more details. Caller is expected to have
262-
``pubsub.topics.setIamPolicy`` permission on the topic when
263-
it's set for a budget, otherwise, the API call will fail
264-
with PERMISSION_DENIED. See
265-
https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications
266-
for more details on Pub/Sub roles and permissions.
273+
sent to the topic at regular intervals; the timing of the
274+
updates is not dependent on the `threshold
275+
rules <#thresholdrule>`__ you've set.
276+
277+
Note that if you want your `Pub/Sub JSON
278+
object <https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format>`__
279+
to contain data for ``alertThresholdExceeded``, you need at
280+
least one `alert threshold rule <#thresholdrule>`__. When
281+
you set threshold rules, you must also enable at least one
282+
of the email notification options, either using the default
283+
IAM recipients or Cloud Monitoring email notification
284+
channels.
285+
286+
To use Pub/Sub topics with budgets, you must do the
287+
following:
288+
289+
1. Create the Pub/Sub topic before connecting it to your
290+
budget. For guidance, see `Manage programmatic budget
291+
alert
292+
notifications <https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications>`__.
293+
294+
2. Grant the API caller the ``pubsub.topics.setIamPolicy``
295+
permission on the Pub/Sub topic. If not set, the API call
296+
fails with PERMISSION_DENIED. For additional details on
297+
Pub/Sub roles and permissions, see `Permissions required
298+
for this
299+
task <https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#permissions_required_for_this_task>`__.
267300
schema_version (str):
268301
Optional. Required when
269302
[NotificationsRule.pubsub_topic][google.cloud.billing.budgets.v1.NotificationsRule.pubsub_topic]
@@ -273,15 +306,29 @@ class NotificationsRule(proto.Message):
273306
defined in
274307
https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications#notification_format.
275308
monitoring_notification_channels (MutableSequence[str]):
276-
Optional. Targets to send notifications to when a threshold
277-
is exceeded. This is in addition to default recipients who
278-
have billing account IAM roles. The value is the full REST
279-
resource name of a monitoring notification channel with the
280-
form
309+
Optional. Email targets to send notifications to when a
310+
threshold is exceeded. This is in addition to the
311+
``DefaultIamRecipients`` who receive alert emails based on
312+
their billing account IAM role. The value is the full REST
313+
resource name of a Cloud Monitoring email notification
314+
channel with the form
281315
``projects/{project_id}/notificationChannels/{channel_id}``.
282-
A maximum of 5 channels are allowed. See
283-
https://cloud.google.com/billing/docs/how-to/budgets-notification-recipients
284-
for more details.
316+
A maximum of 5 email notifications are allowed.
317+
318+
To customize budget alert email recipients with monitoring
319+
notification channels, you *must create the monitoring
320+
notification channels before you link them to a budget*. For
321+
guidance on setting up notification channels to use with
322+
budgets, see `Customize budget alert email
323+
recipients <https://cloud.google.com/billing/docs/how-to/budgets-notification-recipients>`__.
324+
325+
For Cloud Billing budget alerts, you *must use email
326+
notification channels*. The other types of notification
327+
channels are *not* supported, such as Slack, SMS, or
328+
PagerDuty. If you want to `send budget notifications to
329+
Slack <https://cloud.google.com/billing/docs/how-to/notify#send_notifications_to_slack>`__,
330+
use a pubsubTopic and configure `programmatic
331+
notifications <https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications>`__.
285332
disable_default_iam_recipients (bool):
286333
Optional. When set to true, disables default
287334
notifications sent when a threshold is exceeded.
@@ -324,9 +371,16 @@ class Filter(proto.Message):
324371
Optional. A set of projects of the form
325372
``projects/{project}``, specifying that usage from only this
326373
set of projects should be included in the budget. If
327-
omitted, the report will include all usage for the billing
374+
omitted, the report includes all usage for the billing
328375
account, regardless of which project the usage occurred on.
329-
Only zero or one project can be specified currently.
376+
resource_ancestors (MutableSequence[str]):
377+
Optional. A set of folder and organization names of the form
378+
``folders/{folderId}`` or
379+
``organizations/{organizationId}``, specifying that usage
380+
from only this set of folders and organizations should be
381+
included in the budget. If omitted, the report includes all
382+
usage for all organizations, regardless of which
383+
organization the usage occurred on.
330384
credit_types (MutableSequence[str]):
331385
Optional. If
332386
[Filter.credit_types_treatment][google.cloud.billing.budgets.v1.Filter.credit_types_treatment]
@@ -347,32 +401,35 @@ class Filter(proto.Message):
347401
Optional. A set of services of the form
348402
``services/{service_id}``, specifying that usage from only
349403
this set of services should be included in the budget. If
350-
omitted, the report will include usage for all the services.
351-
The service names are available through the Catalog API:
404+
omitted, the report includes usage for all the services. The
405+
service names are available through the Catalog API:
352406
https://cloud.google.com/billing/v1/how-tos/catalog-api.
353407
subaccounts (MutableSequence[str]):
354408
Optional. A set of subaccounts of the form
355409
``billingAccounts/{account_id}``, specifying that usage from
356410
only this set of subaccounts should be included in the
357411
budget. If a subaccount is set to the name of the parent
358-
account, usage from the parent account will be included. If
359-
the field is omitted, the report will include usage from the
360-
parent account and all subaccounts, if they exist.
412+
account, usage from the parent account is included. If the
413+
field is omitted, the report includes usage from the parent
414+
account and all subaccounts, if they exist.
361415
labels (MutableMapping[str, google.protobuf.struct_pb2.ListValue]):
362-
Optional. A single label and value pair
363-
specifying that usage from only this set of
364-
labeled resources should be included in the
365-
budget. Currently, multiple entries or multiple
366-
values per entry are not allowed. If omitted,
367-
the report will include all labeled and
368-
unlabeled usage.
416+
Optional. A single label and value pair specifying that
417+
usage from only this set of labeled resources should be
418+
included in the budget. If omitted, the report includes all
419+
labeled and unlabeled usage.
420+
421+
An object containing a single ``"key": value`` pair.
422+
Example: ``{ "name": "wrench" }``.
423+
424+
*Currently, multiple entries or multiple values per entry
425+
are not allowed.*
369426
calendar_period (google.cloud.billing.budgets_v1.types.CalendarPeriod):
370427
Optional. Specifies to track usage for
371428
recurring calendar period. For example, assume
372429
that CalendarPeriod.QUARTER is set. The budget
373-
will track usage from April 1 to June 30, when
374-
the current calendar month is April, May, June.
375-
After that, it will track usage from July 1 to
430+
tracks usage from April 1 to June 30, when the
431+
current calendar month is April, May, June.
432+
After that, it tracks usage from July 1 to
376433
September 30 when the current calendar month is
377434
July, August, September, so on.
378435
@@ -420,6 +477,10 @@ class CreditTypesTreatment(proto.Enum):
420477
proto.STRING,
421478
number=1,
422479
)
480+
resource_ancestors: MutableSequence[str] = proto.RepeatedField(
481+
proto.STRING,
482+
number=2,
483+
)
423484
credit_types: MutableSequence[str] = proto.RepeatedField(
424485
proto.STRING,
425486
number=7,

packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "1.10.0" # {x-release-please-version}
16+
__version__ = "0.1.0" # {x-release-please-version}

packages/google-cloud-billing-budgets/google/cloud/billing/budgets_v1beta1/types/budget_model.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,14 @@ class Filter(proto.Message):
343343
set of projects should be included in the budget. If
344344
omitted, the report will include all usage for the billing
345345
account, regardless of which project the usage occurred on.
346-
Only zero or one project can be specified currently.
346+
resource_ancestors (MutableSequence[str]):
347+
Optional. A set of folder and organization names of the form
348+
``folders/{folderId}`` or
349+
``organizations/{organizationId}``, specifying that usage
350+
from only this set of folders and organizations should be
351+
included in the budget. If omitted, the report includes all
352+
usage for all organizations, regardless of which
353+
organization the usage occurred on.
347354
credit_types (MutableSequence[str]):
348355
Optional. If
349356
[Filter.credit_types_treatment][google.cloud.billing.budgets.v1beta1.Filter.credit_types_treatment]
@@ -440,6 +447,10 @@ class CreditTypesTreatment(proto.Enum):
440447
proto.STRING,
441448
number=1,
442449
)
450+
resource_ancestors: MutableSequence[str] = proto.RepeatedField(
451+
proto.STRING,
452+
number=2,
453+
)
443454
credit_types: MutableSequence[str] = proto.RepeatedField(
444455
proto.STRING,
445456
number=7,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for CreateBudget
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-billing-budgets
24+
25+
26+
# [START billingbudgets_v1_generated_BudgetService_CreateBudget_async]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud.billing import budgets_v1
35+
36+
37+
async def sample_create_budget():
38+
# Create a client
39+
client = budgets_v1.BudgetServiceAsyncClient()
40+
41+
# Initialize request argument(s)
42+
request = budgets_v1.CreateBudgetRequest(
43+
parent="parent_value",
44+
)
45+
46+
# Make the request
47+
response = await client.create_budget(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
# [END billingbudgets_v1_generated_BudgetService_CreateBudget_async]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Generated code. DO NOT EDIT!
17+
#
18+
# Snippet for CreateBudget
19+
# NOTE: This snippet has been automatically generated for illustrative purposes only.
20+
# It may require modifications to work in your environment.
21+
22+
# To install the latest published package dependency, execute the following:
23+
# python3 -m pip install google-cloud-billing-budgets
24+
25+
26+
# [START billingbudgets_v1_generated_BudgetService_CreateBudget_sync]
27+
# This snippet has been automatically generated and should be regarded as a
28+
# code template only.
29+
# It will require modifications to work:
30+
# - It may require correct/in-range values for request initialization.
31+
# - It may require specifying regional endpoints when creating the service
32+
# client as shown in:
33+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
34+
from google.cloud.billing import budgets_v1
35+
36+
37+
def sample_create_budget():
38+
# Create a client
39+
client = budgets_v1.BudgetServiceClient()
40+
41+
# Initialize request argument(s)
42+
request = budgets_v1.CreateBudgetRequest(
43+
parent="parent_value",
44+
)
45+
46+
# Make the request
47+
response = client.create_budget(request=request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
# [END billingbudgets_v1_generated_BudgetService_CreateBudget_sync]

0 commit comments

Comments
 (0)