Skip to content

Commit

Permalink
Delegate writing of field metrics to the blocking executor (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Nov 19, 2023
1 parent 3cb5e02 commit 2646d9a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/main/scala/caliban/wrappers/FieldMetrics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,20 @@ object FieldMetrics {
): GraphQLRequest => ZIO[R1, Nothing, GraphQLResponse[CalibanError]] =
(request: GraphQLRequest) =>
process(request) <*
(for {
_ <- failures.get.flatMap(metrics.recordFailures)
timings <- timings.get
nodeOffsets = resolveNodeOffsets(timings)
_ <- metrics.recordSuccesses(nodeOffsets, timings)
} yield ()).forkDaemon
ZIO
.blocking(for {
_ <- failures.get.flatMap(metrics.recordFailures)
timings <- timings.get
nodeOffsets = resolveNodeOffsets(timings)
_ <- metrics.recordSuccesses(nodeOffsets, timings)
} yield ())
.forkDaemon
}

private def resolveNodeOffsets(timings: List[Timing]): Map[Vector[Either[String, Int]], Long] = {
val map = new java.util.HashMap[Vector[Either[String, Int]], Long]()
var remaining = timings
while (remaining != Nil) {
while (!remaining.isEmpty) {
val t = remaining.head
val iter = t.path.inits
val duration = t.duration
Expand Down Expand Up @@ -125,7 +127,7 @@ object FieldMetrics {
def makeTiming(duration: Long) =
Timing(
name = info.name,
path = info.path.view.reverse.toVector,
path = info.path.reverse.toVector,
fullName = fieldName,
duration = duration
)
Expand Down

0 comments on commit 2646d9a

Please sign in to comment.