Improved operator string represenation #29935

* New attribute with source location information introduced and added to stages that takes lambdas
* Better default toString for GraphStageLogic including source location where possible
  and used that for debugging, errors and stream snapshots
This commit is contained in:
Johan Andrén 2021-01-11 15:17:50 +01:00 committed by GitHub
parent b8c79f8695
commit ccc4a2f48b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 112 additions and 65 deletions

View file

@ -5,12 +5,12 @@
package akka.stream.impl.fusing
import java.util.concurrent.TimeUnit.NANOSECONDS
import akka.actor.{ ActorRef, Terminated }
import akka.annotation.{ DoNotInherit, InternalApi }
import akka.event.Logging.LogLevel
import akka.event._
import akka.stream.ActorAttributes.SupervisionStrategy
import akka.stream.Attributes.SourceLocation
import akka.stream.Attributes.{ InputBuffer, LogLevels }
import akka.stream.OverflowStrategies._
import akka.stream.impl.Stages.DefaultAttributes
@ -40,7 +40,7 @@ import akka.util.ccompat._
val out = Outlet[Out]("Map.out")
override val shape = FlowShape(in, out)
override def initialAttributes: Attributes = DefaultAttributes.map
override def initialAttributes: Attributes = DefaultAttributes.map and SourceLocation.forLambda(f)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler {
@ -69,7 +69,7 @@ import akka.util.ccompat._
* INTERNAL API
*/
@InternalApi private[akka] final case class Filter[T](p: T => Boolean) extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.filter
override def initialAttributes: Attributes = DefaultAttributes.filter and SourceLocation.forLambda(p)
override def toString: String = "Filter"
@ -121,7 +121,7 @@ import akka.util.ccompat._
*/
@InternalApi private[akka] final case class TakeWhile[T](p: T => Boolean, inclusive: Boolean = false)
extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.takeWhile
override def initialAttributes: Attributes = DefaultAttributes.takeWhile and SourceLocation.forLambda(p)
override def toString: String = "TakeWhile"
@ -159,7 +159,7 @@ import akka.util.ccompat._
* INTERNAL API
*/
@InternalApi private[akka] final case class DropWhile[T](p: T => Boolean) extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.dropWhile
override def initialAttributes: Attributes = DefaultAttributes.dropWhile and SourceLocation.forLambda(p)
def createLogic(inheritedAttributes: Attributes) =
new SupervisedGraphStageLogic(inheritedAttributes, shape) with InHandler with OutHandler {
@ -231,7 +231,7 @@ private[stream] object Collect {
val out = Outlet[Out]("Collect.out")
override val shape = FlowShape(in, out)
override def initialAttributes: Attributes = DefaultAttributes.collect
override def initialAttributes: Attributes = DefaultAttributes.collect and SourceLocation.forLambda(pf)
def createLogic(inheritedAttributes: Attributes) =
new SupervisedGraphStageLogic(inheritedAttributes, shape) with InHandler with OutHandler {
@ -264,7 +264,7 @@ private[stream] object Collect {
*/
@InternalApi private[akka] final case class Recover[T](pf: PartialFunction[Throwable, T])
extends SimpleLinearGraphStage[T] {
override protected def initialAttributes: Attributes = DefaultAttributes.recover
override protected def initialAttributes: Attributes = DefaultAttributes.recover and SourceLocation.forLambda(pf)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler {
@ -315,6 +315,9 @@ private[stream] object Collect {
*/
@InternalApi private[akka] final case class MapError[T](f: PartialFunction[Throwable, Throwable])
extends SimpleLinearGraphStage[T] {
override protected def initialAttributes: Attributes = DefaultAttributes.mapError
override def createLogic(attr: Attributes) =
new GraphStageLogic(shape) with InHandler with OutHandler {
override def onPush(): Unit = push(out, grab(in))
@ -390,7 +393,7 @@ private[stream] object Collect {
extends GraphStage[FlowShape[In, Out]] {
override val shape = FlowShape[In, Out](Inlet("Scan.in"), Outlet("Scan.out"))
override def initialAttributes: Attributes = DefaultAttributes.scan
override def initialAttributes: Attributes = DefaultAttributes.scan and SourceLocation.forLambda(f)
override def toString: String = "Scan"
@ -457,7 +460,7 @@ private[stream] object Collect {
val out = Outlet[Out]("ScanAsync.out")
override val shape: FlowShape[In, Out] = FlowShape[In, Out](in, out)
override val initialAttributes: Attributes = Attributes.name("scanAsync")
override val initialAttributes: Attributes = Attributes.name("scanAsync") and SourceLocation.forLambda(f)
override val toString: String = "ScanAsync"
@ -576,7 +579,7 @@ private[stream] object Collect {
override def toString: String = "Fold"
override val initialAttributes = DefaultAttributes.fold
override val initialAttributes = DefaultAttributes.fold and SourceLocation.forLambda(f)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler {
@ -635,7 +638,7 @@ private[stream] object Collect {
override def toString: String = "FoldAsync"
override val initialAttributes = DefaultAttributes.foldAsync
override val initialAttributes = DefaultAttributes.foldAsync and SourceLocation.forLambda(f)
def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler {
@ -816,7 +819,7 @@ private[stream] object Collect {
*/
@InternalApi private[akka] final case class LimitWeighted[T](val n: Long, val costFn: T => Long)
extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.limitWeighted
override def initialAttributes: Attributes = DefaultAttributes.limitWeighted and SourceLocation.forLambda(costFn)
def createLogic(inheritedAttributes: Attributes) =
new SupervisedGraphStageLogic(inheritedAttributes, shape) with InHandler with OutHandler {
@ -1161,7 +1164,7 @@ private[stream] object Collect {
private val in = Inlet[In]("expand.in")
private val out = Outlet[Out]("expand.out")
override def initialAttributes = DefaultAttributes.expand
override def initialAttributes = DefaultAttributes.expand and SourceLocation.forLambda(extrapolate)
override val shape = FlowShape(in, out)
@ -1253,7 +1256,7 @@ private[stream] object Collect {
private val in = Inlet[In]("MapAsync.in")
private val out = Outlet[Out]("MapAsync.out")
override def initialAttributes = DefaultAttributes.mapAsync
override def initialAttributes = DefaultAttributes.mapAsync and SourceLocation.forLambda(f)
override val shape = FlowShape(in, out)
@ -1353,7 +1356,7 @@ private[stream] object Collect {
private val in = Inlet[In]("MapAsyncUnordered.in")
private val out = Outlet[Out]("MapAsyncUnordered.out")
override def initialAttributes = DefaultAttributes.mapAsyncUnordered
override def initialAttributes = DefaultAttributes.mapAsyncUnordered and SourceLocation.forLambda(f)
override val shape = FlowShape(in, out)
@ -1718,7 +1721,7 @@ private[stream] object Collect {
val in = Inlet[T]("in")
val out = Outlet[immutable.Seq[T]]("out")
override def initialAttributes = DefaultAttributes.groupedWeightedWithin
override def initialAttributes = DefaultAttributes.groupedWeightedWithin and SourceLocation.forLambda(costFn)
val shape = FlowShape(in, out)
@ -2038,7 +2041,7 @@ private[stream] object Collect {
* INTERNAL API
*/
@InternalApi private[akka] final class Reduce[T](val f: (T, T) => T) extends SimpleLinearGraphStage[T] {
override def initialAttributes: Attributes = DefaultAttributes.reduce
override def initialAttributes: Attributes = DefaultAttributes.reduce and SourceLocation.forLambda(f)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new GraphStageLogic(shape) with InHandler with OutHandler { self =>
@ -2166,7 +2169,7 @@ private[akka] final class StatefulMapConcat[In, Out](val f: () => In => Iterable
val out = Outlet[Out]("StatefulMapConcat.out")
override val shape = FlowShape(in, out)
override def initialAttributes: Attributes = DefaultAttributes.statefulMapConcat
override def initialAttributes: Attributes = DefaultAttributes.statefulMapConcat and SourceLocation.forLambda(f)
def createLogic(inheritedAttributes: Attributes) = new GraphStageLogic(shape) with InHandler with OutHandler {
lazy val decider = inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider