Skip to content

Commit

Permalink
chore: clean up alert policies older than 1 hour in snippets test (#170)
Browse files Browse the repository at this point in the history
As a next step in troubleshooting the failure from #149, I'd like to clean up the existing alert policies in the test environment before running tests.
  • Loading branch information
parthea authored and dandhlee committed Nov 9, 2022
1 parent fe0dfe7 commit a828bee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions monitoring/snippets/v3/alerts-client/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import print_function

from datetime import datetime
import random
import string
import time
Expand Down Expand Up @@ -62,6 +63,17 @@ def __init__(self):
monitoring_v3.NotificationChannelServiceClient()
)

# delete all existing policies older than 1 hour prior to testing
for policy in self.alert_policy_client.list_alert_policies(name=self.project_name):
seconds_since_creation = datetime.timestamp(datetime.utcnow())-datetime.timestamp(policy.creation_record.mutate_time)
if seconds_since_creation > 3600:
try:
self.alert_policy_client.delete_alert_policy(
name=policy.name
)
except NotFound:
print("Ignored NotFound when deleting a policy.")

def __enter__(self):
@retry(
wait_exponential_multiplier=1000,
Expand Down

0 comments on commit a828bee

Please sign in to comment.