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

feat(op-service): complete separation of op-node/op-service metrics #10545

Merged
merged 1 commit into from
May 16, 2024

Conversation

hamdiallam
Copy link
Contributor

@hamdiallam hamdiallam commented May 14, 2024

client.RPC & client.Client are unusable outside of op-node as the instrumented versions contain dependencies on op-node metrics.

  • integrate general op-service rpc metrics into the instrumented clients
  • Add a Client#RPC() method allowing a caller to get a instrumented RPC instance from the instrumented eth client.
  • Split the op-service rpc metrics into both client/server metrics. Not every user of op-service will require both. Instrumented clients should only require the client metrics
  • Include testutils mocks for client.RPC and client.Client

@hamdiallam hamdiallam requested a review from a team as a code owner May 14, 2024 22:12
@hamdiallam hamdiallam requested a review from Inphi May 14, 2024 22:12
Copy link
Contributor

coderabbitai bot commented May 14, 2024

Walkthrough

Walkthrough

The recent changes focus on consolidating and refactoring the metrics handling within the op-node and op-service packages. Key modifications include merging constants to streamline code, updating function arguments to use refined metrics structures, and introducing new interfaces and methods for enhanced RPC client and server metrics tracking. Additionally, mock implementations for testing purposes have been added to the testutils package.

Changes

File(s) Change Summary
op-node/metrics/metrics.go Consolidated constants Namespace and BatchMethod into a single constant Namespace.
op-node/node/node.go Modified initL1 and initL2 functions to use &n.metrics.RPCMetrics.RPCClientMetrics.
op-service/client/client.go Refactored InstrumentedClient to use RPCClientMetrics and added new methods and function signatures.
op-service/client/rpc.go Updated imports and function signatures to use RPCClientMetrics.
op-service/metrics/rpc_metrics.go Introduced RPCClientMetricer and RPCServerMetricer interfaces, and restructured RPCMetrics struct.
op-service/testutils/mock_client.go, mock_rpc.go Added mock implementations for client.Client and client.RPC interfaces for testing purposes.

Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between db3871d and b9378bd.
Files selected for processing (7)
  • op-node/metrics/metrics.go (1 hunks)
  • op-node/node/node.go (2 hunks)
  • op-service/client/client.go (3 hunks)
  • op-service/client/rpc.go (3 hunks)
  • op-service/metrics/rpc_metrics.go (4 hunks)
  • op-service/testutils/mock_client.go (1 hunks)
  • op-service/testutils/mock_rpc.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • op-node/metrics/metrics.go
Additional comments not posted (2)
op-node/node/node.go (2)

178-178: Update the argument passed to client.NewInstrumentedRPC.

The change to use &n.metrics.RPCMetrics.RPCClientMetrics instead of n.metrics is correct and aligns with the refactoring to separate RPC metrics for op-node and op-service.


374-374: Update the argument passed to client.NewInstrumentedRPC.

The change to use &n.metrics.RPCMetrics.RPCClientMetrics instead of n.metrics is correct and aligns with the refactoring to separate RPC metrics for op-node and op-service.


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.

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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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
Contributor Author

hamdiallam commented May 14, 2024

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: 0

Out of diff range and nitpick comments (30)
op-service/testutils/mock_rpc.go (6)

20-22: Ensure that the Close method is properly tested to verify that it correctly calls the mock's Called method.


28-31: Consider adding more detailed comments to explain the purpose of the CallContext method and how the mock's Called method is used to simulate the behavior.


37-40: Ensure that the BatchCallContext method is properly tested to verify that it correctly handles batch calls and returns the appropriate error.


62-65: Ensure that the EthSubscribe method is properly tested to verify that it correctly handles subscriptions and returns the appropriate subscription and error.


33-35: Consider adding more detailed comments to explain the purpose of the ExpectCallContext method and how the mock's On method is used to set expectations for the CallContext method.


42-60: Ensure that the ExpectBatchCallContext method is properly tested to verify that it correctly sets expectations for batch calls and handles the mutation of arguments.

op-service/metrics/rpc_metrics.go (8)

