-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(prism-agent): Metrics for connection flow job #611
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c1e1ad
Metrics for connection flow job
6c3a4c9
Merge branch 'main' into ATL-4256-add-metrics-for-connection-flow
c8b4553
Add customMetricsAspect
c28fe90
Cleanup
5aeb58f
Fix error of incorrecting counting duration above 10 seconds
1675c9a
Merge branch 'main' into ATL-4256-add-metrics-for-connection-flow
a795140
Some refactoring
84f4a55
REfactoring
2844322
Track inviter pending to resp sent metric, format files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions
9
shared/src/main/scala/io/iohk/atala/shared/utils/DurationOps.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,9 @@ | ||
package io.iohk.atala.shared.utils | ||
|
||
import java.time.Duration | ||
|
||
object DurationOps { | ||
|
||
extension (d: Duration) def toMetricsSeconds: Double = d.toMillis.toDouble / 1000.0 | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
shared/src/main/scala/io/iohk/atala/shared/utils/aspects/CustomMetricsAspect.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,47 @@ | ||
package io.iohk.atala.shared.utils.aspects | ||
|
||
import zio.* | ||
import scala.collection.mutable.{Map => MutMap} | ||
import zio.metrics.* | ||
import java.time.{Instant, Clock, Duration} | ||
import io.iohk.atala.shared.utils.DurationOps.toMetricsSeconds | ||
|
||
object CustomMetricsAspect { | ||
private val checkpoints: MutMap[String, Instant] = MutMap.empty | ||
private val clock = Clock.systemUTC() | ||
private def now = ZIO.succeed(clock.instant) | ||
|
||
def startRecordingTime(key: String): ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] = | ||
new ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] { | ||
override def apply[R, E, A]( | ||
zio: ZIO[R, E, A] | ||
)(implicit trace: Trace): ZIO[R, E, A] = | ||
for { | ||
res <- zio | ||
timeAfter <- now | ||
_ = checkpoints.update(key, timeAfter) | ||
} yield res | ||
} | ||
|
||
def endRecordingTime( | ||
key: String, | ||
metricsKey: String, | ||
tags: Set[MetricLabel] = Set.empty | ||
): ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] = | ||
new ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] { | ||
override def apply[R, E, A]( | ||
zio: ZIO[R, E, A] | ||
)(implicit trace: Trace): ZIO[R, E, A] = { | ||
for { | ||
res <- zio | ||
end <- now | ||
maybeStart = checkpoints.get(key) | ||
metricsZio = maybeStart.map(start => Duration.between(start, end)).fold(ZIO.unit) { duration => | ||
ZIO.succeed(duration.toMetricsSeconds) @@ Metric.gauge(metricsKey).tagged(tags) | ||
} | ||
_ <- metricsZio | ||
} yield res | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a metrics which is named
invitee_pending_to_req_sent
with a label ofrecord.id
instead of many different metrics? It won't be possible to compare / sum by record.id if this is a full metric on it's own