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

Add block/tx indexed metrics and spork client logging #595

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

peterargue
Copy link
Contributor

@peterargue peterargue commented Sep 27, 2024

Closes: #???

Description

Add metrics for block and transaction indexing. Also add logging for the spork client block ranges on startup.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Introduced a method for tracking the indexing of EVM transactions.
    • Enhanced functionality to record the number of transactions processed in the event handling.
    • Added logging capabilities for spork client additions.
  • Bug Fixes

    • Improved clarity in test case naming for better understanding.
  • Tests

    • Updated test cases to accommodate the new logging parameter in spork client methods.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Warning

Rate limit exceeded

@janezpodhostnik has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 0f3bfdb and 94f727f.

Walkthrough

The changes in this pull request enhance the functionality of the metrics collector by introducing a new method for tracking EVM transactions and updating existing methods to increment counters accordingly. The Collector interface is modified to include the new method, and corresponding counters are added to the DefaultCollector struct. Additionally, other components are updated to utilize the new functionality, including the nopCollector and the event processing logic in the Engine struct.

Changes

File Change Summary
metrics/collector.go, metrics/nop.go Added EVMTransactionIndexed(count int) method to the Collector interface and nopCollector struct. Introduced evmBlockIndexedCounter and evmTxIndexedCounter in DefaultCollector.
services/ingestion/engine.go Updated processEvents method to include a call to e.collector.EVMTransactionIndexed(len(events.Transactions())) for tracking indexed transactions.
services/requester/cross-spork_client.go Modified add method of sporkClients to include a logger parameter for enhanced logging when adding new spork clients.
services/requester/cross-spork_client_test.go Updated test cases in Test_CrossSporkClients to reflect changes in the add method requiring a logger parameter.

Possibly related PRs

  • Add metric for indexed cadence block height #571: The changes in this PR introduce a new method for indexing cadence block heights in the Collector interface, which is directly related to the modifications made in the main PR that also enhance the metrics collector's functionality.

Suggested labels

Improvement, EVM

Suggested reviewers

  • sideninja

Poem

In the meadow where metrics grow,
A rabbit hops with joy, you know!
EVM transactions now in sight,
Counting blocks with all its might.
With each new method, we shall cheer,
For data's dance is finally here! 🐇✨


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 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.

CodeRabbit Configuration 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

@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

🧹 Outside diff range and nitpick comments (5)
metrics/nop.go (1)

20-20: LGTM! Consider adding a comment for clarity.

The new EVMTransactionIndexed method is consistent with the existing no-op implementation pattern and aligns well with the PR objectives for adding transaction indexed metrics.

Consider adding a brief comment to explain the purpose of the int parameter, e.g.:

// EVMTransactionIndexed records the number of EVM transactions indexed
func (c *nopCollector) EVMTransactionIndexed(count int) {}

This would improve code readability and maintain consistency with any existing documentation practices in the project.

services/requester/cross-spork_client_test.go (1)

45-47: LGTM: Updated add method calls with logger parameter.

The changes correctly implement the new method signature for add, including the logger parameter. The order of client additions remains unchanged, which is crucial for testing the sorting functionality.

Consider extracting the logger parameter into a variable for better readability:

-		require.NoError(t, clients.add(logger, client2))
-		require.NoError(t, clients.add(logger, client3))
-		require.NoError(t, clients.add(logger, client1))
+		addClient := func(client Client) {
+			require.NoError(t, clients.add(logger, client))
+		}
+		addClient(client2)
+		addClient(client3)
+		addClient(client1)

This change would make the test more concise and easier to maintain if additional parameters are added in the future.

metrics/collector.go (1)

153-154: LGTM with a minor suggestion: Update EVMHeightIndexed method.

The addition of c.evmBlockIndexedCounter.Inc() correctly increments the counter for each indexed block. This change enhances the tracking capabilities as intended.

Consider updating the method name to reflect its dual purpose, e.g., EVMHeightIndexedAndCounted. Alternatively, add a comment explaining that this method both updates the current height and increments the total block count.

services/requester/cross-spork_client.go (1)

Line range hint 31-46: LGTM! Consider adding error logging.

The changes to the add method improve observability by adding logging for the spork client's first and last heights. This aligns well with the PR objectives.

Consider adding error logging before returning errors. For example:

 if err != nil {
+    logger.Error().Err(err).Msg("failed to get latest block header")
     return fmt.Errorf("could not get latest height using the spork client: %w", err)
 }

This would provide more context in case of failures.

services/ingestion/engine.go (1)

209-211: Consider grouping related metric collections

The addition of the EVM transaction indexing metric enhances the system's observability without introducing complexity or altering the existing logic. It aligns well with the file's purpose and structure.

For improved readability and maintainability, consider grouping related metric collections together. You might want to move the new EVMTransactionIndexed call next to the EVMHeightIndexed call:

e.collector.EVMHeightIndexed(events.Block().Height)
e.collector.EVMTransactionIndexed(len(events.Transactions()))
e.collector.CadenceHeightIndexed(events.CadenceHeight())

This grouping would make it easier to understand and maintain related metrics in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e3e44ae and 0f3bfdb.

📒 Files selected for processing (5)
  • metrics/collector.go (6 hunks)
  • metrics/nop.go (1 hunks)
  • services/ingestion/engine.go (1 hunks)
  • services/requester/cross-spork_client.go (3 hunks)
  • services/requester/cross-spork_client_test.go (2 hunks)
🔇 Additional comments (14)
metrics/nop.go (1)

Line range hint 1-24: Overall, the changes look good and align with the PR objectives.

The addition of the EVMTransactionIndexed method to the nopCollector struct is consistent with the existing implementation pattern and supports the goal of adding transaction indexed metrics. The change is minimal, focused, and doesn't introduce any issues.

services/requester/cross-spork_client_test.go (3)

37-37: LGTM: Logger initialization added.

The addition of the logger variable using zerolog.Nop() is appropriate for test scenarios. This change aligns with the updated method signature of add mentioned in the summary.


62-62: LGTM: Test case name improved and add method calls updated.

The changes in this test case are appropriate:

  1. The test case name has been corrected from "not-continues" to "not-continuous", improving clarity.
  2. The clients.add() calls have been correctly updated with the new logger parameter, consistent with the changes in the first test case.

These modifications enhance the test's readability and align with the updated method signature.

Also applies to: 68-69


Line range hint 37-69: Summary: Successful integration of logger parameter in CrossSporkClients tests.

The changes in this file successfully integrate the new logger parameter into the CrossSporkClients tests. Key points:

  1. A logger variable is properly initialized using zerolog.Nop().
  2. All clients.add() calls are updated to include the logger parameter.
  3. The test case for non-continuous validation has an improved name.

These modifications align well with the PR objectives of enhancing logging capabilities. The tests now accurately reflect the updated method signature of the add function, ensuring that the CrossSporkClient's behavior with the new logging feature is properly validated.

To ensure consistency across the codebase, let's verify the usage of the updated add method:

This script will help identify any locations where the add method might still be called without the logger parameter, ensuring complete implementation of the logging enhancement.

metrics/collector.go (7)

18-18: LGTM: New method for tracking indexed EVM transactions.

The addition of EVMTransactionIndexed(count int) to the Collector interface is well-designed and aligns with the PR objectives. It allows for efficient tracking of multiple indexed transactions at once.


33-34: LGTM: New counters for EVM block and transaction indexing.

The addition of evmBlockIndexedCounter and evmTxIndexedCounter to the DefaultCollector struct is appropriate. These prometheus counters will effectively track the cumulative number of indexed blocks and transactions, enhancing the monitoring capabilities as per the PR objectives.


71-79: LGTM: Proper initialization of new counters.

The initialization of evmBlockIndexedCounter and evmTxIndexedCounter is well-implemented. The metric names and help descriptions are clear, consistent, and follow Prometheus naming conventions.


99-100: LGTM: New counters added to metrics slice.

The evmBlockIndexedCounter and evmTxIndexedCounter are correctly added to the metrics slice. This ensures they will be properly registered with Prometheus for monitoring.


116-117: LGTM: New counters properly assigned in DefaultCollector initialization.

The evmBlockIndexedCounter and evmTxIndexedCounter are correctly assigned to the corresponding struct fields in the DefaultCollector initialization. This ensures that these counters can be used within the collector's methods.


156-157: LGTM: Efficient implementation of EVMTransactionIndexed method.

The EVMTransactionIndexed method is implemented correctly, using Add(float64(count)) to increment the counter by the given number of transactions. This approach is efficient and aligns well with the PR objectives for tracking indexed transactions.


Line range hint 1-180: Overall assessment: Well-implemented enhancements to metrics collection.

The changes in this file successfully implement the new metrics for EVM block and transaction indexing, aligning perfectly with the PR objectives. The code is well-structured, follows Go best practices, and integrates smoothly with the existing codebase. The new counters and methods enhance the monitoring capabilities of the Flow EVM Gateway, particularly for block and transaction processing.

A minor suggestion was made to improve the clarity of the EVMHeightIndexed method, but this doesn't impact the functionality. Great job on these improvements!

services/requester/cross-spork_client.go (2)

121-121: LGTM! Consistent with the add method update.

The change to pass the logger to the add method is consistent with the updated method signature and ensures proper logging for each past spork client.


Line range hint 1-224: Overall, the changes effectively improve logging capabilities.

The modifications to this file successfully implement the PR objectives by:

  1. Adding logging capabilities to the add method of sporkClients.
  2. Ensuring consistent usage of the logger throughout the file.

These changes enhance the observability of spork client operations, particularly during the addition of new spork clients, without altering the core functionality. This improvement will aid in monitoring and debugging block and transaction processing within the system.

services/ingestion/engine.go (1)

209-209: LGTM: Metric addition aligns with PR objectives

The added line e.collector.EVMTransactionIndexed(len(events.Transactions())) successfully implements the PR objective of adding transaction indexed metrics. This change enhances the observability of the EVM Gateway by tracking the number of indexed transactions, complementing the existing metrics for EVM and Cadence heights.

The placement and implementation are consistent with the existing code structure and other metric collection calls. This addition will provide valuable insights into the transaction processing within the system.

Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

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

LGTM! 💯

@janezpodhostnik janezpodhostnik requested review from janezpodhostnik and removed request for sideninja October 2, 2024 15:13
@franklywatson franklywatson merged commit f487008 into main Oct 2, 2024
2 checks passed
@franklywatson franklywatson deleted the petera/add-indexer-metrics branch October 2, 2024 16:13
@coderabbitai coderabbitai bot mentioned this pull request Oct 17, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants