Skip to content

Commit

Permalink
feat(prism-agent): Metrics for verification flow (#714)
Browse files Browse the repository at this point in the history
Signed-off-by: Shota Jolbordi <shota.jolbordi@iohk.io>
  • Loading branch information
shotexa committed Sep 14, 2023
1 parent 63403a5 commit 8bea26e
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.iohk.atala.pollux.core.model.presentation.*
import io.iohk.atala.pollux.core.repository.{CredentialRepository, PresentationRepository}
import io.iohk.atala.pollux.vc.jwt.*
import io.iohk.atala.shared.models.WalletAccessContext
import io.iohk.atala.shared.utils.aspects.CustomMetricsAspect
import zio.*

import java.rmi.UnexpectedException
Expand All @@ -37,7 +38,12 @@ private class PresentationServiceImpl(
record <- getRecordWithState(recordId, ProtocolState.PresentationPending)
count <- presentationRepository
.updateWithPresentation(recordId, presentation, ProtocolState.PresentationGenerated)
.mapError(RepositoryError.apply)
.mapError(RepositoryError.apply) @@ CustomMetricsAspect.endRecordingTime(
s"${record.id}_present_proof_flow_prover_presentation_pending_to_generated_ms_gauge",
"present_proof_flow_prover_presentation_pending_to_generated_ms_gauge"
) @@ CustomMetricsAspect.startRecordingTime(
s"${record.id}_present_proof_flow_prover_presentation_generated_to_sent_ms_gauge"
)
_ <- count match
case 1 => ZIO.succeed(())
case n => ZIO.fail(RecordIdNotFound(recordId))
Expand Down Expand Up @@ -174,7 +180,9 @@ private class PresentationServiceImpl(
case 1 => ZIO.succeed(())
case n => ZIO.fail(UnexpectedException(s"Invalid row count result: $n"))
}
.mapError(RepositoryError.apply)
.mapError(RepositoryError.apply) @@ CustomMetricsAspect.startRecordingTime(
s"${record.id}_present_proof_flow_verifier_req_pending_to_sent_ms_gauge"
)
} yield record
}

Expand Down Expand Up @@ -322,7 +330,9 @@ private class PresentationServiceImpl(
)
count <- presentationRepository
.updatePresentationWithCredentialsToUse(recordId, Option(credentialsToUse), ProtocolState.PresentationPending)
.mapError(RepositoryError.apply)
.mapError(RepositoryError.apply) @@ CustomMetricsAspect.startRecordingTime(
s"${record.id}_present_proof_flow_prover_presentation_pending_to_generated_ms_gauge"
)
_ <- count match
case 1 => ZIO.succeed(())
case n => ZIO.fail(RecordIdNotFound(recordId))
Expand Down Expand Up @@ -364,7 +374,9 @@ private class PresentationServiceImpl(
case 1 => ZIO.succeed(())
case n => ZIO.fail(UnexpectedException(s"Invalid row count result: $n"))
}
.mapError(RepositoryError.apply)
.mapError(RepositoryError.apply) @@ CustomMetricsAspect.startRecordingTime(
s"${record.id}_present_proof_flow_verifier_presentation_received_to_verification_success_or_failure_ms_gauge"
)
record <- presentationRepository
.getPresentationRecord(record.id)
.mapError(RepositoryError.apply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.iohk.atala.resolvers.DIDResolver
import io.iohk.atala.shared.models.{HexString, WalletAccessContext, WalletId}
import io.iohk.atala.system.controller.SystemServerEndpoints
import zio.*
import zio.metrics.*
import io.iohk.atala.shared.utils.DurationOps.toMetricsSeconds

object PrismAgentApp {

Expand Down Expand Up @@ -54,7 +56,9 @@ object PrismAgentApp {
.flatMap { wallets =>
ZIO.foreach(wallets) { wallet =>
BackgroundJobs.issueCredentialDidCommExchanges
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id)))
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id))) @@ Metric
.gauge("issuance_flow_did_com_exchange_job_ms_gauge")
.trackDurationWith(_.toMetricsSeconds)
}
}
.repeat(Schedule.spaced(config.pollux.issueBgJobRecurrenceDelay))
Expand All @@ -73,7 +77,9 @@ object PrismAgentApp {
.flatMap { wallets =>
ZIO.foreach(wallets) { wallet =>
BackgroundJobs.presentProofExchanges
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id)))
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id))) @@ Metric
.gauge("present_proof_flow_did_com_exchange_job_ms_gauge")
.trackDurationWith(_.toMetricsSeconds)
}
}
.repeat(Schedule.spaced(config.pollux.presentationBgJobRecurrenceDelay))
Expand All @@ -91,7 +97,9 @@ object PrismAgentApp {
.flatMap { wallets =>
ZIO.foreach(wallets) { wallet =>
ConnectBackgroundJobs.didCommExchanges
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id)))
.provideSomeLayer(ZLayer.succeed(WalletAccessContext(wallet.id))) @@ Metric
.gauge("connection_flow_did_com_exchange_job_ms_gauge")
.trackDurationWith(_.toMetricsSeconds)
}
}
.repeat(Schedule.spaced(config.connect.connectBgJobRecurrenceDelay))
Expand Down
Loading

0 comments on commit 8bea26e

Please sign in to comment.