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 cadence mtric collection on empty block as well #589

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

peterargue
Copy link
Contributor

@peterargue peterargue commented Sep 25, 2024

Closes: #???

Description

Related to #571

I missed collecting metrics when the cadence block does not include a evm block.


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

    • Enhanced event processing to record cadence height for heartbeat events without payloads.
  • Bug Fixes

    • Improved reliability of event handling within the ingestion engine.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

A new line of code has been added to the processEvents method of the Engine struct in the services/ingestion/engine.go file. This line invokes the CadenceHeightIndexed method on the collector field, using the cadence height obtained from the events parameter. This modification occurs just before the method returns nil, enabling the recording of cadence height for heartbeat events without event payloads.

Changes

File Path Change Summary
services/ingestion/engine.go Modified the processEvents method to include a call to CadenceHeightIndexed using the cadence height from events.

Possibly related PRs

  • Add metric for indexed cadence block height #571: The changes in this PR involve adding a call to CadenceHeightIndexed in the processEvents method of the Engine struct, which directly relates to the new line of code added in the main PR that also calls CadenceHeightIndexed.

Suggested labels

Improvement, EVM

Suggested reviewers

  • sideninja

Poem

In the engine's heart, a new line sings,
A cadence height, oh what joy it brings!
With every event, we gather the score,
Recording the rhythm, forevermore.
Hopping along, we celebrate this feat,
In the world of code, our hearts skip a beat! 🐇✨


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.

@@ -161,6 +161,7 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error {
err,
)
}
e.collector.CadenceHeightIndexed(events.CadenceHeight())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems that blocks.SetLatestCadenceHeight() is only called when the events is empty. If we ever end up with a large string of evm blocks in a row, this would never get saved, possibly resulting in the node having to reindex all of the block if it crash. Should we always set it?

https://github.com/onflow/flow-evm-gateway/blob/petera/570-add-cadence-height-metric2/services/ingestion/engine.go#L157

Copy link
Collaborator

Choose a reason for hiding this comment

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

We actually do set the latest indexed Cadence height, but we do so every time we store an EVM block, in: https://github.com/onflow/flow-evm-gateway/blob/main/storage/pebble/blocks.go#L99-L105.

Calling blocks.SetLatestCadenceHeight() when the events is empty, is just an optimization from the early days, where there was no 1:1 mapping between EVM <-> Flow blocks.

Right now, the only way to have no EVM block for a Flow block, is when the system chunk transaction fails to run(https://github.com/onflow/flow-go/blob/4668c5d997b1e40af65e9a9510e3a3654763e330/fvm/blueprints/scripts/systemChunkTransactionTemplate.cdc#L22-L25). There was one such incident a couple weeks ago, but now we have some backup mechanisms in place, to guard against that.

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 (1)
services/ingestion/engine.go (1)

Line range hint 153-157: Minor: Standardize error message formatting

For consistency in error message formatting, consider using the same style throughout the method. Currently, there's a slight difference in how errors are formatted. For example:

// Current
return fmt.Errorf(
    "failed to update to latest cadence height: %d, during events ingestion: %w",
    events.CadenceHeight(),
    err,
)

// vs

// Current
return fmt.Errorf("failed to index block %d event: %w", events.Block().Height, err)

Consider standardizing to the multi-line format for improved readability:

// Suggested
return fmt.Errorf(
    "failed to index block %d event: %w",
    events.Block().Height,
    err,
)

This is a minor nitpick and doesn't affect functionality.

Also applies to: 176-180

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d5b8984 and ade34fd.

📒 Files selected for processing (1)
  • services/ingestion/engine.go (1 hunks)
🔇 Additional comments not posted (2)
services/ingestion/engine.go (2)

Line range hint 1-300: Summary: PR objectives met, code change looks good

The implemented change successfully addresses the PR objective of adding cadence metric collection for empty blocks. The addition is well-placed and consistent with the existing code structure.

A minor suggestion was made to standardize error message formatting for improved consistency, but this doesn't affect the functionality of the code.

Overall, the changes look good and ready for merging, pending any additional reviews or tests as per your team's process.


164-164: LGTM! Metric collection added for empty blocks.

The addition of e.collector.CadenceHeightIndexed(events.CadenceHeight()) for empty events (heartbeat events) aligns well with the PR objective. This ensures that cadence metrics are collected consistently, even when there's no associated EVM block.

To ensure consistency, let's verify that CadenceHeightIndexed is called in all relevant places:

✅ Verification successful

Verification Complete: CadenceHeightIndexed is consistently called in processEvents.

The CadenceHeightIndexed method is appropriately invoked within the processEvents method in services/ingestion/engine.go. No inconsistencies or additional unexpected usages were found in other parts of the codebase, ensuring that cadence metrics are collected as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent usage of CadenceHeightIndexed

# Test: Search for all occurrences of CadenceHeightIndexed
echo "Occurrences of CadenceHeightIndexed:"
rg --type go "CadenceHeightIndexed" -A 3

# Test: Verify that CadenceHeightIndexed is called in all processEvents scenarios
echo "\nVerifying CadenceHeightIndexed calls in processEvents:"
rg --type go "func \(e \*Engine\) processEvents" -A 50 | rg "CadenceHeightIndexed"

Length of output: 1657

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!

@peterargue peterargue merged commit e7a47eb into main Sep 26, 2024
2 checks passed
@peterargue peterargue deleted the petera/570-add-cadence-height-metric2 branch September 26, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants