onflow / flow-evm-gateway

FlowEVM Gateway implements an Ethereum-equivalent JSON-RPC API for EVM clients to use
https://developers.flow.com/evm/about
Apache License 2.0
11 stars 10 forks source link

Integrate prometheus to evm gateway #360

Closed illia-malachyn closed 3 months ago

illia-malachyn commented 4 months ago

Closes: #359

This covers the following requirements:

Measure end-to-end request/response time by method call (track the time taken from the start of a request to the return of the response for each method call to understand relative performance and user experience using percentiles). api_request_duration_seconds_bucket api_request_duration_seconds_bucket{resolver="SendRawTransaction"}

API requests per time interval metric rate(api_request_duration_seconds_count{resolver="SendRawTransaction"}[5m])

API calls by API endpoint (most used to least used calls) sort_desc(sum by(resolver) (rate(api_request_duration_seconds_count{resolver="SendRawTransaction"}[5m])))

API errors should be submitted to a counter metric api_errors_total

Summary by CodeRabbit

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago

[!CAUTION]

Review failed

The pull request is closed.

Walkthrough

These changes integrate Prometheus metrics into the EVM gateway, significantly enhancing the monitoring of API errors and request response times. Key updates include modifications to the .gitignore and Makefile, the implementation of a metrics collection framework across various API files, and the introduction of configuration support for Prometheus scraping.

Changes

Files Change Summaries
.gitignore, Makefile Updated .gitignore to include metrics/data/ and modified Makefile to remove metrics/data/ from the start-local target.
api/api.go, api/debug.go, api/server.go Integrated Prometheus metrics collection into BlockChainAPI, DebugAPI, and httpServer for enhanced error tracking and request duration measurement.
bootstrap/bootstrap.go Added a metrics server and collector for improved metrics tracking during server operations.
metrics/collector.go Established a framework for metrics collection to monitor API performance and errors.
tests/helpers.go, tests/integration_test.go Enhanced test configurations by adding the Prometheus configuration file path to support monitoring in tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BlockChainAPI
    participant MetricsCollector
    participant Prometheus

    User->>BlockChainAPI: Make API Request
    BlockChainAPI->>MetricsCollector: Start Request Timer
    BlockChainAPI->>BlockChainAPI: Process Request
    alt Request Fails
        BlockChainAPI->>MetricsCollector: Report API Error
    end
    BlockChainAPI->>MetricsCollector: Stop Request Timer
    MetricsCollector->>Prometheus: Push Metrics Data
    Prometheus->>User: Provide Metrics Data

Assessment against linked issues

Objective Addressed Explanation
Integrate Prometheus to EVM gateway (#359) βœ…

Poem

In the code, metrics bloom,
Prometheus watches, no room for gloom.
Errors and times, all recorded fine,
EVM gateway shines, metrics align.
Data flows, insights show,
With Prometheus, we now know. πŸ‡βœ¨


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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
illia-malachyn commented 4 months ago

@sideninja Hey, I'm adding this as skeleton.

Should I create separate issue for each metrics/task as I did for this one or I can just mention #125 in every PR?

illia-malachyn commented 4 months ago

To test this:

illia-malachyn commented 4 months ago

Are we going to run prometheus back-end as a side car ? or is it gonna be a separate server running independently? I want to know whether I should add this to docker/docker-compose

sideninja commented 4 months ago

@sideninja Hey, I'm adding this as skeleton.

Should I create separate issue for each metrics/task as I did for this one or I can just mention #125 in every PR?

No, it's fine for now to reference same issue, but if you want you can add tasklist to the issue itself. But no need.

sideninja commented 4 months ago

@illia-malachyn is this PR ready for review or not yet? since yesterday that I reviewed it, it changed not just based on comments but also by content (adding metrics to all APIs), so I don't know when it's complete. Generally, it will be better if you leave PR in draft as long as you still working on the content and once you finish open it for review. So adding all the metrics to the APIs could be another PR, or if part of this one (which is fine too), but better to leave PR in draft until then.

illia-malachyn commented 4 months ago

@sideninja Basically, I re-request a review after fixing your comments to start the next round of the review process. New metrics will be added in a separate PR. In this PR, I wanted to set up a prometheus and add some simple metrics to show you as an example. I can split this one up too if I'd like me to.

Will keep it as a draft If it's more natural for you!

sideninja commented 4 months ago

@sideninja Basically, I re-request a review after fixing your comments to start the next round of the review process. New metrics will be added in a separate PR. In this PR, I wanted to set up a prometheus and add some simple metrics to show you as an example. I can split this one up too if I'd like me to.

Will keep it as a draft If it's more natural for you!

If it's ready for review put it in review. But I'm confused because after my first review you added metrics to APIs.

illia-malachyn commented 3 months ago

@sideninja Please, take a look at this again once you have time

sideninja commented 3 months ago

@illia-malachyn can you update base branch again sorry