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 evm and flow fees metric #428

Conversation

illia-malachyn
Copy link
Contributor

@illia-malachyn illia-malachyn commented Aug 12, 2024

This covers Report fees paid on Flow and EVM side as a metric.

EVM fees (gas) are gathered in the event ingestion.
Flow fees are collected in the requester package only, therefore we will miss some fees paid on the Flow side. This is done intentionally and is a topic to discuss

Depends on onflow/flow-go#6304

Summary by CodeRabbit

  • New Features

    • Enhanced transaction pool to support additional metrics collection for EVM and Flow transactions.
    • Updated collector functionality for improved transaction fee observability.
  • Bug Fixes

    • Adjusted default configuration for metrics server port from 8080 to 8081.
  • Chores

    • Updated dependencies to a forked version for enhanced functionality and maintenance improvements.

Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Warning

Rate limit exceeded

@illia-malachyn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 27 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 afea3c7 and cf92c7b.

Walkthrough

The recent changes enhance the functionality and observability of the system, particularly in transaction processing and metrics collection. Key modifications include the introduction of a new collector parameter in the transaction pool, updates to dependency management, and improvements in fee tracking methods. These enhancements aim to improve performance, accuracy, and integration capabilities within the overall architecture.

Changes

Files Change Summary
bootstrap/bootstrap.go Modified startServer to include a new collector parameter in NewTxPool.
go.mod, tests/go.mod Updated dependencies, replacing github.com/onflow/flow-go with a forked version and adjusting other packages.
metrics/collector.go, metrics/nop.go Introduced new methods for EVM and Flow fee collection in Collector and nopCollector implementations.
services/requester/pool.go, services/ingestion/engine.go Enhanced the TxPool with a collector field and updated the Send method for fee tracking.
services/requester/remote_state.go Renamed AllocateStorageIndex to AllocateSlabIndex, altering its return type and functionality.

Sequence Diagram(s)

sequenceDiagram
    participant Engine
    participant Collector
    participant TxPool
    participant Transaction

    Engine->>Transaction: Process Events
    Transaction->>Engine: From() (Sender Address)
    Engine->>Collector: EVMFeesCollected(Sender, GasUsed, GasPrice)
    Engine->>TxPool: Send(Transaction)
    TxPool->>Collector: FlowFeesCollected(Payer, Events)
Loading

Poem

🐇 In fields of code where rabbits play,
New features hop, they’re here to stay!
Metrics gather, fees align,
A brighter future, oh how divine!
With every change, we leap and bound,
In code’s warm burrow, joy is found! 🌼


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.
    • @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 as 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.

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

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, codebase verification and nitpick comments (1)
metrics/collector.go (1)

24-25: Implement Missing Methods in Collector Interface Implementations

The EVMFeesCollected and FlowFeesCollected methods have not been implemented in any of the structs that use the Collector interface. This oversight could lead to runtime errors if these methods are invoked. Please ensure that these methods are implemented in all relevant structs.

  • Check and update the following files where the Collector interface is used:
    • metrics/nop.go
    • metrics/collector.go
    • api/server.go
    • metrics/handler.go
    • api/debug.go
    • services/requester/pool.go
    • services/traces/engine.go
    • services/ingestion/engine.go
    • services/requester/requester.go
    • api/api.go
Analysis chain

Interface Update: Ensure Consistency with Implementations.

The Collector interface now includes EVMFeesCollected and FlowFeesCollected. Ensure all implementations of this interface are updated accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all implementations of the `Collector` interface are updated with the new methods.

# Test: Search for implementations of the `Collector` interface. Expect: Implementations include the new methods.
ast-grep --lang go --pattern 'type $_ struct { $$$ }' | rg 'Collector'

Length of output: 661


Script:

#!/bin/bash
# Check for the implementation of the new methods EVMFeesCollected and FlowFeesCollected in the identified files.

# Look for the implementation of EVMFeesCollected method in relevant files.
ast-grep --lang go --pattern 'func ($_).EVMFeesCollected($_, $_, $_) { $$$ }' metrics/nop.go metrics/collector.go

