Skip to content

Commit

Permalink
Add more latency metrics for liquidation daemon (#364)
Browse files Browse the repository at this point in the history
* Add more latency metrics for liquidation daemon

* comments

* use helper function
  • Loading branch information
jayy04 committed Sep 25, 2023
1 parent 10e62c5 commit c02fd7e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
27 changes: 26 additions & 1 deletion protocol/daemons/liquidation/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -98,7 +99,7 @@ func RunLiquidationDaemonTaskLoop(
telemetry.ModuleSetGauge(
metrics.LiquidationDaemon,
float32(len(subaccounts)),
metrics.AllSubaccounts,
metrics.GetAllSubaccounts,
metrics.Count,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions protocol/lib/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c02fd7e

Please sign in to comment.