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

devstack: support node joining existing networks and config passing #4827

Merged
merged 3 commits into from
Jan 26, 2025

Conversation

wdbaruni
Copy link
Member

@wdbaruni wdbaruni commented Jan 26, 2025

This PR refactors devstack to support two key features:

  1. Allow compute nodes to join an existing orchestrator:

    • Added --computes flag (alias for --compute-nodes) to specify number of compute nodes
    • Added --orchestrators flag (alias for --requester-nodes) to specify number of orchestrator nodes
    • Added --hybrids flag (alias for --hybrid-nodes) to specify hybrid nodes
    • When no orchestrator nodes are specified and orchestrator address is provided via -c flag,
      devstack will run compute-only nodes that connect to the external orchestrator
  2. Use test configuration as base:

    • Devstack now uses NewTestConfig() as base configuration
    • All configuration can be overridden using -c flags (same as bacalhau serve)
    • Node-specific settings are layered on top of base configuration
    • Maintains backward compatibility with existing devstack flags

This allows for:

# Run orchestrator node
bacalhau devstack --orchestrators 1

# Run compute nodes connecting to existing orchestrator
bacalhau devstack --computes 3 -c Compute.Orchestrators=127.0.0.1:4222

# Run both with custom config
bacalhau devstack --computes 3 --orchestrators 1 -c Compute.AllowListedLocalPaths=/tmp

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Updated CLI command-line flags for devstack configuration with more intuitive naming.
	- Enhanced configuration setup process with more flexible option handling.
	- Introduced a new package for organizing related functionalities.

- **Refactor**
	- Simplified devstack node configuration terminology.
	- Improved configuration management in devstack and utility functions.
	- Streamlined node setup logic in devstack configuration.

- **Chores**
	- Updated method signatures to support more dynamic configuration options.
	- Maintained backward compatibility with existing flags.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Copy link
Contributor

coderabbitai bot commented Jan 26, 2025

Walkthrough

The pull request introduces modifications across multiple files (cmd/cli/devstack/devstack.go, cmd/util/repo.go, pkg/devstack/devstack.go, and pkg/lib/ncl/metrics.go) focusing on configuration and command-line flag restructuring. The changes primarily involve renaming node-related fields, updating function signatures to support more flexible configuration options, simplifying the devstack setup process, and introducing a new package for metrics. The modifications aim to enhance code clarity, maintainability, and configuration handling flexibility.

Changes

File Change Summary
cmd/cli/devstack/devstack.go - Renamed node-related fields (e.g., NumberOfHybridNodesHybridNodes)
- Updated command-line flags to match new field names
- Modified runDevstack function signature to accept additional configuration
cmd/util/repo.go - Updated configuration setup functions to accept variadic configuration options
- Modified method signatures for SetupConfigType, SetupConfig, and SetupConfigs
pkg/devstack/devstack.go - Removed initialization of orchestratorAddrs and clusterPeersAddrs
- Simplified orchestrator port and cluster name configuration
- Updated API port configuration logic
pkg/lib/ncl/metrics.go - Introduced a new package ncl for organizing related functionalities

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Command
    participant Config as Configuration Handler
    participant DevStack as DevStack Setup

    CLI->>Config: Call SetupConfig with options
    Config-->>CLI: Return Bacalhau configuration
    CLI->>DevStack: Initialize with configuration
    DevStack-->>CLI: Configure nodes and settings
Loading

Possibly related PRs

Poem

🐰 In the realm of code, where rabbits hop and play,
Flags renamed, options dance their merry way!
Devstack blooms with clarity so bright,
Configuration flows with newfound might.
A refactor's tale, both simple and clean,
Where complexity bows to our coding dream! 🌟


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9461497 and a9e096d.

📒 Files selected for processing (2)
  • pkg/devstack/devstack.go (2 hunks)
  • pkg/lib/ncl/metrics.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pkg/lib/ncl/metrics.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/devstack/devstack.go

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

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

🧹 Nitpick comments (1)
pkg/devstack/devstack.go (1)

99-102: Consider documenting the port increment logic.

The addition of port increment for external orchestrator cases is a subtle change that should be documented to prevent future confusion.

 			cfg.API.Port = 1234 + i
-			// add one more if using an external orchestrator to avoid port conflict
+			// When using an external orchestrator (requesterNodeCount == 0),
+			// increment the port by 1 to avoid conflicts with the orchestrator's ports
 			if requesterNodeCount == 0 {
 				cfg.API.Port += 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 5fb976a and 9461497.

📒 Files selected for processing (3)
  • cmd/cli/devstack/devstack.go (8 hunks)
  • cmd/util/repo.go (2 hunks)
  • pkg/devstack/devstack.go (1 hunks)
🔇 Additional comments (7)
cmd/util/repo.go (2)

Line range hint 46-86: LGTM! Well-structured configuration handling.

The function properly handles multiple configuration sources (files, flags, env vars, values) and merges them in a logical order. The addition of variadic options enhances flexibility while maintaining backward compatibility.


87-94: Verify error handling in configuration chain.

While the implementation looks correct, we should ensure proper error propagation when multiple configuration options fail.

Also applies to: 95-104

✅ Verification successful

Error handling in configuration chain is properly implemented

The configuration chain demonstrates robust error handling with proper error propagation from lower-level operations through the entire chain. All error cases are properly handled and no errors are silently ignored.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling patterns in configuration-related code
rg -A 3 'if err [!:=]' | grep -B 1 'return.*err'

Length of output: 65617


Script:

#!/bin/bash
# Search for SetupConfigType and UnmarshalBacalhauConfig implementations
echo "=== SetupConfigType implementation ==="
ast-grep --pattern 'func SetupConfigType($$$) {
  $$$
}'

echo -e "\n=== UnmarshalBacalhauConfig implementation ==="
ast-grep --pattern 'func UnmarshalBacalhauConfig($$$) {
  $$$
}'

echo -e "\n=== Tests for these functions ==="
rg -l "TestSetupConfig|TestUnmarshalBacalhauConfig|TestSetupConfigType" 

echo -e "\n=== Usage of these functions ==="
rg "SetupConfig|SetupConfigType|UnmarshalBacalhauConfig" --type go

Length of output: 1718


Script:

#!/bin/bash
# Get the full implementation of the configuration functions
echo "=== SetupConfigType implementation ==="
rg -A 20 "^func SetupConfigType" cmd/util/repo.go

echo -e "\n=== UnmarshalBacalhauConfig implementation ==="
rg -A 20 "^func UnmarshalBacalhauConfig" cmd/util/repo.go

echo -e "\n=== Error handling in config package ==="
rg "return.*err" pkg/config/

Length of output: 8378

pkg/devstack/devstack.go (1)

71-91: Potential port conflict in predictable port mode.

When PREDICTABLE_API_PORT is set, the code uses incremental ports (4222+i, 6222+i). This could lead to port conflicts in large clusters or when multiple devstacks run simultaneously.

✅ Verification successful

Port allocation strategy is safe and well-designed

The incremental port allocation (+i) in predictable mode is an intentional design that prevents conflicts within the same devstack instance. The code also provides a fallback to dynamic port allocation when PREDICTABLE_API_PORT is not set. The feature is primarily used in controlled environments like benchmarks and testing, where port ranges are known and managed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of port allocation that might conflict
rg "PREDICTABLE_API_PORT" -A 2 | grep -E "Port = \d{4}"

Length of output: 55


Script:

#!/bin/bash
# Search for PREDICTABLE_API_PORT usage and surrounding context
rg "PREDICTABLE_API_PORT" -B 2 -A 5

# Search for specific port numbers used in predictable mode
rg "(4222|6222)" --type go

# Search for port allocation patterns in tests
fd ".*_test\.go$" --exec grep -l "Port.*=.*[0-9]" {} \;

Length of output: 6333

cmd/cli/devstack/devstack.go (4)

50-59: LGTM! Clear and descriptive field naming.

The renamed fields (ComputeNodes, OrchestratorNodes, HybridNodes, BadComputeNodes) provide better clarity about their purpose.


130-171: LGTM! Well-handled backward compatibility.

Good approach to maintaining backward compatibility by keeping old flags functional but hidden, while introducing clearer new flags.


195-198: Verify configuration merge behavior.

The new configuration merging logic needs careful verification to ensure proper precedence of settings.

✅ Verification successful

Configuration merge behavior is properly implemented and well-tested

The configuration merge behavior is implemented safely using the MergeNew method with proper error handling. The implementation is thoroughly tested through multiple integration and unit tests that verify various override scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for configuration merging patterns
ast-grep --pattern 'WithBacalhauConfigOverride($config)'

Length of output: 58


Script:

#!/bin/bash
# Search for devstack options and config overrides
echo "=== Searching for devstack options ==="
rg -l "devstack.*Options" --type go

echo -e "\n=== Searching for config override implementations ==="
rg "WithBacalhau.*Config.*Override" --type go -A 5

echo -e "\n=== Looking for related tests ==="
rg "TestConfig.*Override|TestDevstack.*Config" --type go

Length of output: 5552


105-117: Verify logging configuration precedence.

The new test config integration changes the logging setup flow. Ensure this doesn't override user-specified logging settings.

✅ Verification successful

Logging configuration precedence is correctly maintained

The test config integration doesn't override user-specified logging settings. The configuration system properly merges values with the following precedence (from lowest to highest):

  • Default values
  • Test config defaults
  • User config files
  • Command-line flags
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for logging configuration patterns
rg -A 3 'ParseAndConfigureLogging|ParseAndConfigureLoggingLevel'

Length of output: 2389


Script:

#!/bin/bash
# Check test config creation and setup
ast-grep --pattern 'func NewTestConfig()' -A 20
rg -l "SetupConfig"
ast-grep --pattern 'func SetupConfig'

Length of output: 2161


Script:

#!/bin/bash
# Check test overrides and config setup
rg -A 10 "testOverrides :=" 
ast-grep --pattern 'func SetupConfig($$$)' -A 30

Length of output: 1904


Script:

#!/bin/bash
# Check config precedence and flag handling
rg -A 10 "func SetupConfigType"
ast-grep --pattern 'func ($$$ *Config) MergeNew' -A 10

Length of output: 697

@wdbaruni wdbaruni merged commit e5db120 into main Jan 26, 2025
14 checks passed
@wdbaruni wdbaruni deleted the devstack-config branch January 26, 2025 20:24
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