# Look for the implementation of FlowFeesCollected method in relevant files.
ast-grep --lang go --pattern 'func ($_).FlowFeesCollected($_, $_) { $$$ }' metrics/nop.go metrics/collector.go

Length of output: 228


Script:

#!/bin/bash
# Search for the implementation of the new methods EVMFeesCollected and FlowFeesCollected across all relevant files.

# Look for the implementation of EVMFeesCollected method in all files where Collector is used.
ast-grep --lang go --pattern 'func ($_).EVMFeesCollected($_, $_, $_) { $$$ }' api/server.go metrics/handler.go api/debug.go services/requester/pool.go services/traces/engine.go services/ingestion/engine.go services/requester/requester.go api/api.go

# Look for the implementation of FlowFeesCollected method in all files where Collector is used.
ast-grep --lang go --pattern 'func ($_).FlowFeesCollected($_, $_) { $$$ }' api/server.go metrics/handler.go api/debug.go services/requester/pool.go services/traces/engine.go services/ingestion/engine.go services/requester/requester.go api/api.go

Length of output: 498

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 45c7454 and 483eb1d.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (8)
  • bootstrap/bootstrap.go (1 hunks)
  • config/config.go (1 hunks)
  • go.mod (3 hunks)
  • metrics/collector.go (4 hunks)
  • metrics/nop.go (2 hunks)
  • services/ingestion/engine.go (1 hunks)
  • services/requester/pool.go (4 hunks)
  • services/requester/remote_state.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • config/config.go
Additional comments not posted (18)
metrics/nop.go (1)

23-24: Methods added to nopCollector are correctly defined.

The EVMFeesCollected and FlowFeesCollected methods are added as no-operations, consistent with the purpose of the nopCollector. Ensure these methods align with the Collector interface requirements.

services/requester/remote_state.go (1)

83-83: Method name and return type change are consistent with functionality.

The renaming from AllocateStorageIndex to AllocateSlabIndex and the change in return type reflect a shift in the storage mechanism. The panic behavior remains appropriate for this read-only function.

services/requester/pool.go (3)

34-34: Collector field correctly added to TxPool.

The addition of the collector field to TxPool is consistent with the goal of enhancing metrics collection. Ensure that this field is properly utilized throughout the TxPool methods.


42-49: Constructor updated to include collector.

The NewTxPool constructor now requires a collector parameter, aligning with the changes to the TxPool struct. Ensure that all instances of NewTxPool are updated accordingly in the codebase.


103-104: Flow fees collection integrated into Send method.

The Send method now collects flow fees using the collector, enhancing the observability of transaction costs. This change is consistent with the PR's objectives.

metrics/collector.go (4)

75-87: Prometheus GaugeVec Initialization: Ensure Proper Labeling.

The evmFees and flowFees metrics are initialized with appropriate labels. Ensure that the labels used are consistent with the rest of the metrics in the system.


156-168: EVM Fees Collection: Check for Precision Loss Handling.

The EVMFeesCollected method calculates gas fees and logs a warning if precision is lost. Ensure that the precision loss handling is adequate and that logging is at the appropriate level.


170-186: Flow Fees Collection: Verify Event Decoding Logic.

The FlowFeesCollected method decodes the FlowFeesDeducted event. Ensure that the event decoding logic is robust and handles all possible errors.


38-39: New Fields in DefaultCollector: Verify Metric Registration.

The addition of evmFees and flowFees as prometheus.GaugeVec types is appropriate for tracking fees. Ensure these metrics are correctly registered and used.

services/ingestion/engine.go (1)

162-165: EVM Fees Collection in Event Processing: Verify Integration.

The addition of EVM fee collection in the processEvents method integrates fee tracking before transaction indexing. Ensure this step does not disrupt the existing processing flow and handles errors appropriately.

bootstrap/bootstrap.go (1)

298-298: Transaction Pool Initialization: Verify Collector Integration.

The addition of collector to the NewTxPool function call suggests enhanced functionality. Ensure that the collector is utilized effectively within the transaction pool and that this change is compatible with existing logic.

go.mod (7)

11-11: Verify compatibility with the updated atree version.

The update to github.com/onflow/atree v0.8.0-rc.5 may introduce changes. Ensure compatibility and check for any breaking changes or new features that need attention.


