Skip to content

Commit

Permalink
#153 Align run status reasons across email notifications and journal …
Browse files Browse the repository at this point in the history
…entries.
  • Loading branch information
yruslan committed Feb 6, 2023
1 parent ec042ac commit bcea0b7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class PipelineNotificationBuilderHtml(implicit conf: Config) extends PipelineNot
case _ => false
})

val haveReasonColumn = tasks.exists(t => t.runStatus.isFailure || t.dependencyWarnings.nonEmpty)
val haveReasonColumn = tasks.exists(t => t.runStatus.getReason().nonEmpty || t.dependencyWarnings.nonEmpty)

val tableBuilder = new TableBuilderHtml

Expand Down Expand Up @@ -419,14 +419,9 @@ class PipelineNotificationBuilderHtml(implicit conf: Config) extends PipelineNot
}

private def getFailureReason(task: TaskResult): String = {
task.runStatus match {
case Failed(ex) => ex.getMessage
case ValidationFailed(ex) => ex.getMessage
case InsufficientData(actual, expected, _) => s"Got $actual, expected at least $expected records"
case MissingDependencies(_, tables) => s"Dependent job failures: ${tables.mkString(", ")}"
case FailedDependencies(_, deps) => s"Dependency check failures: ${deps.map(_.renderText).mkString("; ")}"
case NoData(true) => s"No records at the source"
case _ =>
task.runStatus.getReason() match {
case Some(reason) => reason
case None =>
if (task.dependencyWarnings.isEmpty) {
""
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ object RunStatus {
}

case class MissingDependencies(isFailure: Boolean, tables: Seq[String]) extends RunStatus {
override def toString: String = "Missing dependencies"
override def toString: String = "Dependent job failed"

override def getReason(): Option[String] = Option(s"Missing dependencies: ${tables.mkString(", ")}")
override def getReason(): Option[String] = Option(s"Dependent job failures: ${tables.mkString(", ")}")
}

case class FailedDependencies(isFailure: Boolean, failures: Seq[DependencyFailure]) extends RunStatus {
override def toString: String = "Failed dependencies"
override def toString: String = "Dependency check failed"

override def getReason(): Option[String] = {
val failedTables = failures.flatMap(d => d.failedTables ++ d.emptyTables).distinct.sorted
Option(s"Failed dependencies for: ${failedTables.mkString(", ")}")
Option(s"Dependency check failures: ${failures.map(_.renderText).mkString("; ")}")
}
}

Expand All @@ -75,7 +74,7 @@ object RunStatus {

val isFailure: Boolean = true

override def getReason(): Option[String] = Option(s"Expected $expected records, but got $actual records")
override def getReason(): Option[String] = Option(s"Got $actual, expected at least $expected records")
}

case object NotRan extends RunStatus {
Expand All @@ -91,6 +90,6 @@ object RunStatus {

override def toString: String = "Skipped"

override def getReason(): Option[String] = Option(msg)
override def getReason(): Option[String] = if (msg.isEmpty) None else Option(msg)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class RunStatusSuite extends AnyWordSpec {
"MissingDependencies" in {
val status = RunStatus.MissingDependencies(isFailure = false, null)

assert(status.toString == "Missing dependencies")
assert(status.toString == "Dependent job failed")
}

"FailedDependencies" in {
val status = RunStatus.FailedDependencies(isFailure = false, null)

assert(status.toString == "Failed dependencies")
assert(status.toString == "Dependency check failed")
}

"NoData" in {
Expand Down Expand Up @@ -187,7 +187,7 @@ class RunStatusSuite extends AnyWordSpec {
"MissingDependencies" in {
val status = RunStatus.MissingDependencies(isFailure = false, Seq("table2", "table1"))

assert(status.getReason().contains("Missing dependencies: table2, table1"))
assert(status.getReason().contains("Dependent job failures: table2, table1"))
}

"FailedDependencies" in {
Expand All @@ -196,10 +196,10 @@ class RunStatusSuite extends AnyWordSpec {
MetastoreDependency(Seq("table2", "table1", "table3"), "", None, triggerUpdates = false, isOptional = false, isPassive = false),
Seq("table3"),
Seq("table1"),
Nil
Seq("2022-01-01")
)))

assert(status.getReason().contains("Failed dependencies for: table1, table3"))
assert(status.getReason().contains("Dependency check failures: table3 (Empty or wrong name), table1 (2022-01-01)"))
}

"NoData" in {
Expand All @@ -211,7 +211,7 @@ class RunStatusSuite extends AnyWordSpec {
"InsufficientData" in {
val status = RunStatus.InsufficientData(100, 200, None)

assert(status.getReason().contains("Expected 200 records, but got 100 records"))
assert(status.getReason().contains("Got 100, expected at least 200 records"))
}

"NotRan" in {
Expand All @@ -220,10 +220,17 @@ class RunStatusSuite extends AnyWordSpec {
assert(status.getReason().isEmpty)
}

"Skipped" in {
val status = RunStatus.Skipped("My reason")
"Skipped" when {
"empty reason" in {
val status = RunStatus.Skipped("")

assert(status.getReason().isEmpty)
}
"non-empty reason" in {
val status = RunStatus.Skipped("My reason")

assert(status.getReason().contains("My reason"))
assert(status.getReason().contains("My reason"))
}
}
}
}

0 comments on commit bcea0b7

Please sign in to comment.