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

refactor(katana): separate metrics address and port into 2 args #2537

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 15, 2024

replace --metrics 0.0.0.0:9100 to --metrics --metrics.addr 0.0.0.0 --metrics.port 9100.

by default, if just do --metrics it will use 127.0.0.0:9100. but other values can be specified using the new appropriately named flags

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

Ohayo, sensei! This pull request introduces significant modifications to the NodeArgs structure by replacing the metrics field with a new MetricsOptions struct. The MetricsOptions includes fields for enabling metrics collection and specifying the metrics address and port. Additionally, the MetricsConfig structure is updated for enhanced flexibility in handling addresses and ports. The Node struct's methods have been refined for better initialization and error handling, particularly in relation to the metrics server and CORS configuration.

Changes

File Change Summary
bin/katana/src/cli/node.rs - Updated NodeArgs struct: removed metrics, added MetricsOptions struct with metrics, metrics_addr, metrics_port.
- Modified metrics_config method.
crates/katana/node/src/config/metrics.rs - Changed MetricsConfig field addr from SocketAddr to IpAddr, added port field.
- Introduced constants DEFAULT_METRICS_ADDR, DEFAULT_METRICS_PORT.
- Added socket_addr method.
crates/katana/node/src/lib.rs - Modified launch, build, and spawn methods for improved initialization and error handling, including new CORS configuration.

Possibly related PRs


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

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

@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: 2

🧹 Outside diff range and nitpick comments (3)
crates/katana/node/src/config/metrics.rs (2)

3-6: Ohayo, sensei! These constants look great!

The addition of DEFAULT_METRICS_ADDR and DEFAULT_METRICS_PORT provides sensible defaults for the metrics server configuration. Using localhost as the default address is a safe choice.

Consider adding a brief comment explaining why port 9100 was chosen as the default. This could be helpful for future maintainers.


17-21: Ohayo, sensei! The new socket_addr method looks great!

This method provides a convenient way to obtain a SocketAddr from the separated addr and port fields. It's a smart addition that maintains compatibility with code expecting a SocketAddr.

Consider adding a brief example in the method's documentation to show how it can be used. This could be helpful for developers using this method.

bin/katana/src/cli/node.rs (1)

Line range hint 185-187: Ohayo, sensei! Minor Grammatical Correction in long_help

In the long_help for the chain_id argument, there's a minor grammatical error. The phrase "then it'd used as the actual chain ID" should be "then it will be used as the actual chain ID."

Apply this diff to correct it:

 #[arg(long_help = "The chain ID. If a raw hex string (`0x` prefix) is provided, then it\
-ed used as the actual chain ID. Otherwise, it's represented as the raw \
+ will be used as the actual chain ID. Otherwise, it's represented as the raw \
 ASCII values. It must be a valid Cairo short string.")]
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc5d2f6 and dfe642a.

📒 Files selected for processing (3)
  • bin/katana/src/cli/node.rs (7 hunks)
  • crates/katana/node/src/config/metrics.rs (1 hunks)
  • crates/katana/node/src/lib.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
crates/katana/node/src/config/metrics.rs (3)

1-1: Ohayo, sensei! LGTM!

The import statement has been updated to include IpAddr and Ipv4Addr, which aligns perfectly with the changes made in the rest of the file. Good job on keeping the imports consistent!


12-15: Ohayo, sensei! Excellent refactoring!

The separation of addr and port in the MetricsConfig struct is a great improvement. Here's why:

  1. It provides more flexibility in configuration.
  2. It aligns well with the new constants added earlier.
  3. Using IpAddr for the addr field is more appropriate now that the port is separate.

This change will make it easier to configure and manage the metrics server settings.


1-21: Ohayo, sensei! Overall, these changes are excellent!

The refactoring of the MetricsConfig structure and the addition of new constants and methods have significantly improved the flexibility and usability of the metrics configuration. Here's a summary of the key improvements:

  1. Separation of address and port in MetricsConfig for more granular control.
  2. Addition of default constants for easy configuration.
  3. New socket_addr method for backward compatibility.

These changes will make it easier for users to configure and manage metrics settings while maintaining compatibility with existing code. Great work on this refactoring, sensei!

crates/katana/node/src/lib.rs (1)

Line range hint 107-115: Ohayo sensei! The metrics endpoint initialization looks solid.

The use of cfg.socket_addr() neatly encapsulates the logic for retrieving the socket address, enhancing code clarity and maintainability. The prometheus_exporter::serve function is correctly invoked with the appropriate parameters, ensuring the metrics server is set up properly.

bin/katana/src/cli/node.rs (3)

14-14: Ohayo, sensei! Importing IpAddr for Address Configuration

The addition of use std::net::IpAddr; is necessary for handling IP addresses in the new metrics and server options.


29-29: Ohayo, sensei! Importing Metrics Configuration

Including MetricsConfig, DEFAULT_METRICS_ADDR, and DEFAULT_METRICS_PORT is essential for the new metrics functionality.


101-101: Ohayo, sensei! Adding Metrics Options to NodeArgs

The inclusion of pub metrics: MetricsOptions in NodeArgs integrates the new metrics configuration into the application's arguments.

