Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate registration of FieldMetrics to blocking threadpool #2014

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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