From eb7c6ff15ed8b03e623399b7395e4c1f36239beb Mon Sep 17 00:00:00 2001 From: Crystal Lemire Date: Tue, 24 Oct 2023 15:31:57 -0700 Subject: [PATCH] [CORE-711] Always log market id when pair information is missing. (#694) --- protocol/daemons/pricefeed/metrics/market_pairs.go | 5 +++-- protocol/daemons/pricefeed/metrics/market_pairs_test.go | 2 +- protocol/daemons/pricefeed/metrics/metrics_test.go | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/protocol/daemons/pricefeed/metrics/market_pairs.go b/protocol/daemons/pricefeed/metrics/market_pairs.go index 8ee93c8919..8b10fbc1a7 100644 --- a/protocol/daemons/pricefeed/metrics/market_pairs.go +++ b/protocol/daemons/pricefeed/metrics/market_pairs.go @@ -1,6 +1,7 @@ package metrics import ( + "fmt" "sync" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/types" @@ -19,7 +20,7 @@ var ( // these market pairs are very unlikely to be updated, so this solution, while not perfect, is // acceptable for the use case of logging/metrics in order to manage code complexity. marketToPair = map[types.MarketId]string{} - // lock syncronizes access to the marketToPair map. + // lock synchronizes access to the marketToPair map. lock sync.Mutex ) @@ -39,7 +40,7 @@ func GetMarketPairForTelemetry(marketId types.MarketId) string { marketPair, exists := marketToPair[marketId] if !exists { - return INVALID + return fmt.Sprintf("invalid_id:%v", marketId) } return marketPair diff --git a/protocol/daemons/pricefeed/metrics/market_pairs_test.go b/protocol/daemons/pricefeed/metrics/market_pairs_test.go index 46a6bd9a1f..6e02eedf3c 100644 --- a/protocol/daemons/pricefeed/metrics/market_pairs_test.go +++ b/protocol/daemons/pricefeed/metrics/market_pairs_test.go @@ -18,7 +18,7 @@ func TestGetMarketPairForTelemetry(t *testing.T) { }, "absent id": { marketId: 99, - expected: "INVALID", + expected: "invalid_id:99", }, } metrics.SetMarketPairForTelemetry(1, "BTC-USD") diff --git a/protocol/daemons/pricefeed/metrics/metrics_test.go b/protocol/daemons/pricefeed/metrics/metrics_test.go index 708e2659e1..6fc2a3bb6a 100644 --- a/protocol/daemons/pricefeed/metrics/metrics_test.go +++ b/protocol/daemons/pricefeed/metrics/metrics_test.go @@ -1,6 +1,7 @@ package metrics_test import ( + "fmt" "testing" "github.com/dydxprotocol/v4-chain/protocol/testutil/daemons/pricefeed/exchange_config" @@ -27,7 +28,7 @@ func TestGetLabelForMarketIdSuccess(t *testing.T) { func TestGetLabelForMarketIdFailure(t *testing.T) { require.Equal( t, - metrics.GetLabelForStringValue(metrics.MarketId, pricefeedmetrics.INVALID), + metrics.GetLabelForStringValue(metrics.MarketId, fmt.Sprintf("invalid_id:%d", INVALID_ID)), pricefeedmetrics.GetLabelForMarketId(INVALID_ID), ) }