14-14: Verify compatibility with the updated flow-go-sdk version.

The update to github.com/onflow/flow-go-sdk v1.0.0-preview.47 may introduce changes. Ensure compatibility and check for any breaking changes or new features that need attention.


7-7: Verify the necessity of the AWS SDK dependency.

The addition of github.com/aws/aws-sdk-go-v2 v1.27.0 suggests new functionality related to AWS services. Ensure that this dependency is necessary and correctly integrated within the codebase.


41-41: Verify the necessity of the Smithy Go dependency.

The addition of github.com/aws/smithy-go v1.20.2 as an indirect dependency is likely related to the AWS SDK. Ensure that this dependency is necessary and correctly integrated within the codebase.

Verification successful

Smithy Go Dependency is Justified and Correctly Integrated

The github.com/aws/smithy-go v1.20.2 dependency is necessary and correctly integrated as an indirect dependency. It appears in go.sum, indicating it is used by other dependencies in the project. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the Smithy Go dependency in the codebase.

# Test: Search for usage of Smithy Go. Expect: Relevant code using Smithy Go.
rg --type go $'smithy'

Length of output: 21


Script:

#!/bin/bash
# Description: Check for dependencies that might rely on `smithy-go` in go.mod and go.sum.

# List all dependencies in go.mod that might indirectly require smithy-go.
rg 'require' go.mod

# Check go.sum for any references to smithy-go to see if it is used indirectly.
rg 'smithy-go' go.sum

Length of output: 493


213-213: Verify compatibility with the updated blake3 version.

The update to lukechampine.com/blake3 v1.3.0 may include performance improvements or bug fixes. Ensure compatibility and check for any breaking changes.

Verification successful

No impact from blake3 update found.

The lukechampine.com/blake3 v1.3.0 dependency is not directly or indirectly used in the codebase, indicating that the update does not affect current functionality. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility with the updated `blake3` version.

# Test: Search for `blake3` usage. Expect: No breaking changes or necessary updates.
rg --type go $'blake3'

Length of output: 21


Script:

#!/bin/bash
# Search for import statements of `blake3` to verify if it is used in the codebase.
rg --type go 'import.*blake3' -A 5

# Additionally, search for any indirect usage through other packages.
rg --type go 'blake3' -A 5

Length of output: 63


217-217: Verify the necessity of the flow-go replacement directive.

The replacement of github.com/onflow/flow-go suggests custom modifications or fixes. Ensure that these modifications are necessary and correctly integrated within the codebase.

Verification successful

The flow-go replacement directive is justified.

The replacement of github.com/onflow/flow-go with a custom version is necessary to address specific issues, such as hash calculation fixes and pending upstream issues (e.g., onflow/flow-go#5481). These modifications are crucial for the current functionality of the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and necessity of the `flow-go` replacement directive in the codebase.

# Test: Search for `flow-go` usage. Expect: Justification for the replacement.
rg --type go $'flow-go'

Length of output: 7235


Script:

#!/bin/bash
# Search for comments or documentation that justify the custom `flow-go` version.
rg "flow-go" --type md --type go -A 3 -B 3 | grep -i "custom\|modification\|fix\|feature"

Length of output: 321


12-12: Verify compatibility with the updated cadence version.

The update to github.com/onflow/cadence v1.0.0-preview.44 may introduce changes. Ensure compatibility and check for any breaking changes or new features that need attention.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 483eb1d and afea3c7.

Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
Files selected for processing (3)
  • bootstrap/bootstrap.go (1 hunks)
  • go.mod (1 hunks)
  • tests/go.mod (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bootstrap/bootstrap.go
Additional comments not posted (2)
go.mod (1)

215-215: Verify the use of a forked version of flow-go.

The replacement of github.com/onflow/flow-go with a forked version suggests custom modifications. Ensure these changes are documented and necessary for your project.

tests/go.mod (1)

246-246: Verify the use of a forked version of flow-go in tests.

The replacement of github.com/onflow/flow-go with a forked version in the test environment suggests custom modifications. Ensure these changes are necessary and consistent with the main project.

@sideninja sideninja closed this Aug 28, 2024
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