Comment on lines +388 to +392
if self.metrics.metrics {
Some(MetricsConfig { addr: self.metrics.metrics_addr, port: self.metrics.metrics_port })
} else {
None
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ohayo, sensei! Adjusting metrics_config for Field Name Change

Following the renaming of the metrics field to enabled, ensure that the metrics_config method reflects this change.

Apply this diff to update the field reference:

 fn metrics_config(&self) -> Option<MetricsConfig> {
-    if self.metrics.metrics {
+    if self.metrics.enabled {
         Some(MetricsConfig { addr: self.metrics.metrics_addr, port: self.metrics.metrics_port })
     } else {
         None
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if self.metrics.metrics {
Some(MetricsConfig { addr: self.metrics.metrics_addr, port: self.metrics.metrics_port })
} else {
None
}
if self.metrics.enabled {
Some(MetricsConfig { addr: self.metrics.metrics_addr, port: self.metrics.metrics_port })
} else {
None
}

Comment on lines +115 to +137
#[command(next_help_heading = "Metrics options")]
pub struct MetricsOptions {
/// Whether to enable metrics.
///
/// For now, metrics will still be collected even if this flag is not set. This only
/// controls whether the metrics server is started or not.
#[arg(long)]
pub metrics: bool,

/// The metrics will be served at the given address.
#[arg(long = "metrics.addr")]
#[arg(value_name = "ADD")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_ADDR)]
pub metrics_addr: IpAddr,

/// The metrics will be served at the given port.
#[arg(long = "metrics.port")]
#[arg(value_name = "PORT")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_PORT)]
pub metrics_port: u16,
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Ohayo, sensei! Possible Typos and Clarity Improvements in MetricsOptions

  1. Typo in value_name for metrics_addr

    The value_name for metrics_addr is set to "ADD", which seems like a typo. Consider changing it to "ADDR" for clarity.

    Apply this diff to fix the typo:

     #[arg(long = "metrics.addr")]
    -#[arg(value_name = "ADD")]
    +#[arg(value_name = "ADDR")]
     #[arg(requires = "metrics")]
  2. Consider Renaming the metrics Field to Improve Clarity

    Using self.metrics.metrics may cause confusion due to the repetitive naming. Consider renaming the boolean field metrics in MetricsOptions to enabled or enable_metrics to enhance readability.

    Apply this diff to rename the field:

     pub struct MetricsOptions {
    -    pub metrics: bool,
    +    pub enabled: bool,

    Update the references accordingly in the code:

    In metrics_config method:

     fn metrics_config(&self) -> Option<MetricsConfig> {
    -    if self.metrics.metrics {
    +    if self.metrics.enabled {

    Update the #[arg] attribute:

     #[arg(long)]
    -pub metrics: bool,
    +pub enabled: bool,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[command(next_help_heading = "Metrics options")]
pub struct MetricsOptions {
/// Whether to enable metrics.
///
/// For now, metrics will still be collected even if this flag is not set. This only
/// controls whether the metrics server is started or not.
#[arg(long)]
pub metrics: bool,
/// The metrics will be served at the given address.
#[arg(long = "metrics.addr")]
#[arg(value_name = "ADD")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_ADDR)]
pub metrics_addr: IpAddr,
/// The metrics will be served at the given port.
#[arg(long = "metrics.port")]
#[arg(value_name = "PORT")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_PORT)]
pub metrics_port: u16,
}
#[command(next_help_heading = "Metrics options")]
pub struct MetricsOptions {
/// Whether to enable metrics.
///
/// For now, metrics will still be collected even if this flag is not set. This only
/// controls whether the metrics server is started or not.
#[arg(long)]
pub metrics: bool,
/// The metrics will be served at the given address.
#[arg(long = "metrics.addr")]
#[arg(value_name = "ADDR")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_ADDR)]
pub metrics_addr: IpAddr,
/// The metrics will be served at the given port.
#[arg(long = "metrics.port")]
#[arg(value_name = "PORT")]
#[arg(requires = "metrics")]
#[arg(default_value_t = DEFAULT_METRICS_PORT)]
pub metrics_port: u16,
}

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Project coverage is 69.27%. Comparing base (bc5d2f6) to head (dfe642a).

Files with missing lines Patch % Lines
bin/katana/src/cli/node.rs 50.00% 4 Missing ⚠️
crates/katana/node/src/config/metrics.rs 0.00% 3 Missing ⚠️
crates/katana/node/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2537      +/-   ##
==========================================
- Coverage   69.28%   69.27%   -0.01%     
==========================================
  Files         388      389       +1     
  Lines       50012    50022      +10     
==========================================
+ Hits        34652    34655       +3     
- Misses      15360    15367       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy changed the base branch from main to katana/cli-breaking October 15, 2024 17:54
@kariy kariy merged commit 9477620 into katana/cli-breaking Oct 15, 2024
5 of 7 checks passed
@kariy kariy deleted the katana/metrics-args branch October 15, 2024 17:54
glihm pushed a commit that referenced this pull request Nov 10, 2024
* refactor(katana): separate metrics address and port into 2 args (#2537)

* refactor(katana-cli): rename server args

* refactor(katana-cli): explicit development related args

* chore(katana-cli): rename var

* fix

* refactor cli

* move gas price to gas price oracle options

* update node bindings to new cli args

* update ci

* revert to free port

* fmt

* remove l1.provider

* update

* make fixed gpo sovereign

* remove broken link
glihm added a commit that referenced this pull request Nov 10, 2024
* refactor(katana): separate metrics address and port into 2 args (#2537)

* refactor(katana-cli): rename server args

* refactor(katana-cli): explicit development related args

* chore(katana-cli): rename var

* fix

* refactor cli

* move gas price to gas price oracle options

* update node bindings to new cli args

* update ci

* revert to free port

* fmt

* remove l1.provider

* update

* make fixed gpo sovereign

* remove broken link

* fix

* feat: add config file with manual merge for now

* fix: rename cors_domain to cors_origins

---------

Co-authored-by: Ammar Arif <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant