Skip to content

feat: Add host address as scheduler and worker command line argument - #47

Merged
sitaowang1998 merged 5 commits into
y-scope:mainfrom
sitaowang1998:addr
Jan 13, 2025
Merged

feat: Add host address as scheduler and worker command line argument#47
sitaowang1998 merged 5 commits into
y-scope:mainfrom
sitaowang1998:addr

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Jan 13, 2025

Copy link
Copy Markdown
Collaborator

Description

Previously, clients, schedulers and workers get their IP addresses at runtime. This approach does not work when running inside a container. Thus, now scheduler and worker gets their IP addresses as command line argument, and clients no longer need to get their addresses.

Validation performed

  • GitHub workflow passes
  • Unit tests pass in dev container
  • Integration tests pass in dev container

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated quick-start guide with new scheduler and worker configuration parameters.
    • Added notes about host configuration and task library management.
  • Configuration Changes

    • Introduced --host parameter for scheduler and worker startup.
    • Simplified driver address handling across the system.
  • Database Updates

    • Removed address-related fields from driver and scheduler storage.
    • Updated database schema to focus on driver and scheduler identification.
  • Testing

    • Updated test cases to reflect new driver initialization process.
    • Expanded test flexibility for task state checking.

These changes streamline the Spider system's configuration and improve its network setup flexibility.

@coderabbitai

coderabbitai Bot commented Jan 13, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request introduces significant changes to the Spider system's architecture by removing the automatic IP address retrieval mechanism. The modifications primarily focus on explicitly specifying host addresses through command-line arguments for schedulers and workers. The changes simplify the driver initialization process by removing the address parameter from the Driver class and related storage methods. Test cases and integration tests have been updated to reflect these architectural modifications, emphasizing a more explicit configuration approach.

Changes

