-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement alerting and retrying mechanisms
Two features has been added in this commit: alerting and retrying For alerting, webhook method is used similar to other Snowplow apps. Alert message is sent to URL given in the config. Alerts are sent for some error cases, not for all of them. It is implemented such that it is sent only for setup errors. The error cases where alert sent can be extended in the future, of course. For retrying, two retry policies can be defined similar to Snowflake Loader. One of them is for setup errors and other one is for transient errors. Alert would be sent only for setup errors, not for transient errors. Also, possible setup error cases for Iceberg/Glue/S3 are added in this commit as well. Error cases for other destinations/table formats will be added later.
- Loading branch information
Showing
22 changed files
with
661 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
modules/core/src/main/scala/com.snowplowanalytics.snowplow.lakes/Alert.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2014-present Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This software is made available by Snowplow Analytics, Ltd., | ||
* under the terms of the Snowplow Limited Use License Agreement, Version 1.0 | ||
* located at https://docs.snowplow.io/limited-use-license-1.0 | ||
* BY INSTALLING, DOWNLOADING, ACCESSING, USING OR DISTRIBUTING ANY PORTION | ||
* OF THE SOFTWARE, YOU AGREE TO THE TERMS OF SUCH LICENSE AGREEMENT. | ||
*/ | ||
|
||
package com.snowplowanalytics.snowplow.lakes | ||
|
||
import cats.Show | ||
import cats.implicits.showInterpolator | ||
|
||
import com.snowplowanalytics.iglu.core.circe.implicits.igluNormalizeDataJson | ||
import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer, SelfDescribingData} | ||
import com.snowplowanalytics.snowplow.runtime.AppInfo | ||
|
||
import io.circe.Json | ||
import io.circe.syntax.EncoderOps | ||
|
||
import java.sql.SQLException | ||
|
||
sealed trait Alert | ||
object Alert { | ||
|
||
/** Restrict the length of an alert message to be compliant with alert iglu schema */ | ||
private val MaxAlertPayloadLength = 4096 | ||
|
||
final case class FailedToCreateEventsTable(cause: Throwable) extends Alert | ||
|
||
def toSelfDescribingJson( | ||
alert: Alert, | ||
appInfo: AppInfo, | ||
tags: Map[String, String] | ||
): Json = | ||
SelfDescribingData( | ||
schema = SchemaKey("com.snowplowanalytics.monitoring.loader", "alert", "jsonschema", SchemaVer.Full(1, 0, 0)), | ||
data = Json.obj( | ||
"appName" -> appInfo.name.asJson, | ||
"appVersion" -> appInfo.version.asJson, | ||
"message" -> getMessage(alert).asJson, | ||
"tags" -> tags.asJson | ||
) | ||
).normalize | ||
|
||
private def getMessage(alert: Alert): String = { | ||
val full = alert match { | ||
case FailedToCreateEventsTable(cause) => show"Failed to create events table: $cause" | ||
} | ||
|
||
full.take(MaxAlertPayloadLength) | ||
} | ||
|
||
private implicit def throwableShow: Show[Throwable] = { | ||
def removeDuplicateMessages(in: List[String]): List[String] = | ||
in match { | ||
case h :: t :: rest => | ||
if (h.contains(t)) removeDuplicateMessages(h :: rest) | ||
else if (t.contains(h)) removeDuplicateMessages(t :: rest) | ||
else h :: removeDuplicateMessages(t :: rest) | ||
case fewer => fewer | ||
} | ||
|
||
def accumulateMessages(t: Throwable): List[String] = { | ||
val nextMessage = t match { | ||
case t: SQLException => Some(s"${t.getMessage} = SqlState: ${t.getSQLState}") | ||
case t => Option(t.getMessage) | ||
} | ||
Option(t.getCause) match { | ||
case Some(cause) => nextMessage.toList ::: accumulateMessages(cause) | ||
case None => nextMessage.toList | ||
} | ||
} | ||
|
||
Show.show { t => | ||
removeDuplicateMessages(accumulateMessages(t)).mkString(": ") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.