Skip to content

Commit 978b014

Browse files
authored
Merge branch 'master' into spanner-create-instance
2 parents 85f1b9c + 51a66f9 commit 978b014

File tree

30 files changed

+61
-2569
lines changed

30 files changed

+61
-2569
lines changed

appengine/flexible/scipy/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Flask==1.1.2
22
gunicorn==20.0.4
33
imageio==2.8.0
44
numpy==1.19.0
5-
pillow==7.1.2
5+
pillow==7.2.0
66
scipy==1.5.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
PyMySQL==0.9.3
2-
Django==1.11.29 # needs to stay under 2.0.0 for Python 2 support
2+
Django==1.11.29; python_version < '3.0' # needs to stay under 2.0.0 for Python 2 support
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Django==3.0.7
1+
Django==3.0.8
22
PyMySQL==0.9.3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Django==3.0.7
1+
Django==3.0.8
22
PyMySQL==0.9.3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-bigquery-datatransfer==1.0.0
1+
google-cloud-bigquery-datatransfer==1.1.0

datastore/schedule-export/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@
33
import os
44

55
from googleapiclient.discovery import build
6+
from googleapiclient.discovery_cache.base import Cache
67

7-
datastore = build('datastore', 'v1')
8+
9+
class MemoryCache(Cache):
10+
_CACHE = {}
11+
12+
def get(self, url):
13+
return MemoryCache._CACHE.get(url)
14+
15+
def set(self, url, content):
16+
MemoryCache._CACHE[url] = content
17+
18+
19+
# The default cache (file_cache) is unavailable when using oauth2client >= 4.0.0 or google-auth,
20+
# and it will log worrisome messages unless given another interface to use.
21+
datastore = build('datastore', 'v1', cache=MemoryCache())
822
project_id = os.environ.get('GCP_PROJECT')
923

1024

functions/billing/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def stop_billing(data, context):
7575
print(f'No action necessary. (Current cost: {cost_amount})')
7676
return
7777

78+
if PROJECT_ID is None:
79+
print('No project specified with environment variable')
80+
return
81+
7882
billing = discovery.build(
7983
'cloudbilling',
8084
'v1',
@@ -83,8 +87,10 @@ def stop_billing(data, context):
8387

8488
projects = billing.projects()
8589

86-
if __is_billing_enabled(PROJECT_NAME, projects):
87-
print(__disable_billing_for_project(PROJECT_NAME, projects))
90+
billing_enabled = __is_billing_enabled(PROJECT_NAME, projects)
91+
92+
if billing_enabled:
93+
__disable_billing_for_project(PROJECT_NAME, projects)
8894
else:
8995
print('Billing already disabled')
9096

@@ -95,19 +101,25 @@ def __is_billing_enabled(project_name, projects):
95101
@param {string} project_name Name of project to check if billing is enabled
96102
@return {bool} Whether project has billing enabled or not
97103
"""
98-
res = projects.getBillingInfo(name=project_name).execute()
99-
return res['billingEnabled']
104+
try:
105+
res = projects.getBillingInfo(name=project_name).execute()
106+
return res['billingEnabled']
107+
except Exception:
108+
print('Unable to determine if billing is enabled on specified project, assuming billing is enabled')
109+
return True
100110

101111

102112
def __disable_billing_for_project(project_name, projects):
103113
"""
104114
Disable billing for a project by removing its billing account
105115
@param {string} project_name Name of project disable billing on
106-
@return {string} Text containing response from disabling billing
107116
"""
108117
body = {'billingAccountName': ''} # Disable billing
109-
res = projects.updateBillingInfo(name=project_name, body=body).execute()
110-
print(f'Billing disabled: {json.dumps(res)}')
118+
try:
119+
res = projects.updateBillingInfo(name=project_name, body=body).execute()
120+
print(f'Billing disabled: {json.dumps(res)}')
121+
except Exception:
122+
print('Failed to disable billing, possibly check permissions')
111123
# [END functions_billing_stop]
112124

113125

functions/slack/main_test.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def test_verify_web_hook_valid_request(self):
5858
def test_format_slack_message(self):
5959
message = main.format_slack_message('lion', example_response)
6060

61-
assert 'lion' in message['text'].lower()
62-
assert 'lion' in message['attachments'][0]['title'].lower()
61+
# Just make sure there's a result.
62+
assert 'title' in message['attachments'][0]
6363
assert message['attachments'][0]['color'] == '#3367d6'
6464

6565
def test_make_search_request(self):
@@ -68,9 +68,8 @@ def test_make_search_request(self):
6868
search = entities.search.return_value
6969
search.execute.return_value = example_response
7070
message = main.make_search_request('lion')
71-
72-
assert 'lion' in message['text'].lower()
73-
assert 'lion' in message['attachments'][0]['title'].lower()
71+
# Just make sure there's a result.
72+
assert 'title' in message['attachments'][0]
7473
assert message['attachments'][0]['color'] == '#3367d6'
7574

7675
def test_kg_search(self):

monitoring/api/v3/alerts-client/snippets_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020

2121
from google.api_core.exceptions import Aborted
22+
from google.api_core.exceptions import DeadlineExceeded
2223
from google.api_core.exceptions import NotFound
2324
from google.api_core.exceptions import ServiceUnavailable
2425
from google.cloud import monitoring_v3
@@ -38,12 +39,13 @@ def random_name(length):
3839
[random.choice(string.ascii_lowercase) for i in range(length)])
3940

4041

41-
def retry_if_aborted(exception):
42-
return isinstance(exception, (Aborted, ServiceUnavailable))
42+
def retry_on_exceptions(exception):
43+
return isinstance(
44+
exception, (Aborted, ServiceUnavailable, DeadlineExceeded))
4345

4446

4547
def delay_on_aborted(err, *args):
46-
if retry_if_aborted(err[1]):
48+
if retry_on_exceptions(err[1]):
4749
# add randomness for avoiding continuous conflict
4850
time.sleep(5 + (random.randint(0, 9) * 0.1))
4951
return True
@@ -64,7 +66,8 @@ def __init__(self):
6466

6567
def __enter__(self):
6668
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
67-
stop_max_attempt_number=10, retry_on_exception=retry_if_aborted)
69+
stop_max_attempt_number=10,
70+
retry_on_exception=retry_on_exceptions)
6871
def setup():
6972
# Create a policy.
7073
policy = monitoring_v3.types.alert_pb2.AlertPolicy()
@@ -89,7 +92,8 @@ def setup():
8992
def __exit__(self, type, value, traceback):
9093
# Delete the policy and channel we created.
9194
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
92-
stop_max_attempt_number=10, retry_on_exception=retry_if_aborted)
95+
stop_max_attempt_number=10,
96+
retry_on_exception=retry_on_exceptions)
9397
def teardown():
9498
try:
9599
self.alert_policy_client.delete_alert_policy(

opencensus/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
grpcio==1.30.0
2-
opencensus-ext-stackdriver==0.7.2
2+
opencensus-ext-stackdriver==0.7.3
33
opencensus==0.7.10

0 commit comments

Comments
 (0)