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

chore(zetaclient): improve logging by adding and moving data to attributes #2875

Closed
wants to merge 1 commit into from

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Sep 13, 2024

We see a lot of "RPC Status Check error: RPC down?" with error "not found".

  • make the log messages more specific about what exactly is failing
  • add consistent block_number log attribute whenever possible

Summary by CodeRabbit

  • New Features

    • Enhanced logging functionality for RPC status checks, providing more detailed error messages and context.
    • Improved clarity in logs for both successful and failed RPC calls, including specific method names and additional structured information.
  • Bug Fixes

    • Updated logging for block age checks to include relevant details like block number and age in seconds, aiding diagnostics.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

Walkthrough

The changes in this pull request focus on enhancing the logging functionality of the WatchRPCStatus function within the Observer struct for both Bitcoin and EVM chains. The modifications involve providing more detailed error messages, including specific RPC methods that failed, and updating log messages to include additional contextual information such as block numbers and timestamps. This results in improved clarity and diagnostic capabilities during RPC status checks.

Changes

File Path Change Summary
zetaclient/chains/bitcoin/observer/observer.go Enhanced logging in WatchRPCStatus to include detailed error messages with context for failed RPC calls and improved success log messages.
zetaclient/chains/evm/observer/observer.go Improved logging in WatchRPCStatus by specifying failed RPC method names, renaming variables for clarity, and adding structured logging for warnings and successes.

Possibly related PRs

  • fix(zetaclient): use on-chain chain struct #2834: The changes in the NewObserver function in observer.go are related to the main PR as both involve modifications to the observer's initialization and logging functionality, specifically enhancing the handling of JSON RPC clients.

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gartnera gartnera force-pushed the improve-zetaclient-logging branch from cc78c1e to ce119a1 Compare September 13, 2024 17:18
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.

Project coverage is 66.87%. Comparing base (19c929c) to head (ce119a1).
Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/bitcoin/observer/observer.go 0.00% 21 Missing ⚠️
zetaclient/chains/evm/observer/observer.go 0.00% 15 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2875      +/-   ##
===========================================
- Coverage    66.94%   66.87%   -0.07%     
===========================================
  Files          373      373              
  Lines        21032    21054      +22     
===========================================
  Hits         14080    14080              
- Misses        6288     6310      +22     
  Partials       664      664              
Files with missing lines Coverage Δ
zetaclient/chains/evm/observer/observer.go 59.47% <0.00%> (-2.62%) ⬇️
zetaclient/chains/bitcoin/observer/observer.go 31.42% <0.00%> (-1.47%) ⬇️

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.

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
zetaclient/chains/bitcoin/observer/observer.go (1)

243-243: Improve error messages and logging.

Consider enhancing the error messages and logging in the WatchRPCStatus function:

  1. Include the chain ID in the error messages and success log to provide more context.
  2. For failed RPC calls, include the specific RPC method that failed in the error message.

For example:

ob.logger.Chain.Error().Err(err).
    Int64("chain_id", ob.Chain().ChainId).
    Msg("RPC status check failed: GetBlockCount")

Additionally, consider logging the TSS address in the error message when no UTXOs are found for better debugging.

Also applies to: 249-251, 257-260, 265-271

Tools
GitHub Check: codecov/patch

[warning] 243-243: zetaclient/chains/bitcoin/observer/observer.go#L243
Added line #L243 was not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 19c929c and ce119a1.

Files selected for processing (2)
  • zetaclient/chains/bitcoin/observer/observer.go (2 hunks)
  • zetaclient/chains/evm/observer/observer.go (1 hunks)
Additional context used
Path-based instructions (2)
zetaclient/chains/evm/observer/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/bitcoin/observer/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

GitHub Check: codecov/patch
zetaclient/chains/evm/observer/observer.go

[warning] 220-220: zetaclient/chains/evm/observer/observer.go#L220
Added line #L220 was not covered by tests


[warning] 225-227: zetaclient/chains/evm/observer/observer.go#L225-L227
Added lines #L225 - L227 were not covered by tests


[warning] 232-234: zetaclient/chains/evm/observer/observer.go#L232-L234
Added lines #L232 - L234 were not covered by tests


[warning] 239-240: zetaclient/chains/evm/observer/observer.go#L239-L240
Added lines #L239 - L240 were not covered by tests


[warning] 242-242: zetaclient/chains/evm/observer/observer.go#L242
Added line #L242 was not covered by tests


[warning] 246-250: zetaclient/chains/evm/observer/observer.go#L246-L250
Added lines #L246 - L250 were not covered by tests

zetaclient/chains/bitcoin/observer/observer.go

[warning] 243-243: zetaclient/chains/bitcoin/observer/observer.go#L243
Added line #L243 was not covered by tests


[warning] 249-251: zetaclient/chains/bitcoin/observer/observer.go#L249-L251
Added lines #L249 - L251 were not covered by tests


[warning] 257-260: zetaclient/chains/bitcoin/observer/observer.go#L257-L260
Added lines #L257 - L260 were not covered by tests


[warning] 265-271: zetaclient/chains/bitcoin/observer/observer.go#L265-L271
Added lines #L265 - L271 were not covered by tests


[warning] 292-297: zetaclient/chains/bitcoin/observer/observer.go#L292-L297
Added lines #L292 - L297 were not covered by tests

zetaclient/chains/evm/observer/observer.go Show resolved Hide resolved
zetaclient/chains/evm/observer/observer.go Show resolved Hide resolved
@@ -240,26 +240,35 @@

bn, err := ob.btcClient.GetBlockCount()
if err != nil {
ob.logger.Chain.Error().Err(err).Msg("RPC status check: RPC down? ")
ob.logger.Chain.Error().Err(err).Msg("RPC status check failed: GetBlockCount")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add unit tests for WatchRPCStatus.

The static analysis hints indicate that the added lines in the WatchRPCStatus function are not covered by tests. To ensure the correctness of the RPC status checks and error handling, consider adding unit tests for this function.

Some test cases to consider:

  1. Test successful RPC status check with valid block and TSS address details.
  2. Test error handling for each failed RPC call (GetBlockCount, GetBlockHash, GetBlockHeader, ListUnspentMinMaxAddresses).
  3. Test error handling for old blocks and missing TSS address UTXOs.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

Also applies to: 249-251, 257-260, 265-271, 292-297

Tools
GitHub Check: codecov/patch

[warning] 243-243: zetaclient/chains/bitcoin/observer/observer.go#L243
Added line #L243 was not covered by tests

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

@gartnera
Copy link
Member Author

superseded by #2751 which does at least add more descriptive error messages.

@gartnera gartnera closed this Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants