from typing import Dict, Generator, List from notification_service.entities import NotificationType from datadog.dogstatsd.base import statsd def chunks(lst: List, elements: int) -> Generator: """Yield successive n-sized chunks from lst.""" for i in range(0, len(lst), elements): yield lst[i:i + elements] def send_metric_by_dimension(msg: Dict) -> None: content_keys = msg['data']['content'].keys() if NotificationType.TRACK.value in content_keys: notification_type = NotificationType.TRACK.value elif NotificationType.PLAYLIST.value in content_keys: notification_type = NotificationType.PLAYLIST.value else: raise Exception('Unsupported notification_type.' f'Existing keys in json - {content_keys}') dsp = msg['meta']['dsp'] event_type = msg['meta']['event_type'] statsd.increment( 'notification-service.sent_notifications', tags=[ f'notification_type:{notification_type}', f'dsp:{dsp}', f'event_type:{event_type}', ], )