• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8483546216

29 Mar 2024 05:08PM UTC coverage: 31.807% (+0.4%) from 31.453%
8483546216

Pull #952

web-flow
Merge branch 'main' into docs/ATL-6599-update-adr-based-on-first-implementation-experience
Pull Request #952: docs(adr): ATL-6599 update ADR based on first implementation experience

4515 of 14195 relevant lines covered (31.81%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.11
/shared/src/main/scala/io/iohk/atala/shared/utils/aspects/CustomMetricsAspect.scala
1
package io.iohk.atala.shared.utils.aspects
2

3
import zio.*
4
import scala.collection.mutable.{Map => MutMap}
5
import zio.metrics.*
6
import java.time.{Instant, Clock, Duration}
7
import io.iohk.atala.shared.utils.DurationOps.toMetricsSeconds
8

9
object CustomMetricsAspect {
1✔
10
  private val checkpoints: MutMap[String, Instant] = MutMap.empty
1✔
11
  private val clock = Clock.systemUTC()
1✔
12
  private def now = ZIO.succeed(clock.instant)
13

1✔
14
  def startRecordingTime(key: String): ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] =
15
    new ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] {
1✔
16
      override def apply[R, E, A](
17
          zio: ZIO[R, E, A]
18
      )(implicit trace: Trace): ZIO[R, E, A] =
1✔
19
        for {
20
          res <- zio
×
21
          timeAfter <- now
×
22
          _ = checkpoints.update(key, timeAfter)
23
        } yield res
24
    }
25

1✔
26
  def endRecordingTime(
27
      key: String,
28
      metricsKey: String,
1✔
29
      tags: Set[MetricLabel] = Set.empty
30
  ): ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] =
31
    new ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] {
1✔
32
      override def apply[R, E, A](
33
          zio: ZIO[R, E, A]
34
      )(implicit trace: Trace): ZIO[R, E, A] = {
1✔
35
        for {
36
          res <- zio
×
37
          end <- now
×
38
          maybeStart = checkpoints.get(key)
×
39
          _ = checkpoints.remove(key)
×
40
          metricsZio = maybeStart.map(start => Duration.between(start, end)).fold(ZIO.unit) { duration =>
×
41
            ZIO.succeed(duration.toMetricsSeconds) @@ Metric.gauge(metricsKey).tagged(tags)
42
          }
1✔
43
          _ <- metricsZio
44
        } yield res
45
      }
46
    }
47

48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc