Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Shota Jolbordi committed Aug 5, 2023
1 parent 1675c9a commit a795140
Showing 1 changed file with 51 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,62 +40,41 @@ object ConnectBackgroundJobs {
import ProtocolState.*
import Role.*

val InviteeConnectionRequestMsgFailed =
Metric
.counterInt("connection_flow_invitee_connection_request_msg_failed_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val InviteeConnectionRequestMsgSuccess = Metric
.counterInt("connection_flow_invitee_connection_request_msg_success_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val InviterConnectionResponseMsgFailed =
Metric
.counterInt("connection_flow_inviter_connection_response_msg_failed_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val InviterConnectionResponseMsgSuccess =
Metric
.counterInt("connection_flow_inviter_connection_response_msg_success_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviteePendingSuccess =
Metric
.counterInt("connection_flow_invitee_process_connection_record_success_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviteePendingFailed =
Metric
.counterInt("connection_flow_invitee_process_connection_record_failed_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviteePendingTotal = Metric
.counterInt("connection_flow_invitee_process_connection_record_total_count")
def counterMetric(key: String) = Metric
.counterInt(key)
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviterPendingSuccess =
Metric
.counterInt("connection_flow_inviter_process_connection_record_success_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviterPendingFailed =
Metric
.counterInt("connection_flow_inviter_process_connection_record_failed_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)

val ProcessConnectionRecordInviterPendingTotal = Metric
.counterInt("connection_flow_inviter_process_connection_record_total_count")
.fromConst(1)
.tagged("connectionId", record.id.toString)
val InviteeConnectionRequestMsgFailed = counterMetric(
"connection_flow_invitee_connection_request_msg_failed_counter"
)
val InviteeConnectionRequestMsgSuccess = counterMetric(
"connection_flow_invitee_connection_request_msg_success_counter"
)
val InviterConnectionResponseMsgFailed = counterMetric(
"connection_flow_inviter_connection_response_msg_failed_counter"
)
val InviterConnectionResponseMsgSuccess = counterMetric(
"connection_flow_inviter_connection_response_msg_success_counter"
)
val InviteeProcessConnectionRecordPendingSuccess = counterMetric(
"connection_flow_invitee_process_connection_record_success_counter"
)
val InviteeProcessConnectionRecordPendingFailed = counterMetric(
"connection_flow_invitee_process_connection_record_failed_counter"
)
val InviteeProcessConnectionRecordPendingTotal = counterMetric(
"connection_flow_invitee_process_connection_record_total_counter"
)
val InviterProcessConnectionRecordPendingSuccess = counterMetric(
"connection_flow_inviter_process_connection_record_success_counter"
)
val InviterProcessConnectionRecordPendingFailed = counterMetric(
"connection_flow_inviter_process_connection_record_failed_counter"
)
val InviterProcessConnectionRecordPendingTotal = counterMetric(
"connection_flow_inviter_process_connection_record_total_counter"
)

val exchange = record match {
case ConnectionRecord(
Expand All @@ -117,31 +96,36 @@ object ConnectBackgroundJobs {

didCommAgent <- buildDIDCommAgent(request.from)
resp <- MessagingService.send(request.makeMessage).provideSomeLayer(didCommAgent) @@ Metric
.gauge("connection_flow_invitee_send_connection_request_ms")
.gauge("connection_flow_invitee_send_connection_request_ms_gauge")
.tagged("connectionId", record.id.toString)
.trackDurationWith(_.toNanos.toDouble)
connectionService <- ZIO.service[ConnectionService]
_ <- {
if (resp.status >= 200 && resp.status < 300)
connectionService.markConnectionRequestSent(id)
@@ InviteeConnectionRequestMsgSuccess
@@ CustomMetricsAspect.endRecordingTime(s"${record.id}_invitee_pending_to_req_sent", "connection_flow_invitee_pending_to_req_sent_ms", Set(
MetricLabel(
"connectionId", record.id.toString
@@ CustomMetricsAspect.endRecordingTime(
s"${record.id}_invitee_pending_to_req_sent",
"connection_flow_invitee_pending_to_req_sent_ms_gauge",
Set(
MetricLabel(
"connectionId",
record.id.toString
)
)
)
))
else ZIO.fail(ErrorResponseReceivedFromPeerAgent(resp)) @@ InviteeConnectionRequestMsgFailed
}
} yield ()

// inviteeProcessFlow // TODO decrease metaRetries if it has a error

inviteeProcessFlow
@@ ProcessConnectionRecordInviteePendingSuccess.trackSuccess
@@ ProcessConnectionRecordInviteePendingFailed.trackError
@@ ProcessConnectionRecordInviteePendingTotal
@@ InviteeProcessConnectionRecordPendingSuccess.trackSuccess
@@ InviteeProcessConnectionRecordPendingFailed.trackError
@@ InviteeProcessConnectionRecordPendingTotal
@@ Metric
.gauge("connection_flow_invitee_process_connection_record_ms")
.gauge("connection_flow_invitee_process_connection_record_ms_gauge")
.tagged("connectionId", record.id.toString)
.trackDurationWith(_.toMillis.toDouble)

Expand All @@ -163,7 +147,7 @@ object ConnectBackgroundJobs {
val inviterProcessFlow = for {
didCommAgent <- buildDIDCommAgent(response.from)
resp <- MessagingService.send(response.makeMessage).provideSomeLayer(didCommAgent) @@ Metric
.gauge("connection_flow_inviter_send_connection_response_ms")
.gauge("connection_flow_inviter_send_connection_response_ms_gauge")
.tagged("connectionId", record.id.toString)
.trackDurationWith(_.toNanos.toDouble)
connectionService <- ZIO.service[ConnectionService]
Expand All @@ -175,11 +159,11 @@ object ConnectBackgroundJobs {
} yield ()

inviterProcessFlow
@@ ProcessConnectionRecordInviterPendingSuccess.trackSuccess
@@ ProcessConnectionRecordInviterPendingFailed.trackError
@@ ProcessConnectionRecordInviterPendingTotal
@@ InviterProcessConnectionRecordPendingSuccess.trackSuccess
@@ InviterProcessConnectionRecordPendingFailed.trackError
@@ InviterProcessConnectionRecordPendingTotal
@@ Metric
.gauge("connection_flow_inviter_process_connection_record_ms")
.gauge("connection_flow_inviter_process_connection_record_ms_gauge")
.tagged("connectionId", record.id.toString)
.trackDurationWith(_.toMillis.toDouble)

Expand Down

0 comments on commit a795140

Please sign in to comment.