Skip to content

Commit

Permalink
cleanup devstack options
Browse files Browse the repository at this point in the history
  • Loading branch information
wdbaruni committed Oct 3, 2024
1 parent 3a7e2f2 commit cf0b5b7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 58 deletions.
49 changes: 33 additions & 16 deletions cmd/cli/devstack/devstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,45 @@ var (
`))
)

func newDevStackOptions() *devstack.DevStackOptions {
return &devstack.DevStackOptions{
type options struct {
NumberOfHybridNodes int // Number of nodes to start in the cluster
NumberOfRequesterOnlyNodes int // Number of nodes to start in the cluster
NumberOfComputeOnlyNodes int // Number of nodes to start in the cluster
NumberOfBadComputeActors int // Number of compute nodes to be bad actors
CPUProfilingFile string
MemoryProfilingFile string
BasePath string
WebUIListen string
}

func (o *options) devstackOptions() []devstack.ConfigOption {
opts := []devstack.ConfigOption{
devstack.WithNumberOfHybridNodes(o.NumberOfHybridNodes),
devstack.WithNumberOfRequesterOnlyNodes(o.NumberOfRequesterOnlyNodes),
devstack.WithNumberOfComputeOnlyNodes(o.NumberOfComputeOnlyNodes),
devstack.WithNumberOfBadComputeActors(o.NumberOfBadComputeActors),
devstack.WithCPUProfilingFile(o.CPUProfilingFile),
devstack.WithMemoryProfilingFile(o.MemoryProfilingFile),
devstack.WithBasePath(o.BasePath),
}
return opts
}

func newOptions() *options {
return &options{
NumberOfRequesterOnlyNodes: 1,
NumberOfComputeOnlyNodes: 3,
NumberOfBadComputeActors: 0,
Peer: "",
CPUProfilingFile: "",
MemoryProfilingFile: "",
BasePath: "",
WebUIListen: config.Default.WebUI.Listen,
}
}

//nolint:funlen,gocyclo
func NewCmd() *cobra.Command {
ODs := newDevStackOptions()
var webUIListen string
ODs := newOptions()
devstackFlags := map[string][]configflags.Definition{
"job-selection": configflags.JobSelectionFlags,
"disable-features": configflags.DisabledFeatureFlags,
Expand All @@ -83,7 +106,7 @@ func NewCmd() *cobra.Command {
if err := logger.ConfigureLogging(string(logger.LogModeDefault), "debug"); err != nil {
return fmt.Errorf("failed to configure logging: %w", err)
}
return runDevstack(cmd, ODs, webUIListen)
return runDevstack(cmd, ODs)
},
}

Expand All @@ -108,13 +131,9 @@ func NewCmd() *cobra.Command {
`How many compute nodes should be bad actors`,
)
devstackCmd.PersistentFlags().StringVar(
&webUIListen, "webui-address", config.Default.WebUI.Listen,
&ODs.WebUIListen, "webui-address", ODs.WebUIListen,
`Listen address for the web UI server`,
)
devstackCmd.PersistentFlags().StringVar(
&ODs.Peer, "peer", ODs.Peer,
`Connect node 0 to another network node`,
)
devstackCmd.PersistentFlags().StringVar(
&ODs.CPUProfilingFile, "cpu-profiling-file", ODs.CPUProfilingFile,
"File to save CPU profiling to",
Expand All @@ -131,7 +150,7 @@ func NewCmd() *cobra.Command {
}

//nolint:gocyclo,funlen
func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen string) error {
func runDevstack(cmd *cobra.Command, ODs *options) error {
ctx := cmd.Context()

cm := util.GetCleanupManager(ctx)
Expand Down Expand Up @@ -164,9 +183,7 @@ func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen
defer os.RemoveAll(baseRepoPath)
}

options := ODs.Options()

stack, err := devstack.Setup(ctx, cm, options...)
stack, err := devstack.Setup(ctx, cm, ODs.devstackOptions()...)
if err != nil {
return err
}
Expand All @@ -177,7 +194,7 @@ func runDevstack(cmd *cobra.Command, ODs *devstack.DevStackOptions, webUIListen
if n.IsRequesterNode() {
webuiConfig := webui.Config{
APIEndpoint: n.APIServer.GetURI().String(),
Listen: webUIListen,
Listen: ODs.WebUIListen,
}
webuiServer, err := webui.NewServer(webuiConfig)
if err != nil {
Expand Down
28 changes: 0 additions & 28 deletions pkg/devstack/devstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/system"
)

type DevStackOptions struct {
NumberOfHybridNodes int // Number of nodes to start in the cluster
NumberOfRequesterOnlyNodes int // Number of nodes to start in the cluster
NumberOfComputeOnlyNodes int // Number of nodes to start in the cluster
NumberOfBadComputeActors int // Number of compute nodes to be bad actors
Peer string // Connect node 0 to another network node
CPUProfilingFile string
MemoryProfilingFile string
BasePath string
}

func (o *DevStackOptions) Options() []ConfigOption {
opts := []ConfigOption{
WithNumberOfHybridNodes(o.NumberOfHybridNodes),
WithNumberOfRequesterOnlyNodes(o.NumberOfRequesterOnlyNodes),
WithNumberOfComputeOnlyNodes(o.NumberOfComputeOnlyNodes),
WithNumberOfBadComputeActors(o.NumberOfBadComputeActors),
WithCPUProfilingFile(o.CPUProfilingFile),
WithMemoryProfilingFile(o.MemoryProfilingFile),
WithBasePath(o.BasePath),
}
return opts
}

func (o *DevStackOptions) NumberOfNodes() int {
return o.NumberOfHybridNodes + o.NumberOfRequesterOnlyNodes + o.NumberOfComputeOnlyNodes
}

type DevStack struct {
Nodes []*node.Node
}
Expand Down
15 changes: 1 addition & 14 deletions pkg/test/teststack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ import (
"github.com/bacalhau-project/bacalhau/pkg/system"
)

func testDevStackConfig() *devstack.DevStackOptions {
return &devstack.DevStackOptions{
NumberOfHybridNodes: 0,
NumberOfRequesterOnlyNodes: 0,
NumberOfComputeOnlyNodes: 0,
NumberOfBadComputeActors: 0,
Peer: "",
CPUProfilingFile: "",
MemoryProfilingFile: "",
}
}

func Setup(
ctx context.Context,
t testing.TB,
Expand All @@ -42,8 +30,7 @@ func Setup(
cm.Cleanup(ctx)
})

options := testDevStackConfig().Options()
options = append(options, devstack.WithBasePath(t.TempDir()))
options := []devstack.ConfigOption{devstack.WithBasePath(t.TempDir())}
options = append(options, opts...)
stack, err := devstack.Setup(ctx, cm, options...)
if err != nil {
Expand Down

0 comments on commit cf0b5b7

Please sign in to comment.