notify-243 remove statsd

This commit is contained in:
Kenneth Kehl
2023-04-25 07:50:56 -07:00
parent 625f6e3f6b
commit 001954538e
19 changed files with 178 additions and 282 deletions

View File

@@ -57,7 +57,7 @@ class AwsSesClient(EmailClient):
Amazon SES email client.
'''
def init_app(self, statsd_client, *args, **kwargs):
def init_app(self, *args, **kwargs):
self._client = client(
'ses',
region_name=cloud_config.ses_region,
@@ -65,7 +65,6 @@ class AwsSesClient(EmailClient):
aws_secret_access_key=cloud_config.ses_secret_key
)
super(AwsSesClient, self).__init__(*args, **kwargs)
self.statsd_client = statsd_client
@property
def name(self):
@@ -110,7 +109,6 @@ class AwsSesClient(EmailClient):
ReplyToAddresses=[punycode_encode_email(addr) for addr in reply_to_addresses]
)
except botocore.exceptions.ClientError as e:
self.statsd_client.incr("clients.ses.error")
# http://docs.aws.amazon.com/ses/latest/DeveloperGuide/api-error-codes.html
if e.response['Error']['Code'] == 'InvalidParameterValue':
@@ -121,16 +119,12 @@ class AwsSesClient(EmailClient):
):
raise AwsSesClientThrottlingSendRateException(str(e))
else:
self.statsd_client.incr("clients.ses.error")
raise AwsSesClientException(str(e))
except Exception as e:
self.statsd_client.incr("clients.ses.error")
raise AwsSesClientException(str(e))
else:
elapsed_time = monotonic() - start_time
current_app.logger.info("AWS SES request finished in {}".format(elapsed_time))
self.statsd_client.timing("clients.ses.request-time", elapsed_time)
self.statsd_client.incr("clients.ses.success")
return response['MessageId']

View File

@@ -12,8 +12,7 @@ class AwsSesStubClientException(EmailClientException):
class AwsSesStubClient(EmailClient):
def init_app(self, statsd_client, stub_url):
self.statsd_client = statsd_client
def init_app(self, stub_url):
self.url = stub_url
@property
@@ -39,11 +38,8 @@ class AwsSesStubClient(EmailClient):
response_json = json.loads(response.text)
except Exception as e:
self.statsd_client.incr("clients.ses_stub.error")
raise AwsSesStubClientException(str(e))
else:
elapsed_time = monotonic() - start_time
current_app.logger.info("AWS SES stub request finished in {}".format(elapsed_time))
self.statsd_client.timing("clients.ses_stub.request-time", elapsed_time)
self.statsd_client.incr("clients.ses_stub.success")
return response_json['MessageId']

View File

@@ -14,7 +14,7 @@ class AwsSnsClient(SmsClient):
AwsSns sms client
"""
def init_app(self, current_app, statsd_client, *args, **kwargs):
def init_app(self, current_app, *args, **kwargs):
self._client = client(
"sns",
region_name=cloud_config.sns_region,
@@ -23,7 +23,6 @@ class AwsSnsClient(SmsClient):
)
super(SmsClient, self).__init__(*args, **kwargs)
self.current_app = current_app
self.statsd_client = statsd_client
self._valid_sender_regex = re.compile(r"^\+?\d{5,14}$")
@property
@@ -67,19 +66,14 @@ class AwsSnsClient(SmsClient):
start_time = monotonic()
response = self._client.publish(PhoneNumber=to, Message=content, MessageAttributes=attributes)
except botocore.exceptions.ClientError as e:
self.statsd_client.incr("clients.sns.error")
raise str(e)
except Exception as e:
self.statsd_client.incr("clients.sns.error")
raise str(e)
finally:
elapsed_time = monotonic() - start_time
self.current_app.logger.info("AWS SNS request finished in {}".format(elapsed_time))
self.statsd_client.timing("clients.sns.request-time", elapsed_time)
self.statsd_client.incr("clients.sns.success")
return response["MessageId"]
if not matched:
self.statsd_client.incr("clients.sns.error")
self.current_app.logger.error("No valid numbers found in {}".format(to))
raise ValueError("No valid numbers found for SMS delivery")