File Change Summary
docs/quick-start.md Added --host "127.0.0.1" parameter for scheduler and worker startup commands. Updated notes regarding configuration changes.
src/spider/client/Driver.cpp Removed retrieval of machine address in Driver instance creation. Simplified add_driver method.
src/spider/core/Driver.hpp Removed address-related constructor and method, simplified Driver class by deleting m_addr member variable.
src/spider/io/BoostAsio.hpp Deleted get_address() function and related includes for optional types and logging.
src/spider/scheduler/scheduler.cpp Added --host command-line argument option for scheduler startup. Simplified address retrieval logic.
src/spider/storage/MetadataStorage.hpp Removed get_driver method with address parameter.
src/spider/storage/MysqlStorage.cpp Updated database operations to remove address-related logic in driver and scheduler methods.
src/spider/storage/MysqlStorage.hpp Removed get_driver method from MySqlMetadataStorage class.
src/spider/worker/worker.cpp Added --host command-line argument option for worker startup. Simplified Driver instantiation.
tests/* Updated driver instantiations to remove address parameter across multiple test files, including integration and unit tests.

Possibly related PRs

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/spider/core/Driver.hpp (1)

Line range hint 13-38: Consider standardizing address handling across components.

While the Driver class has been simplified to remove address handling, the Scheduler class still maintains address-related fields. Consider standardizing the approach across all components for better architectural consistency.

tests/integration/test_client.py (1)

22-23: Consider making the host address configurable in tests.

The hardcoded "127.0.0.1" might not be suitable for all test environments. Consider:

  1. Using an environment variable or test configuration
  2. Supporting different addresses for scheduler and worker to test distributed scenarios
+# At the top of the file
+SCHEDULER_HOST = os.getenv("SPIDER_TEST_SCHEDULER_HOST", "127.0.0.1")
+WORKER_HOST = os.getenv("SPIDER_TEST_WORKER_HOST", "127.0.0.1")

 scheduler_cmds = [
     str(dir_path / "spider_scheduler"),
     "--host",
-    "127.0.0.1",
+    SCHEDULER_HOST,
     "--port",
     str(scheduler_port),

 worker_cmds = [
     str(dir_path / "spider_worker"),
     "--host",
-    "127.0.0.1",
+    WORKER_HOST,

Also applies to: 32-33

tests/integration/test_scheduler_worker.py (1)

109-123: Improved test reliability with flexible state checks

The modified assertions now handle race conditions better by accepting multiple valid task states ('ready', 'running', 'success').

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 235b164 and f51a1df.

📒 Files selected for processing (17)
  • docs/quick-start.md (2 hunks)
  • src/spider/client/Driver.cpp (2 hunks)
  • src/spider/core/Driver.hpp (1 hunks)
  • src/spider/io/BoostAsio.hpp (0 hunks)
  • src/spider/scheduler/scheduler.cpp (2 hunks)
  • src/spider/storage/MetadataStorage.hpp (0 hunks)
  • src/spider/storage/MysqlStorage.cpp (4 hunks)
  • src/spider/storage/MysqlStorage.hpp (0 hunks)
  • src/spider/worker/worker.cpp (3 hunks)
  • tests/integration/client.py (1 hunks)
  • tests/integration/test_client.py (2 hunks)
  • tests/integration/test_scheduler_worker.py (5 hunks)
  • tests/scheduler/test-SchedulerPolicy.cpp (2 hunks)
  • tests/storage/test-DataStorage.cpp (3 hunks)
  • tests/storage/test-MetadataStorage.cpp (1 hunks)
  • tests/worker/test-FunctionManager.cpp (1 hunks)
  • tests/worker/test-TaskExecutor.cpp (1 hunks)
💤 Files with no reviewable changes (3)
  • src/spider/storage/MysqlStorage.hpp
  • src/spider/storage/MetadataStorage.hpp
  • src/spider/io/BoostAsio.hpp
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests
🔇 Additional comments (23)
src/spider/core/Driver.hpp (1)

13-13: LGTM! Constructor simplified to focus on core identity.

The removal of the address parameter aligns with the PR's objective to handle IP addresses via command-line arguments instead of runtime retrieval.

src/spider/client/Driver.cpp (1)

37-37: LGTM! Consistent error handling maintained after address removal.

The changes properly maintain error handling while simplifying the driver registration process.

Also applies to: 70-70

tests/integration/client.py (1)

182-182: Verify database schema changes and consider migration strategy.

The removal of the address field from the drivers table requires:

  1. Database schema updates
  2. Migration strategy for existing deployments
tests/worker/test-TaskExecutor.cpp (1)

155-155: LGTM! Driver initialization simplified

The removal of the IP address parameter from the Driver constructor aligns with the PR's objective of eliminating runtime IP address retrieval.

tests/scheduler/test-SchedulerPolicy.cpp (1)

97-97: LGTM! Driver initialization updated correctly

The removal of the IP address parameter from Driver constructor calls maintains consistency with the new architecture while preserving the test's functionality.

Also applies to: 144-144

tests/integration/test_scheduler_worker.py (2)

37-38: LGTM! Host address now provided via command line

The addition of the --host argument for both scheduler and worker aligns with the PR's objective of explicitly providing IP addresses through command-line arguments.

Also applies to: 47-48


159-159: LGTM! Consistent Driver initialization

The removal of the IP address parameter from Driver initialization maintains consistency with the architectural changes.

Also applies to: 190-190

tests/worker/test-FunctionManager.cpp (1)

156-156: LGTM! Driver initialization updated

The removal of the IP address parameter from the Driver constructor maintains consistency with the new architecture.

tests/storage/test-DataStorage.cpp (3)

28-28: LGTM! Driver instantiation updated correctly.

The removal of the IP address parameter aligns with the architectural changes to simplify driver initialization.


60-60: LGTM! Consistent update to driver instantiation.

The change maintains consistency with the updated Driver constructor signature.


179-180: LGTM! Driver instantiations updated correctly.

Both driver instantiations have been properly updated to remove the IP address parameter.

src/spider/scheduler/scheduler.cpp (2)

45-49: LGTM! Host address option added correctly.

The command-line option for host address is properly defined with clear description.


144-144: LGTM! Host argument handling implemented properly.

The implementation includes:

  • Proper variable declaration
  • Required argument validation
  • Clear error messaging

Also applies to: 152-156

src/spider/worker/worker.cpp (3)

66-66: LGTM! Host address option added correctly.

The command-line option for worker host address is properly defined.


336-336: LGTM! Host argument handling implemented properly.

The implementation includes proper validation and error handling for the host argument.

Also applies to: 338-351


379-379: LGTM! Driver instantiation updated correctly.

The Driver constructor call has been updated to align with the new signature.

tests/storage/test-MetadataStorage.cpp (1)

34-34: LGTM! Driver instantiation updated correctly.

The test case has been properly updated to use the simplified Driver constructor.

src/spider/storage/MysqlStorage.cpp (3)

64-64: LGTM! Well-designed schema change.

The address column is appropriately sized to handle both IPv4 (15 chars) and IPv6 (39 chars) addresses, with NOT NULL constraint ensuring the address is always provided.


334-335: LGTM! Clean implementation of the address management changes.

The changes properly implement the transition from automatic IP address retrieval to explicit address management:

  • Removed address storage from driver registration
  • Added proper address and port storage for scheduler registration

Also applies to: 353-364


1491-1506: LGTM! Efficient query optimization.

The method has been optimized to fetch both address and port in a single query, reducing database round trips while maintaining proper error handling and parameterization.

docs/quick-start.md (3)

149-157: LGTM! Clear and comprehensive documentation update.

The scheduler setup instructions have been properly updated with:

  • Clear example of the new --host parameter
  • Important production considerations regarding IP address usage

174-175: LGTM! Well-documented worker configuration.

The worker setup instructions clearly document both new parameters:

  • The --host parameter for address configuration
  • The --libs parameter for task library loading

180-184: LGTM! Comprehensive notes section.

The additional notes effectively cover important considerations:

  • Storage URL configuration requirements
  • Production IP address usage
  • Task library linkage requirements

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/spider/scheduler/scheduler.cpp (2)

44-48: Enhance the help text for the host argument

The help text could be more specific about the expected format of the host address (e.g., IPv4, IPv6, hostname).

-            "scheduler host address"
+            "scheduler host address (e.g., '127.0.0.1', 'localhost', '::1')"

151-153: Enhance the error message for missing host argument

The error message could be more helpful by including an example of the expected format.

-            spdlog::error("host is required");
+            spdlog::error("host address is required (e.g., --host \"127.0.0.1\")");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59eed9f and 3982db9.

📒 Files selected for processing (1)
  • src/spider/scheduler/scheduler.cpp (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: non-storage-unit-tests
  • GitHub Check: lint
🔇 Additional comments (1)
src/spider/scheduler/scheduler.cpp (1)

143-155: LGTM! The implementation effectively addresses containerization requirements

The changes successfully make the host address explicit through command-line arguments, which is crucial for containerized environments. The implementation is clean and consistent with the existing codebase style.

Comment on lines +151 to +155
if (!args.contains("host")) {
spdlog::error("host is required");
return cCmdArgParseErr;
}
scheduler_addr = args["host"].as<std::string>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for the host address value

The code checks if the argument exists but doesn't validate the host address format or handle empty strings. Consider adding validation to ensure the address is well-formed and reachable.

         scheduler_addr = args["host"].as<std::string>();
+        if (scheduler_addr.empty()) {
+            spdlog::error("host address cannot be empty");
+            return cCmdArgParseErr;
+        }
+        // Optional: Add format validation using regex or boost::asio::ip::address::from_string
📝 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 (!args.contains("host")) {
spdlog::error("host is required");
return cCmdArgParseErr;
}
scheduler_addr = args["host"].as<std::string>();
if (!args.contains("host")) {
spdlog::error("host is required");
return cCmdArgParseErr;
}
scheduler_addr = args["host"].as<std::string>();
if (scheduler_addr.empty()) {
spdlog::error("host address cannot be empty");
return cCmdArgParseErr;
}
// Optional: Add format validation using regex or boost::asio::ip::address::from_string

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