From c02fd7ef1ca9761232a3e91aff7cc8fe947db76d Mon Sep 17 00:00:00 2001 From: jayy04 <103467857+jayy04@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:05:08 -0400 Subject: [PATCH] Add more latency metrics for liquidation daemon (#364) * Add more latency metrics for liquidation daemon * comments * use helper function --- protocol/daemons/liquidation/client/client.go | 27 ++++++++++++++++++- protocol/lib/metrics/constants.go | 12 ++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/protocol/daemons/liquidation/client/client.go b/protocol/daemons/liquidation/client/client.go index cfbb31f387..af2d115b6a 100644 --- a/protocol/daemons/liquidation/client/client.go +++ b/protocol/daemons/liquidation/client/client.go @@ -4,6 +4,7 @@ import ( "context" "time" + gometrics "github.com/armon/go-metrics" "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/telemetry" "github.com/cosmos/cosmos-sdk/types/query" @@ -98,7 +99,7 @@ func RunLiquidationDaemonTaskLoop( telemetry.ModuleSetGauge( metrics.LiquidationDaemon, float32(len(subaccounts)), - metrics.AllSubaccounts, + metrics.GetAllSubaccounts, metrics.Count, ) @@ -166,6 +167,7 @@ func GetAllSubaccounts( subaccounts []satypes.Subaccount, err error, ) { + defer telemetry.ModuleMeasureSince(metrics.LiquidationDaemon, time.Now(), metrics.GetAllSubaccounts, metrics.Latency) subaccounts = make([]satypes.Subaccount, 0) var nextKey []byte @@ -200,6 +202,13 @@ func CheckCollateralizationForSubaccounts( results []clobtypes.AreSubaccountsLiquidatableResponse_Result, err error, ) { + defer telemetry.ModuleMeasureSince( + metrics.LiquidationDaemon, + time.Now(), + metrics.CheckCollateralizationForSubaccounts, + metrics.Latency, + ) + query := &clobtypes.AreSubaccountsLiquidatableRequest{ SubaccountIds: subaccountIds, } @@ -217,6 +226,13 @@ func SendLiquidatableSubaccountIds( client api.LiquidationServiceClient, subaccountIds []satypes.SubaccountId, ) error { + defer telemetry.ModuleMeasureSince( + metrics.LiquidationDaemon, + time.Now(), + metrics.SendLiquidatableSubaccountIds, + metrics.Latency, + ) + request := &api.LiquidateSubaccountsRequest{ SubaccountIds: subaccountIds, } @@ -237,6 +253,15 @@ func getSubaccountsFromKey( nextKey []byte, err error, ) { + defer metrics.ModuleMeasureSinceWithLabels( + metrics.LiquidationDaemon, + []string{metrics.GetSubaccountsFromKey, metrics.Latency}, + time.Now(), + []gometrics.Label{ + metrics.GetLabelForIntValue(metrics.PageLimit, int(limit)), + }, + ) + query := &satypes.QueryAllSubaccountRequest{ Pagination: &query.PageRequest{ Key: pageRequestKey, diff --git a/protocol/lib/metrics/constants.go b/protocol/lib/metrics/constants.go index 4741cf2a4c..b21fa43040 100644 --- a/protocol/lib/metrics/constants.go +++ b/protocol/lib/metrics/constants.go @@ -240,10 +240,14 @@ const ( UpdateSubaccounts = "update_subaccounts" // Liquidation Daemon. - AllSubaccounts = "get_all_subaccounts" - LiquidatableSubaccountIds = "liquidatable_subaccount_ids" - LiquidationDaemon = "liquidation_daemon" - SubaccountsWithOpenPositions = "subaccounts_with_open_positions" + CheckCollateralizationForSubaccounts = "check_collateralization_for_subaccounts" + GetAllSubaccounts = "get_all_subaccounts" + GetSubaccountsFromKey = "get_subaccounts_from_key" + LiquidatableSubaccountIds = "liquidatable_subaccount_ids" + LiquidationDaemon = "liquidation_daemon" + PageLimit = "page_limit" + SendLiquidatableSubaccountIds = "send_liquidatable_subaccount_ids" + SubaccountsWithOpenPositions = "subaccounts_with_open_positions" // Liquidation. InsuranceFundBalance = "insurance_fund_balance"