chore_: add fleet flag to cli (#5478)

This commit is contained in:
Pablo Lopez 2024-07-04 09:15:58 +03:00 committed by GitHub
parent 437f830b51
commit 2debe06680
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 19 deletions

View File

@ -22,6 +22,7 @@ const PortFlag = "port"
const APIModulesFlag = "api-modules"
const TelemetryServerURLFlag = "telemetry-server-url"
const KeyUIDFlag = "key-uid"
const FleetFlag = "fleet"
const DebugLevel = "debug"
const MessageFailureFlag = "fail"
@ -52,6 +53,13 @@ var CommonFlags = []cli.Flag{
Usage: "Enable CLI's debug level logging",
Value: false,
},
&cli.StringFlag{
Name: FleetFlag,
Aliases: []string{"f"},
Usage: "The fleet to use for the node, e.g.: shards.staging, shards.test",
Value: "shards.staging",
Required: false,
},
}
var SimulateFlags = append([]cli.Flag{

View File

@ -24,6 +24,7 @@ func serve(cCtx *cli.Context) error {
dest := cCtx.String(AddFlag)
keyUID := cCtx.String(KeyUIDFlag)
isDebugLevel := cCtx.Bool(DebugLevel)
fleet := cCtx.String(FleetFlag)
cmdName := cCtx.Command.Name
logger, err := getSLogger(isDebugLevel)
@ -34,7 +35,14 @@ func serve(cCtx *cli.Context) error {
logger = logger.Named(name)
cli, err := start(name, port, apiModules, telemetryUrl, keyUID, logger)
cli, err := start(StartParams{
Name: name,
Port: port,
APIModules: apiModules,
TelemetryURL: telemetryUrl,
KeyUID: keyUID,
Fleet: fleet,
}, logger)
if err != nil {
return err
}

View File

@ -36,14 +36,25 @@ func simulate(cCtx *cli.Context) error {
apiModules := cCtx.String(APIModulesFlag)
telemetryUrl := cCtx.String(TelemetryServerURLFlag)
failMessages := cCtx.Bool(MessageFailureFlag)
fleet := cCtx.String(FleetFlag)
alice, err := start("Alice", 0, apiModules, telemetryUrl, "", logger.Named("alice"))
alice, err := start(StartParams{
Name: "Alice",
APIModules: apiModules,
TelemetryURL: telemetryUrl,
Fleet: fleet,
}, logger.Named("alice"))
if err != nil {
return err
}
defer alice.stop()
charlie, err := start("Charlie", 0, apiModules, telemetryUrl, "", logger.Named("charlie"))
charlie, err := start(StartParams{
Name: "Charlie",
APIModules: apiModules,
TelemetryURL: telemetryUrl,
Fleet: fleet,
}, logger.Named("charlie"))
if err != nil {
return err
}

View File

@ -13,6 +13,7 @@ import (
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/services/wakuv2ext"
"github.com/status-im/status-go/telemetry"
@ -37,22 +38,31 @@ func setupLogger(file string) *zap.Logger {
return logutils.ZapLogger()
}
func start(name string, port int, apiModules string, telemetryUrl string, keyUID string, logger *zap.SugaredLogger) (*StatusCLI, error) {
type StartParams struct {
Name string
Port int
APIModules string
TelemetryURL string
KeyUID string
Fleet string
}
func start(p StartParams, logger *zap.SugaredLogger) (*StatusCLI, error) {
var (
rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(name))
rootDataDir = fmt.Sprintf("./test-%s", strings.ToLower(p.Name))
password = "some-password"
)
setupLogger(name)
setupLogger(p.Name)
logger.Info("starting messenger")
backend := api.NewGethStatusBackend()
if keyUID != "" {
if err := getAccountAndLogin(backend, name, rootDataDir, password, keyUID); err != nil {
if p.KeyUID != "" {
if err := getAccountAndLogin(backend, p.Name, rootDataDir, password, p.KeyUID); err != nil {
return nil, err
}
logger.Infof("existing account, key UID: %v", keyUID)
logger.Infof("existing account, key UID: %v", p.KeyUID)
} else {
acc, err := createAccountAndLogin(backend, name, rootDataDir, password, apiModules, telemetryUrl, port)
acc, err := createAccountAndLogin(backend, rootDataDir, password, p)
if err != nil {
return nil, err
}
@ -64,12 +74,12 @@ func start(name string, port int, apiModules string, telemetryUrl string, keyUID
return nil, errors.New("waku service is not available")
}
if telemetryUrl != "" {
if p.TelemetryURL != "" {
telemetryLogger, err := getLogger(true)
if err != nil {
return nil, err
}
telemetryClient := telemetry.NewClient(telemetryLogger, telemetryUrl, backend.SelectedAccountKeyID(), name, "cli")
telemetryClient := telemetry.NewClient(telemetryLogger, p.TelemetryURL, backend.SelectedAccountKeyID(), p.Name, "cli")
go telemetryClient.Start(context.Background())
backend.StatusNode().WakuV2Service().SetStatusTelemetryClient(telemetryClient)
}
@ -84,7 +94,7 @@ func start(name string, port int, apiModules string, telemetryUrl string, keyUID
time.Sleep(WaitingInterval)
data := StatusCLI{
name: name,
name: p.Name,
messenger: messenger,
backend: backend,
logger: logger,
@ -125,27 +135,31 @@ func getAccountAndLogin(b *api.GethStatusBackend, name, rootDataDir, password st
})
}
func createAccountAndLogin(b *api.GethStatusBackend, name, rootDataDir, password, apiModules, telemetryUrl string, port int) (*multiaccounts.Account, error) {
func createAccountAndLogin(b *api.GethStatusBackend, rootDataDir, password string, p StartParams) (*multiaccounts.Account, error) {
if err := os.MkdirAll(rootDataDir, os.ModePerm); err != nil {
return nil, err
}
req := &requests.CreateAccount{
DisplayName: name,
DisplayName: p.Name,
CustomizationColor: "#ffffff",
Emoji: "some",
Password: password,
RootDataDir: rootDataDir,
LogFilePath: "log",
APIConfig: &requests.APIConfig{
APIModules: apiModules,
APIModules: p.APIModules,
HTTPEnabled: true,
HTTPHost: "127.0.0.1",
HTTPPort: port,
HTTPPort: p.Port,
},
TelemetryServerURL: telemetryUrl,
TelemetryServerURL: p.TelemetryURL,
}
return b.CreateAccountAndLogin(req)
return b.CreateAccountAndLogin(req,
params.WithFleet(p.Fleet),
params.WithDiscV5BootstrapNodes(params.DefaultDiscV5Nodes(p.Fleet)),
params.WithWakuNodes(params.DefaultWakuNodes(p.Fleet)),
)
}
func (cli *StatusCLI) stop() {