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

refactor(zetaclient): move rpc latency logs to metrics #3313

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 17, 2024

Remove all "rpc latency" logs and move them to metrics instead. We definitely prefer to set alert thresholds in the monitoring stack rather than in a config file.

Closes #3292

Summary by CodeRabbit

  • New Features
    • Introduced a new gauge metric, LatestBlockLatency, for tracking the latency of the last block across observed chains.
  • Bug Fixes
    • Enhanced error handling and logging for observer and signer synchronization processes.
  • Refactor
    • Removed the rpcAlertLatency parameter from various observer initialization functions, simplifying the observer's configuration.
  • Documentation
    • Updated comments in methods to reflect changes in functionality related to latency reporting.
  • Tests
    • Adjusted test cases to remove references to the rpcAlertLatency parameter and ensure consistent observer initialization.

@gartnera gartnera added the no-changelog Skip changelog CI check label Dec 17, 2024
@gartnera gartnera requested a review from a team December 17, 2024 19:20
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a comprehensive refactoring of RPC latency handling across multiple blockchain observers. The primary focus is transitioning from an alert-based latency mechanism to a metrics-driven approach. This involves removing rpcAlertLatency parameters, introducing a new LatestBlockLatency metric, and replacing alert logic with direct block latency reporting across Bitcoin, EVM, Solana, and TON chain observers.

Changes

File Change Summary
zetaclient/chains/base/observer.go Removed rpcAlertLatency, added ReportBlockLatency method
zetaclient/config/types.go Removed RPCAlertLatency field from configuration structs
zetaclient/metrics/metrics.go Added new LatestBlockLatency gauge metric
Multiple observer files Removed rpcAlertLatency parameter from NewObserver methods

Assessment against linked issues

Objective Addressed Explanation
Move RPC block latency logs to metrics Introduced LatestBlockLatency metric for tracking block latency
Enable tunable observability parameters Metrics can now be configured and alerted on externally

Suggested Labels

performance, metrics, observability

Suggested Reviewers

The implementation elegantly transforms RPC latency monitoring from a localized alert system to a centralized, configurable metrics approach, enhancing system observability and flexibility.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 61.63%. Comparing base (6730285) to head (0e7f610).

Files with missing lines Patch % Lines
zetaclient/chains/base/observer.go 0.00% 2 Missing ⚠️
zetaclient/chains/bitcoin/observer/rpc_status.go 0.00% 1 Missing ⚠️
zetaclient/chains/evm/observer/rpc_status.go 0.00% 1 Missing ⚠️
zetaclient/chains/solana/observer/rpc_status.go 0.00% 1 Missing ⚠️
zetaclient/chains/ton/observer/observer.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3313      +/-   ##
===========================================
- Coverage    61.67%   61.63%   -0.05%     
===========================================
  Files          433      433              
  Lines        31011    30981      -30     
===========================================
- Hits         19126    19095      -31     
- Misses       11026    11027       +1     
  Partials       859      859              
Files with missing lines Coverage Δ
zetaclient/chains/bitcoin/observer/observer.go 26.84% <ø> (-0.25%) ⬇️
zetaclient/chains/evm/observer/observer.go 69.03% <ø> (-0.20%) ⬇️
zetaclient/chains/solana/observer/observer.go 42.64% <ø> (-0.84%) ⬇️
zetaclient/config/config_chain.go 100.00% <100.00%> (ø)
zetaclient/config/types.go 50.64% <ø> (ø)
zetaclient/metrics/metrics.go 69.64% <ø> (ø)
zetaclient/orchestrator/bootstrap.go 58.30% <ø> (-0.50%) ⬇️
zetaclient/chains/bitcoin/observer/rpc_status.go 0.00% <0.00%> (ø)
zetaclient/chains/evm/observer/rpc_status.go 0.00% <0.00%> (ø)
zetaclient/chains/solana/observer/rpc_status.go 0.00% <0.00%> (ø)
... and 2 more

@gartnera gartnera force-pushed the zetaclient-remove-rpc-latency-logs branch from 8b857e6 to 0e7f610 Compare December 17, 2024 19:41
@gartnera gartnera marked this pull request as ready for review December 17, 2024 19:49
@gartnera gartnera requested a review from a team as a code owner December 17, 2024 19:49
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: 1

🧹 Nitpick comments (4)
zetaclient/chains/evm/observer/rpc_status.go (1)

39-39: Consider enhancing log context for better observability

While the transition to metrics is correct, consider adding debug logs to provide additional context about the latency being reported.

+	ob.Logger().Chain.Debug().Dur("block_latency", blockTime).Msg("EVM block latency reported")
 	ob.ReportBlockLatency(blockTime)
zetaclient/chains/bitcoin/observer/rpc_status.go (1)

Line range hint 11-11: Remove unused context parameter

The context parameter is marked as unused with _. If context isn't needed, consider removing it from the method signature.

-func (ob *Observer) watchRPCStatus(_ context.Context) error {
+func (ob *Observer) watchRPCStatus() error {
zetaclient/chains/solana/observer/rpc_status.go (1)

43-43: Consider enhancing log context for better observability

While the transition to metrics is correct, consider adding debug logs to provide additional context about the latency being reported, including the privnet status.

+	ob.Logger().Chain.Debug().
+		Dur("block_latency", blockTime).
+		Bool("is_privnet", privnet).
+		Msg("Solana block latency reported")
 	ob.ReportBlockLatency(blockTime)
zetaclient/chains/base/observer.go (1)

427-432: Consider enhancing method documentation.

While the implementation is correct, the documentation could be more specific about the time units being reported (seconds).

Consider updating the comment to:

-// ReportBlockLatency records the latency between the current time
-// an the latest block time for a chain as a metric
+// ReportBlockLatency records the latency in seconds between the current time
+// and the latest block time for a chain as a metric
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6730285 and 0e7f610.

📒 Files selected for processing (22)
  • zetaclient/chains/base/observer.go (1 hunks)
  • zetaclient/chains/base/observer_test.go (25 hunks)
  • zetaclient/chains/bitcoin/observer/observer.go (0 hunks)
  • zetaclient/chains/bitcoin/observer/observer_test.go (0 hunks)
  • zetaclient/chains/bitcoin/observer/outbound_test.go (1 hunks)
  • zetaclient/chains/bitcoin/observer/rpc_status.go (1 hunks)
  • zetaclient/chains/evm/observer/observer.go (0 hunks)
  • zetaclient/chains/evm/observer/observer_test.go (0 hunks)
  • zetaclient/chains/evm/observer/rpc_status.go (1 hunks)
  • zetaclient/chains/evm/signer/signer_test.go (0 hunks)
  • zetaclient/chains/solana/observer/inbound_test.go (2 hunks)
  • zetaclient/chains/solana/observer/observer.go (0 hunks)
  • zetaclient/chains/solana/observer/observer_test.go (0 hunks)
  • zetaclient/chains/solana/observer/outbound_test.go (1 hunks)
  • zetaclient/chains/solana/observer/rpc_status.go (1 hunks)
  • zetaclient/chains/ton/observer/observer.go (1 hunks)
  • zetaclient/chains/ton/observer/observer_test.go (0 hunks)
  • zetaclient/config/config_chain.go (2 hunks)
  • zetaclient/config/types.go (1 hunks)
  • zetaclient/metrics/metrics.go (1 hunks)
  • zetaclient/orchestrator/bootstap_test.go (1 hunks)
  • zetaclient/orchestrator/bootstrap.go (0 hunks)
💤 Files with no reviewable changes (9)
  • zetaclient/chains/evm/signer/signer_test.go
  • zetaclient/chains/ton/observer/observer_test.go
  • zetaclient/chains/solana/observer/observer_test.go
  • zetaclient/chains/bitcoin/observer/observer_test.go
  • zetaclient/chains/evm/observer/observer.go
  • zetaclient/chains/evm/observer/observer_test.go
  • zetaclient/chains/bitcoin/observer/observer.go
  • zetaclient/chains/solana/observer/observer.go
  • zetaclient/orchestrator/bootstrap.go
✅ Files skipped from review due to trivial changes (1)
  • zetaclient/config/config_chain.go
🧰 Additional context used
📓 Path-based instructions (12)
zetaclient/chains/solana/observer/rpc_status.go (1)

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

zetaclient/chains/evm/observer/rpc_status.go (1)

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

zetaclient/chains/solana/observer/outbound_test.go (1)

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

zetaclient/metrics/metrics.go (1)

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

zetaclient/config/types.go (1)

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

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

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

zetaclient/orchestrator/bootstap_test.go (1)

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

zetaclient/chains/solana/observer/inbound_test.go (1)

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

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

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

zetaclient/chains/base/observer_test.go (1)

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

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

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

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

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

🔇 Additional comments (9)
zetaclient/chains/ton/observer/observer.go (1)

189-189: LGTM: Successfully migrated to metrics-based latency reporting.

The change aligns with the PR objective of moving from alert-based to metrics-based latency monitoring.

zetaclient/chains/solana/observer/inbound_test.go (1)

75-75: LGTM: Successfully removed deprecated RPC alert latency parameter.

The test modifications correctly align with the observer's new initialization signature, maintaining the same test coverage and functionality.

Also applies to: 116-116

zetaclient/config/types.go (2)

41-41: LGTM: Configuration types updated to reflect metrics-based approach.

The removal of RPCAlertLatency fields and reorganization of BTCConfig fields improve code clarity while maintaining all necessary configuration options.

Also applies to: 47-50, 55-55


41-41: Verify complete removal of RPCAlertLatency references.

Let's ensure all references to the removed configuration fields have been updated.

zetaclient/metrics/metrics.go (1)

82-88: LGTM: Well-structured metric definition.

The new LatestBlockLatency metric follows the established patterns and naming conventions, with clear documentation and appropriate metric type selection (GaugeVec).

zetaclient/orchestrator/bootstap_test.go (1)

219-219: LGTM: Clean removal of deprecated config.

The removal of RPCAlertLatency from the TON configuration aligns with the transition to metrics-based latency monitoring while maintaining comprehensive test coverage.

zetaclient/chains/base/observer_test.go (1)

Line range hint 39-61: LGTM: Test suite initialization refactored correctly.

The removal of the alertLatency parameter aligns with the PR objective of moving RPC latency handling to metrics. The test suite initialization remains clean and maintains all essential parameters.

zetaclient/chains/solana/observer/outbound_test.go (1)

64-64: LGTM: Observer initialization aligned with new signature.

The removal of the timeout parameter is consistent with the broader refactoring effort to simplify observer initialization and move latency handling to metrics.

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

46-46: LGTM: Bitcoin observer initialization updated correctly.

The removal of the hardcoded timeout value (60) aligns with the PR's objective of transitioning RPC latency handling to metrics.

@@ -41,6 +41,5 @@
return
}

// alert if RPC latency is too high
ob.AlertOnRPCLatency(blockTime, rpc.RPCAlertLatency)
ob.ReportBlockLatency(blockTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider propagating context for better cancellation support

The RPC status check could benefit from context propagation for proper cancellation handling.

-func (ob *Observer) checkRPCStatus() {
+func (ob *Observer) checkRPCStatus(ctx context.Context) {
 	tssAddress, err := ob.TSS().PubKey().AddressBTC(ob.Chain().ChainId)
 	if err != nil {
 		ob.Logger().Chain.Error().Err(err).Msg("unable to get TSS BTC address")
 		return
 	}
 
-	blockTime, err := rpc.CheckRPCStatus(ob.btcClient, tssAddress)
+	blockTime, err := rpc.CheckRPCStatus(ctx, ob.btcClient, tssAddress)

Committable suggestion skipped: line range outside the PR's diff.

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.

zetaclient: move rpc latency logs to metrics
1 participant