33-39: Ensure that the RPCClientMetrics struct is properly tested to verify that it correctly tracks client RPC metrics using Prometheus counters and histograms.


41-44: Ensure that the RPCServerMetrics struct is properly tested to verify that it correctly tracks server RPC metrics using Prometheus counters and histograms.


46-50: Ensure that the RPCMetrics struct is properly tested to verify that it correctly combines both client and server metrics.


Line range hint 161-171: Ensure that the NoopRPCMetrics struct is properly tested to verify that it correctly implements the RPCMetricer interface with no-op methods.


52-58: Ensure that the MakeRPCMetrics function is properly tested to verify that it correctly creates and initializes an RPCMetrics instance with the given namespace and factory.


Line range hint 60-93: Ensure that the MakeRPCClientMetrics function is properly tested to verify that it correctly creates and initializes an RPCClientMetrics instance with the given namespace and factory.


128-149: Ensure that the MakeRPCServerMetrics function is properly tested to verify that it correctly creates and initializes an RPCServerMetrics instance with the given namespace and factory.


Line range hint 110-127: Consider adding more detailed comments to explain the purpose of the RecordRPCClientResponse function and how it converts errors into metrics-friendly strings.

op-service/client/rpc.go (7)

Line range hint 173-187: Ensure that the BaseRPCClient struct is properly tested to verify that it correctly wraps an rpc.Client instance and sets appropriate timeouts for RPC calls.


188-191: Ensure that the InstrumentedRPCClient struct is properly tested to verify that it correctly tracks Prometheus metrics for each RPC call.


Line range hint 25-28: Consider adding more detailed comments to explain the purpose of the rpcConfig struct and how its fields are used to configure RPC clients.


Line range hint 75-91: Ensure that the NewRPC function is properly tested to verify that it correctly creates and configures an RPC client with the given options.


Line range hint 94-99: Ensure that the NewRPCWithClient function is properly tested to verify that it correctly wraps an existing RPC client with additional functionality, such as polling.


Line range hint 102-122: Ensure that the dialRPCClientWithBackoff function is properly tested to verify that it correctly handles dialing an RPC endpoint with exponential backoff.


Line range hint 224-237: Consider adding more detailed comments to explain the purpose of the instrumentBatch function and how it tracks metrics for batch RPC calls.

op-service/client/client.go (3)

57-69: Ensure that the InstrumentedClient struct is properly tested to verify that it correctly tracks Prometheus metrics for each Ethereum client call.


Line range hint 17-53: Consider adding more detailed comments to explain the purpose of the Client interface and how its methods are used for various blockchain-related operations.


65-69: Ensure that the NewInstrumentedClient function is properly tested to verify that it correctly creates and initializes an InstrumentedClient instance with the given RPC client and metrics.

op-service/testutils/mock_client.go (6)

22-24: Ensure that the Close method is properly tested to verify that it correctly calls the mock's Called method.


30-33: Consider adding more detailed comments to explain the purpose of the RPC method and how the mock's Called method is used to simulate the behavior.


39-42: Ensure that the ChainID method is properly tested to verify that it correctly returns the expected chain ID and error.


48-51: Ensure that the BlockByHash method is properly tested to verify that it correctly returns the expected block and error.


102-105: Ensure that the TransactionByHash method is properly tested to verify that it correctly returns the expected transaction, pending status, and error.


273-276: Ensure that the CallContract method is properly tested to verify that it correctly returns the expected result and error.

@hamdiallam hamdiallam enabled auto-merge May 14, 2024 22:33
@hamdiallam hamdiallam changed the title feat(op-service): separate op-node/op-service rpc metrics. include client mocks feat(op-service): complete separation of op-node/op-service metrics May 15, 2024
Copy link
Contributor

@protolambda protolambda left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work

@hamdiallam hamdiallam added this pull request to the merge queue May 16, 2024
Merged via the queue into develop with commit 861fbc0 May 16, 2024
69 checks passed
@hamdiallam hamdiallam deleted the op-service.client.metrics branch May 16, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants