Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE-711] Always log market id when pair information is missing. #694

Merged
merged 2 commits into from
Oct 24, 2023

Conversation

clemire
Copy link
Contributor

@clemire clemire commented Oct 24, 2023

Changelist

When getting market id labels, always return the printed market id if the pair string is not available.

Test Plan

Updated existing tests.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

@linear
Copy link

linear bot commented Oct 24, 2023

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2023

Walkthrough

The changes primarily focus on improving the error handling and readability of the code. The GetMarketPairForTelemetry function now returns a more descriptive error message when a market pair is not found. Corresponding changes have been made in the test cases to reflect this new behavior.

Changes

File(s) Summary
.../pricefeed/metrics/market_pairs.go Added import statement for the "fmt" package. Modified the GetMarketPairForTelemetry function to return a formatted string instead of a constant value when a market pair is not found.
.../pricefeed/metrics/market_pairs_test.go Updated the expected value in a test case for the GetMarketPairForTelemetry function from "INVALID" to "invalid_id:99".
.../pricefeed/metrics/metrics_test.go Added import statement for the "fmt" package. Modified a function call in the TestGetLabelForMarketIdFailure test function to use fmt.Sprintf for formatting the string argument. This ensures correct comparison of the expected label with the label generated by pricefeedmetrics.GetLabelForMarketId.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a612627 and 758c114.
Files selected for processing (3)
  • protocol/daemons/pricefeed/metrics/market_pairs.go (3 hunks)
  • protocol/daemons/pricefeed/metrics/market_pairs_test.go (1 hunks)
  • protocol/daemons/pricefeed/metrics/metrics_test.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/daemons/pricefeed/metrics/market_pairs_test.go
  • protocol/daemons/pricefeed/metrics/metrics_test.go
Additional comments: 3
protocol/daemons/pricefeed/metrics/market_pairs.go (3)
  • 4-4: The addition of the "fmt" package is necessary for the string formatting operation introduced in the GetMarketPairForTelemetry function. This change is appropriate and does not introduce any issues.

  • 23-23: The comment has been updated to fix a minor spelling mistake. This change is appropriate and does not introduce any issues.

  • 43-43: The return value of the GetMarketPairForTelemetry function has been updated to return a formatted string that includes the market id when the market id does not exist in the marketToPair map. This change improves the logging of market ids when pair information is not available. However, ensure that all calls to this function throughout the codebase can handle the new return value format.

@@ -39,7 +40,7 @@ func GetMarketPairForTelemetry(marketId types.MarketId) string {

marketPair, exists := marketToPair[marketId]
if !exists {
return INVALID
return fmt.Sprintf("id:%v", marketId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Sprintf("id:%v", marketId)
return fmt.Sprintf("invalid id:%v", marketId)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 758c114 and d6b5e99.
Files selected for processing (3)
  • protocol/daemons/pricefeed/metrics/market_pairs.go (3 hunks)
  • protocol/daemons/pricefeed/metrics/market_pairs_test.go (1 hunks)
  • protocol/daemons/pricefeed/metrics/metrics_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/daemons/pricefeed/metrics/market_pairs_test.go
Additional comments: 3
protocol/daemons/pricefeed/metrics/metrics_test.go (2)
  • 4-4: The addition of the "fmt" package is appropriate for the new string formatting requirement in the test function TestGetLabelForMarketIdFailure.

  • 31-31: The change in the expected value from pricefeedmetrics.INVALID to fmt.Sprintf("invalid_id:%d", INVALID_ID) is correct as it aligns with the updated behavior of the GetMarketPairForTelemetry function. Ensure that the INVALID_ID constant is defined and accessible in this context.

protocol/daemons/pricefeed/metrics/market_pairs.go (1)
  • 4-4: The addition of the "fmt" package is appropriate for the new string formatting requirement in the GetMarketPairForTelemetry function.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from returning a constant "INVALID" to a formatted string with the market id provides more information when the market pair is not found. This is a good improvement for logging and debugging purposes.

-		return INVALID
+		return fmt.Sprintf("invalid_id:%v", marketId)
Committable suggestion (Beta)
Suggested change
return fmt.Sprintf("invalid_id:%v", marketId)
marketPair, exists := marketToPair[marketId]
if !exists {
return fmt.Sprintf("invalid_id:%v", marketId)
}
return marketPair

@clemire clemire added the backport/protocol/v1.x Backport v1.x label Oct 24, 2023
@clemire clemire merged commit eb7c6ff into main Oct 24, 2023
15 of 16 checks passed
@clemire clemire deleted the crystal/CORE-711 branch October 24, 2023 22:31
mergify bot pushed a commit that referenced this pull request Oct 24, 2023
clemire added a commit that referenced this pull request Oct 24, 2023
…) (#700)

(cherry picked from commit eb7c6ff)

Co-authored-by: Crystal Lemire <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants