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 metric for indexed cadence block height #571

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

peterargue
Copy link
Contributor

@peterargue peterargue commented Sep 24, 2024

Closes: #570

Description

Add metric for latest cadence block height


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 new method to index Cadence block heights, enhancing metrics collection capabilities.
    • Added functionality to the event processing engine to track Cadence heights alongside existing metrics.
  • Bug Fixes

    • Improved the handling of Cadence height events in the metrics collector.

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes introduce a new method, CadenceHeightIndexed, to the Collector interface and its implementation in metrics/collector.go, allowing for the tracking of Cadence block heights. A corresponding gauge, cadenceBlockHeight, is added to monitor this metric. Additionally, the nopCollector in metrics/nop.go is updated to include the new method. The processEvents method in services/ingestion/engine.go is modified to call the new method, enabling the indexing of Cadence heights during event processing.

Changes

Files Change Summary
metrics/collector.go Added method CadenceHeightIndexed(height uint64) to Collector interface; introduced cadenceBlockHeight gauge in DefaultCollector.
metrics/nop.go Added method CadenceHeightIndexed(uint64) to nopCollector struct.
services/ingestion/engine.go Modified processEvents method to call e.collector.CadenceHeightIndexed(events.CadenceHeight()).

Assessment against linked issues

Objective Addressed Explanation
Add metric for cadence block height (#570)

🐰 In the meadow where bunnies play,
A new height metric has come to stay.
With cadence tracked, we hop with glee,
Collecting data, as happy as can be!
Metrics grow, our joy is bright,
Hopping high, in the moonlight! 🌙✨


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 (1)
metrics/collector.go (1)

58-61: LGTM with a minor suggestion: Cadence block height gauge initialization

The initialization of the cadenceBlockHeight gauge is correct and consistent with other metrics. It's properly added to the metrics slice for registration.

Consider slightly modifying the help text to be more specific:

-		Help: "Current Cadence block height",
+		Help: "Latest indexed Cadence block height",

This change would more accurately reflect that it's tracking the latest indexed height rather than the current network height.

Also applies to: 84-84

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 888c69d and 7f8a5d5.

Files selected for processing (3)
  • metrics/collector.go (6 hunks)
  • metrics/nop.go (1 hunks)
  • services/ingestion/engine.go (1 hunks)
Additional comments not posted (6)
metrics/nop.go (1)

18-18: LGTM! The new method is correctly implemented.

The addition of CadenceHeightIndexed(uint64) to the nopCollector struct is consistent with the existing implementation and aligns with the PR objectives. The empty implementation is correct for a no-op collector.

Let's verify that the Collector interface has been updated to include this new method:

Verification successful

Verified that the Collector interface includes CadenceHeightIndexed(uint64). No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the Collector interface includes the CadenceHeightIndexed method

# Test: Search for the Collector interface definition
rg --type go -A 20 'type Collector interface'

Length of output: 1224

metrics/collector.go (4)

16-16: LGTM: New method added to track Cadence block height

The addition of CadenceHeightIndexed(height uint64) to the Collector interface is well-placed and consistent with existing methods. This change aligns with the PR objective to introduce a metric for tracking Cadence block height.


30-30: LGTM: New gauge added for Cadence block height

The addition of cadenceBlockHeight prometheus.Gauge to the DefaultCollector struct is appropriate. It uses the correct Prometheus type for tracking a single numerical value and is well-placed among other related metrics.


130-132: LGTM: Implementation of CadenceHeightIndexed method

The implementation of CadenceHeightIndexed is correct and consistent with similar methods in the struct. It properly updates the cadenceBlockHeight gauge with the provided height value.


Line range hint 1-162: Summary: Cadence block height metric successfully implemented

The changes to add a metric for tracking the indexed Cadence block height have been implemented correctly and consistently throughout the file. The new CadenceHeightIndexed method and cadenceBlockHeight gauge are well-integrated into the existing Collector interface and DefaultCollector struct.

The implementation aligns with the PR objectives and follows the established patterns in the codebase. A minor suggestion was made to improve the help text for the new gauge, but overall, the changes are approved and ready for integration.

services/ingestion/engine.go (1)

209-209: LGTM! Verify the CadenceHeightIndexed method implementation.

The addition of e.collector.CadenceHeightIndexed(events.CadenceHeight()) aligns well with the PR objective of adding a metric for indexed cadence block height. This change enhances the monitoring capabilities by tracking both EVM and Cadence block heights.

To ensure the completeness of this change, please run the following script to verify the implementation of the CadenceHeightIndexed method in the Collector interface and its concrete implementations:

This script will help ensure that the CadenceHeightIndexed method is properly defined in the Collector interface and implemented in the necessary structs.

Verification successful

Verified: CadenceHeightIndexed method is properly defined and implemented.

All necessary implementations are in place, and no outstanding issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of CadenceHeightIndexed method

# Test 1: Check if CadenceHeightIndexed is defined in the Collector interface
echo "Checking Collector interface:"
rg --type go "type\s+Collector\s+interface" -A 10 | rg "CadenceHeightIndexed"

# Test 2: Look for implementations of CadenceHeightIndexed
echo "Checking for implementations:"
rg --type go "func\s+\(\w+\s+\*\w+\)\s+CadenceHeightIndexed"

# Test 3: Check for any TODOs or FIXMEs related to CadenceHeightIndexed
echo "Checking for TODOs or FIXMEs:"
rg --type go "(TODO|FIXME).*CadenceHeightIndexed"

Length of output: 626

@@ -206,6 +206,7 @@ func (e *Engine) processEvents(events *models.CadenceEvents) error {
}

e.collector.EVMHeightIndexed(events.Block().Height)
e.collector.CadenceHeightIndexed(events.CadenceHeight())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This processEvents method has a case where it can return early, if a Flow block has no EVM-related events:

// if heartbeat interval with no data still update the cadence height
if events.Empty() {
if err := e.blocks.SetLatestCadenceHeight(events.CadenceHeight(), nil); err != nil {

Maybe we should move the tracking of CadenceHeightIndexed before that condition, if we want to keep track of the fact that we received a response from the event-streaming API.
Right now we use a heartbeatInterval of 1, so we should get a response for every block.

Copy link
Contributor

@sideninja sideninja Sep 25, 2024

Choose a reason for hiding this comment

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

Good point @m-Peter
I think we should change flow EVM GW to expect one evm block for one cadence block, now we kinda generalize the idea so there could be none blocks etc, I think this loose requirement can create more issues than it will solve, if we, one day change this mapping 1:1 we should update the gateway then. I don't think it's still worth generalizing at this point. So this PR can be accepted in the current shape but follow-up PR must be made to make ingesting more strict imho.

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! 👏
Left just a comment/question, regarding the intention of this metric.

@peterargue peterargue merged commit d5b8984 into main Sep 25, 2024
2 checks passed
@peterargue peterargue deleted the petera/570-add-cadence-height-metric branch September 25, 2024 18:26
@peterargue
Copy link
Contributor Author

LGTM! 👏 Left just a comment/question, regarding the intention of this metric.

Oops. I was too fast on the merge and didn't see your comment. I opened #589 to address it.

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.

Add metric for cadence block height
3 participants