Add prometheus client metric for number of inbound text messages

As we gradually move from statsd to prometheus, we change the metric to
be a prometheus metric rather than statsd.

The change worth pointing out is that we have dropped the 'successful'
and 'failed' statuses from the metrics. I don't think it's useful to
have these statuses. It's very rare for an inbound message to fail when
we receive it and when it does, we raise an error and see it in our
logs. We aren't going to be looking at a graph of it as it's a rare
event, not typical behaviour that we want to monitor with a graph.
This commit is contained in:
David McDonald
2020-06-29 20:31:17 +01:00
parent 40f09097c8
commit 1e253b2257
2 changed files with 20 additions and 11 deletions

View File

@@ -3,9 +3,9 @@ from urllib.parse import unquote
import iso8601
from flask import jsonify, Blueprint, current_app, request, abort
from gds_metrics.metrics import Counter
from notifications_utils.recipients import try_validate_and_format_phone_number
from app import statsd_client
from app.celery import tasks
from app.config import QueueNames
from app.dao.services_dao import dao_fetch_service_by_inbound_number
@@ -17,6 +17,13 @@ receive_notifications_blueprint = Blueprint('receive_notifications', __name__)
register_errors(receive_notifications_blueprint)
INBOUND_SMS_COUNTER = Counter(
'inbound_sms',
'Total number of inbound SMS received',
['provider']
)
@receive_notifications_blueprint.route('/notifications/sms/receive/mmg', methods=['POST'])
def receive_mmg_sms():
"""
@@ -48,7 +55,7 @@ def receive_mmg_sms():
# we should still tell MMG that we received it successfully
return 'RECEIVED', 200
statsd_client.incr('inbound.mmg.successful')
INBOUND_SMS_COUNTER.labels("mmg").inc()
inbound = create_inbound_sms_object(service,
content=format_mmg_message(post_data["Message"]),
@@ -93,7 +100,7 @@ def receive_firetext_sms():
date_received=post_data['time'],
provider_name="firetext")
statsd_client.incr('inbound.firetext.successful')
INBOUND_SMS_COUNTER.labels("firetext").inc()
tasks.send_inbound_sms_to_service.apply_async([str(inbound.id), str(service.id)], queue=QueueNames.NOTIFY)
current_app.logger.debug(
@@ -155,7 +162,6 @@ def fetch_potential_service(inbound_number, provider_name):
current_app.logger.error('Inbound number "{}" from {} not associated with a service'.format(
inbound_number, provider_name
))
statsd_client.incr('inbound.{}.failed'.format(provider_name))
return False
if not has_inbound_sms_permissions(service.permissions):