Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(monitoring): also retry upon DeadlineExceeded #4202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions 14 monitoring/api/v3/alerts-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time

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


def retry_if_aborted(exception):
return isinstance(exception, (Aborted, ServiceUnavailable))
def retry_on_exceptions(exception):
return isinstance(
exception, (Aborted, ServiceUnavailable, DeadlineExceeded))


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

def __enter__(self):
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
stop_max_attempt_number=10, retry_on_exception=retry_if_aborted)
stop_max_attempt_number=10,
retry_on_exception=retry_on_exceptions)
def setup():
# Create a policy.
policy = monitoring_v3.types.alert_pb2.AlertPolicy()
Expand All @@ -89,7 +92,8 @@ def setup():
def __exit__(self, type, value, traceback):
# Delete the policy and channel we created.
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
stop_max_attempt_number=10, retry_on_exception=retry_if_aborted)
stop_max_attempt_number=10,
retry_on_exception=retry_on_exceptions)
def teardown():
try:
self.alert_policy_client.delete_alert_policy(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.