mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 01:32:20 -05:00
The performance platform is going away soon. The only stat that we do not have in our database is the processing time. Let me clarify the only statistic we don't have in our database that we can query efficiently is the processing time. Any queries on notification_history are too inefficient to use on a web page. Processing time = the total number of normal/team emails and text messages plus the number of messages that have gone from created to sending within 10 seconds per whole day. We can then easily calculate the percentage of messages that were marked as sending under 10 seconds.
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
from datetime import timedelta
|
|
|
|
from flask import current_app
|
|
|
|
from app.dao.fact_processing_time_dao import insert_update_processing_time
|
|
from app.models import FactProcessingTime
|
|
from app.utils import get_london_midnight_in_utc
|
|
from app.dao.notifications_dao import dao_get_total_notifications_sent_per_day_for_performance_platform
|
|
from app import performance_platform_client
|
|
|
|
|
|
def send_processing_time_to_performance_platform(bst_date):
|
|
start_time = get_london_midnight_in_utc(bst_date)
|
|
end_time = get_london_midnight_in_utc(bst_date + timedelta(days=1))
|
|
|
|
send_processing_time_for_start_and_end(start_time, end_time, bst_date)
|
|
|
|
|
|
def send_processing_time_for_start_and_end(start_time, end_time, bst_date):
|
|
result = dao_get_total_notifications_sent_per_day_for_performance_platform(start_time, end_time)
|
|
|
|
current_app.logger.info(
|
|
'Sending processing-time to performance platform for date {}. Total: {}, under 10 secs {}'.format(
|
|
start_time, result.messages_total, result.messages_within_10_secs
|
|
)
|
|
)
|
|
|
|
send_processing_time_data(start_time, 'messages-total', result.messages_total)
|
|
send_processing_time_data(start_time, 'messages-within-10-secs', result.messages_within_10_secs)
|
|
insert_update_processing_time(FactProcessingTime(
|
|
bst_date=bst_date,
|
|
messages_total=result.messages_total,
|
|
messages_within_10_secs=result.messages_within_10_secs)
|
|
)
|
|
|
|
|
|
def send_processing_time_data(start_time, status, count):
|
|
payload = performance_platform_client.format_payload(
|
|
dataset='processing-time',
|
|
start_time=start_time,
|
|
group_name='status',
|
|
group_value=status,
|
|
count=count
|
|
)
|
|
|
|
performance_platform_client.send_stats_to_performance_platform(payload)
|