-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic reporting for import batch (#4773)
* Add basic reporting for import batch --------- Co-authored-by: Simon Dumas <[email protected]>
- Loading branch information
Showing
12 changed files
with
160 additions
and
52 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
51 changes: 51 additions & 0 deletions
51
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ImportReport.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,51 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import cats.Show | ||
import cats.kernel.Monoid | ||
import cats.syntax.all._ | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.model.EntityType | ||
import ch.epfl.bluebrain.nexus.delta.sourcing.offset.Offset | ||
import ch.epfl.bluebrain.nexus.ship.ImportReport.Count | ||
import ch.epfl.bluebrain.nexus.ship.model.InputEvent | ||
|
||
import java.time.Instant | ||
|
||
final case class ImportReport(offset: Offset, instant: Instant, progress: Map[EntityType, Count]) { | ||
def +(event: InputEvent, status: ImportStatus): ImportReport = { | ||
val entityType = event.`type` | ||
val newProgress = progress.updatedWith(entityType) { | ||
case Some(count) => Some(count |+| status.asCount) | ||
case None => Some(status.asCount) | ||
} | ||
copy(offset = event.ordering, instant = event.instant, progress = newProgress) | ||
} | ||
} | ||
|
||
object ImportReport { | ||
|
||
val start: ImportReport = ImportReport(Offset.start, Instant.EPOCH, Map.empty) | ||
|
||
final case class Count(success: Long, dropped: Long) | ||
|
||
object Count { | ||
|
||
implicit val countMonoid: Monoid[Count] = new Monoid[Count] { | ||
override def empty: Count = Count(0L, 0L) | ||
|
||
override def combine(x: Count, y: Count): Count = Count(x.success + y.success, x.dropped + y.dropped) | ||
} | ||
|
||
} | ||
|
||
implicit val showReport: Show[ImportReport] = (report: ImportReport) => { | ||
val header = s"Type\tSuccess\tDropped\n" | ||
val details = report.progress.foldLeft(header) { case (acc, (entityType, count)) => | ||
acc ++ s"$entityType\t${count.success}\t${count.dropped}\n" | ||
} | ||
|
||
val aggregatedCount = report.progress.values.reduceOption(_ |+| _).getOrElse(Count(0L, 0L)) | ||
val global = | ||
s"${aggregatedCount.success} events were imported up to offset ${report.offset} (${aggregatedCount.dropped} have been dropped)." | ||
s"$global\n$details" | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/ImportStatus.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,23 @@ | ||
package ch.epfl.bluebrain.nexus.ship | ||
|
||
import ch.epfl.bluebrain.nexus.ship.ImportReport.Count | ||
|
||
sealed trait ImportStatus { | ||
|
||
def asCount: Count | ||
|
||
} | ||
|
||
object ImportStatus { | ||
|
||
case object Success extends ImportStatus { | ||
override def asCount: Count = Count(1L, 0L) | ||
} | ||
|
||
case object Dropped extends ImportStatus { | ||
|
||
override def asCount: Count = Count(0L, 1L) | ||
|
||
} | ||
|
||
} |
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
Oops, something went wrong.