From a4690e8228a8181095a0e090d37170dc8737fdf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Poniedzia=C5=82ek?= Date: Fri, 1 Jul 2022 08:50:32 +0200 Subject: [PATCH] Loader: Trim alert message payloads to 4096 characters (close #956) --- .../com/snowplowanalytics/snowplow/rdbloader/Loader.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/Loader.scala b/modules/loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/Loader.scala index 803f0ea32..345fe2781 100644 --- a/modules/loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/Loader.scala +++ b/modules/loader/src/main/scala/com/snowplowanalytics/snowplow/rdbloader/Loader.scala @@ -33,7 +33,10 @@ object Loader { Logging.LoggerName(getClass.getSimpleName.stripSuffix("$")) /** How often Loader should print its internal state */ - val StateLoggingFrequency: FiniteDuration = 5.minutes + private val StateLoggingFrequency: FiniteDuration = 5.minutes + + /** Restrict the length of an alert message to be compliant with alert iglu schema */ + private val MaxAlertPayloadLength = 4096 /** * Primary application's entry-point, responsible for launching all processes @@ -182,7 +185,8 @@ object Loader { case e: SQLException => s"${error.getMessage} - SqlState: ${e.getSQLState}" case _ => Option(error.getMessage).getOrElse(error.toString) } - val alert = Monitoring.AlertPayload.warn(message, discovery.origin.base) + val trimmedMessage = message.take(MaxAlertPayloadLength) + val alert = Monitoring.AlertPayload.warn(trimmedMessage, discovery.origin.base) val logNoRetry = Logging[F].error(s"Loading of ${discovery.origin.base} has failed. Not adding into retry queue. $message") val logRetry = Logging[F].error(s"Loading of ${discovery.origin.base} has failed. Adding intro retry queue. $message")