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

@@ -23,7 +23,6 @@ from notifications_utils import logging, request_helper
from notifications_utils.celery import NotifyCelery
from notifications_utils.clients.encryption.encryption_client import Encryption
from notifications_utils.clients.redis.redis_client import RedisClient
from notifications_utils.clients.statsd.statsd_client import StatsdClient
from notifications_utils.clients.zendesk.zendesk_client import ZendeskClient
from sqlalchemy import event
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException
@@ -58,7 +57,6 @@ aws_ses_stub_client = AwsSesStubClient()
aws_sns_client = AwsSnsClient()
encryption = Encryption()
zendesk_client = ZendeskClient()
statsd_client = StatsdClient()
redis_store = RedisClient()
document_download_client = DocumentDownloadClient()
metrics = GDSMetrics()
@@ -91,13 +89,11 @@ def create_app(application):
migrate.init_app(application, db=db)
ma.init_app(application)
zendesk_client.init_app(application)
statsd_client.init_app(application)
logging.init_app(application)
aws_sns_client.init_app(application, statsd_client=statsd_client)
aws_sns_client.init_app(application)
aws_ses_client.init_app(statsd_client=statsd_client)
aws_ses_client.init_app()
aws_ses_stub_client.init_app(
statsd_client=statsd_client,
stub_url=application.config['SES_STUB_URL']
)
# If a stub url is provided for SES, then use the stub client rather than the real SES boto client

View File

@@ -4,7 +4,7 @@ from flask import current_app
from notifications_utils.timezones import convert_utc_to_local_timezone
from sqlalchemy.exc import SQLAlchemyError
from app import notify_celery, statsd_client
from app import notify_celery
from app.aws import s3
from app.celery.process_ses_receipts_tasks import check_and_queue_callback_task
from app.config import QueueNames
@@ -134,7 +134,6 @@ def timeout_notifications():
notifications = dao_timeout_notifications(cutoff_time)
for notification in notifications:
statsd_client.incr(f'timeout-sending.{notification.sent_by}')
check_and_queue_callback_task(notification)
current_app.logger.info(

View File

@@ -5,7 +5,7 @@ from celery.exceptions import Retry
from flask import current_app, json
from sqlalchemy.orm.exc import NoResultFound
from app import notify_celery, statsd_client
from app import notify_celery
from app.celery.service_callback_tasks import (
create_complaint_callback_data,
create_delivery_status_callback_data,
@@ -92,11 +92,6 @@ def process_ses_results(self, response):
"SES callback return status of {} for notification: {}".format(notification_status, notification.id)
)
statsd_client.incr("callback.ses.{}".format(notification_status))
if notification.sent_at:
statsd_client.timing_with_dates("callback.ses.elapsed-time", datetime.utcnow(), notification.sent_at)
check_and_queue_callback_task(notification)
return True

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")

View File

@@ -11,7 +11,6 @@ from click_datetime import Datetime as click_dt
from flask import current_app, json
from notifications_python_client.authentication import create_jwt_token
from notifications_utils.recipients import RecipientCSV
from notifications_utils.statsd_decorators import statsd
from notifications_utils.template import SMSMessageTemplate
from sqlalchemy import and_
from sqlalchemy.exc import IntegrityError
@@ -247,7 +246,6 @@ def bulk_invite_user_to_service(file_name, service_id, user_id, auth_type, permi
@notify_command(name='archive-jobs-created-between-dates')
@click.option('-s', '--start_date', required=True, help="start date inclusive", type=click_dt(format='%Y-%m-%d'))
@click.option('-e', '--end_date', required=True, help="end date inclusive", type=click_dt(format='%Y-%m-%d'))
@statsd(namespace="tasks")
def update_jobs_archived_flag(start_date, end_date):
current_app.logger.info('Archiving jobs created between {} to {}'.format(start_date, end_date))

View File

@@ -116,9 +116,6 @@ class Config(object):
# Monitoring
CRONITOR_ENABLED = False
CRONITOR_KEYS = json.loads(getenv('CRONITOR_KEYS', '{}'))
STATSD_HOST = getenv('STATSD_HOST')
STATSD_PORT = 8125
STATSD_ENABLED = bool(STATSD_HOST)
# Antivirus
ANTIVIRUS_ENABLED = getenv('ANTIVIRUS_ENABLED', '1') == '1'

View File

@@ -10,7 +10,7 @@ from notifications_utils.template import (
SMSMessageTemplate,
)
from app import create_uuid, db, notification_provider_clients, statsd_client
from app import create_uuid, db, notification_provider_clients
from app.celery.research_mode_tasks import (
send_email_response,
send_sms_response,
@@ -59,8 +59,6 @@ def send_sms_to_provider(notification):
prefix=service.name,
show_prefix=service.prefix_sms,
)
created_at = notification.created_at
key_type = notification.key_type
if service.research_mode or notification.key_type == KEY_TYPE_TEST:
update_notification_to_sending(notification, provider)
send_sms_response(provider.name, str(notification.id), notification.to)
@@ -91,18 +89,6 @@ def send_sms_to_provider(notification):
notification.billable_units = template.fragment_count
update_notification_to_sending(notification, provider)
delta_seconds = (datetime.utcnow() - created_at).total_seconds()
statsd_client.timing("sms.total-time", delta_seconds)
if key_type == KEY_TYPE_TEST:
statsd_client.timing("sms.test-key.total-time", delta_seconds)
else:
statsd_client.timing("sms.live-key.total-time", delta_seconds)
if service.high_volume:
statsd_client.timing("sms.live-key.high-volume.total-time", delta_seconds)
else:
statsd_client.timing("sms.live-key.not-high-volume.total-time", delta_seconds)
def send_email_to_provider(notification):
service = SerialisedService.from_id(notification.service_id)
@@ -127,8 +113,6 @@ def send_email_to_provider(notification):
template_dict,
values=notification.personalisation
)
created_at = notification.created_at
key_type = notification.key_type
if service.research_mode or notification.key_type == KEY_TYPE_TEST:
notification.reference = str(create_uuid())
update_notification_to_sending(notification, provider)
@@ -147,16 +131,6 @@ def send_email_to_provider(notification):
)
notification.reference = reference
update_notification_to_sending(notification, provider)
delta_seconds = (datetime.utcnow() - created_at).total_seconds()
if key_type == KEY_TYPE_TEST:
statsd_client.timing("email.test-key.total-time", delta_seconds)
else:
statsd_client.timing("email.live-key.total-time", delta_seconds)
if service.high_volume:
statsd_client.timing("email.live-key.high-volume.total-time", delta_seconds)
else:
statsd_client.timing("email.live-key.not-high-volume.total-time", delta_seconds)
def update_notification_to_sending(notification, provider):