in slomonitor/src/main/scala/com.gu.notifications.slos/SloMonitor.scala [145:166]
def handleMessage(event: SQSEvent): Unit = {
logger.info(s"Running SLO monitor")
val record = event.getRecords.get(0) // Batch size is defined as 1 in cdk
val notificationId = record.getBody
val sentTime: LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(record.getAttributes.get("SentTimestamp").toLong), ZoneOffset.UTC)
val query = generateQueryString(notificationId, sentTime)
logger.info(s"Starting query: $query")
val result = Athena.startQuery(Query("notifications", query, s"s3://aws-mobile-event-logs-${this.stage.toLowerCase()}/athena/slo-monitoring")).flatMap {
Athena.fetchQueryResponse(_, rows => {
val androidDeliveries = rows.head
val iosDeliveries = rows(1)
pushMetricsToCloudWatch(buildMetricsForPlatform(androidDeliveries, "android") ++ buildMetricsForPlatform(iosDeliveries, "ios"))
val deliveriesWithinTwoMinutes = Try(androidDeliveries(4).toDouble + iosDeliveries(4).toDouble).getOrElse("unknown")
logger.info(Map(
"notificationId" -> notificationId,
"deliveriesWithin2mins" -> deliveriesWithinTwoMinutes
),
s"Notifications delivered within 120 seconds was $deliveriesWithinTwoMinutes")
})
}
Await.result(result, duration.Duration(4, TimeUnit.MINUTES))
}