Skip to content

Commit

Permalink
[CORE-711] Always log market id when pair information is missing. (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemire authored Oct 24, 2023
1 parent ed6429f commit eb7c6ff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions protocol/daemons/pricefeed/metrics/market_pairs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package metrics

import (
"fmt"
"sync"

"github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/types"
Expand All @@ -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
)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocol/daemons/pricefeed/metrics/market_pairs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGetMarketPairForTelemetry(t *testing.T) {
},
"absent id": {
marketId: 99,
expected: "INVALID",
expected: "invalid_id:99",
},
}
metrics.SetMarketPairForTelemetry(1, "BTC-USD")
Expand Down
3 changes: 2 additions & 1 deletion protocol/daemons/pricefeed/metrics/metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package metrics_test

import (
"fmt"
"testing"

"github.com/dydxprotocol/v4-chain/protocol/testutil/daemons/pricefeed/exchange_config"
Expand All @@ -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),
)
}
Expand Down

0 comments on commit eb7c6ff

Please sign in to comment.