Skip to content

Commit

Permalink
Merge pull request #1185 from 0x5d/rpk-start-disable-vendor-check
Browse files Browse the repository at this point in the history
rpk/start: Reduce startup time
  • Loading branch information
emaxerrno authored Apr 17, 2021
2 parents 98f1b9b + 87d06c1 commit 8f38139
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
24 changes: 15 additions & 9 deletions src/go/rpk/pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ func SendMetrics(p MetricsPayload, conf config.Config) error {
}

func SendEnvironment(
fs afero.Fs, env EnvironmentPayload, conf config.Config, confJSON string,
fs afero.Fs,
env EnvironmentPayload,
conf config.Config,
confJSON string,
skipCloudCheck bool,
) error {
confMap := map[string]interface{}{}
err := json.Unmarshal([]byte(confJSON), &confMap)
Expand All @@ -104,16 +108,18 @@ func SendEnvironment(
}
cloudVendor := "N/A"
vmType := "N/A"
v, err := cloud.AvailableVendor()
if err != nil {
log.Debug(err)
} else {
cloudVendor = v.Name()
vt, err := v.VmType()
if !skipCloudCheck {
v, err := cloud.AvailableVendor()
if err != nil {
log.Debug("Error retrieving instance type: ", err)
log.Debug(err)
} else {
vmType = vt
cloudVendor = v.Name()
vt, err := v.VmType()
if err != nil {
log.Debug("Error retrieving instance type: ", err)
} else {
vmType = vt
}
}
}

Expand Down
50 changes: 31 additions & 19 deletions src/go/rpk/pkg/cli/cmd/redpanda/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func NewStartCommand(
}
seedServers, err := parseSeeds(seeds)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if len(seedServers) != 0 {
Expand All @@ -166,7 +166,7 @@ func NewStartCommand(
config.DefaultKafkaPort,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if kafkaApi != nil && len(kafkaApi) > 0 {
Expand All @@ -185,7 +185,7 @@ func NewStartCommand(
config.DefaultProxyPort,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if proxyApi != nil && len(proxyApi) > 0 {
Expand All @@ -204,7 +204,7 @@ func NewStartCommand(
config.Default().Redpanda.RPCServer.Port,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if rpcServer != nil {
Expand All @@ -223,7 +223,7 @@ func NewStartCommand(
config.DefaultKafkaPort,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if advKafkaApi != nil {
Expand All @@ -242,7 +242,7 @@ func NewStartCommand(
config.DefaultProxyPort,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if advProxyApi != nil {
Expand All @@ -261,25 +261,26 @@ func NewStartCommand(
config.Default().Redpanda.RPCServer.Port,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
if advRPCApi != nil {
conf.Redpanda.AdvertisedRPCAPI = advRPCApi
}
installDirectory, err := cli.GetOrFindInstallDir(fs, installDirFlag)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
rpArgs, err := buildRedpandaFlags(
fs,
conf,
sFlags,
ccmd.Flags(),
!prestartCfg.checkEnabled,
)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}
checkPayloads, tunerPayloads, err := prestart(
Expand All @@ -292,17 +293,17 @@ func NewStartCommand(
env.Checks = checkPayloads
env.Tuners = tunerPayloads
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}

err = mgr.Write(conf)
if err != nil {
sendEnv(fs, mgr, env, conf, err)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, err)
return err
}

sendEnv(fs, mgr, env, conf, nil)
sendEnv(fs, mgr, env, conf, !prestartCfg.checkEnabled, nil)
rpArgs.ExtraArgs = args
log.Info(common.FeedbackMsg)
log.Info("Starting redpanda...")
Expand Down Expand Up @@ -475,7 +476,11 @@ func prestart(
}

func buildRedpandaFlags(
fs afero.Fs, conf *config.Config, sFlags seastarFlags, flags *pflag.FlagSet,
fs afero.Fs,
conf *config.Config,
sFlags seastarFlags,
flags *pflag.FlagSet,
skipChecks bool,
) (*rp.RedpandaArgs, error) {
wellKnownIOSet := conf.Rpk.WellKnownIo != ""
ioPropsSet := flags.Changed(ioPropertiesFileFlag) || flags.Changed(ioPropertiesFlag)
Expand All @@ -498,15 +503,15 @@ func buildRedpandaFlags(
}
// Otherwise, try to deduce the IO props.
if sFlags.ioPropertiesFile == "" {
ioProps, err := resolveWellKnownIo(conf)
if err == nil {
ioProps, err := resolveWellKnownIo(conf, skipChecks)
if err != nil {
log.Warn(err)
} else if ioProps != nil {
yaml, err := iotune.ToYaml(*ioProps)
if err != nil {
return nil, err
}
sFlags.ioProperties = fmt.Sprintf("'%s'", yaml)
} else {
log.Warn(err)
}
}
}
Expand Down Expand Up @@ -575,7 +580,9 @@ func mergeFlags(
return current
}

func resolveWellKnownIo(conf *config.Config) (*iotune.IoProperties, error) {
func resolveWellKnownIo(
conf *config.Config, skipChecks bool,
) (*iotune.IoProperties, error) {
var ioProps *iotune.IoProperties
if conf.Rpk.WellKnownIo != "" {
wellKnownIoTokens := strings.Split(conf.Rpk.WellKnownIo, ":")
Expand All @@ -597,6 +604,10 @@ func resolveWellKnownIo(conf *config.Config) (*iotune.IoProperties, error) {
}
return ioProps, nil
}
// Skip detecting the cloud vendor if skipChecks is true
if skipChecks {
return nil, nil
}
log.Info("Detecting the current cloud vendor and VM")
vendor, err := cloud.AvailableVendor()
if err != nil {
Expand Down Expand Up @@ -867,6 +878,7 @@ func sendEnv(
mgr config.Manager,
env api.EnvironmentPayload,
conf *config.Config,
skipChecks bool,
err error,
) {
if err != nil {
Expand All @@ -891,7 +903,7 @@ func sendEnv(
}
confJSON = string(confBytes)
}
err = api.SendEnvironment(fs, env, *conf, confJSON)
err = api.SendEnvironment(fs, env, *conf, confJSON, skipChecks)
if err != nil {
log.Debugf("couldn't send environment data: %v", err)
}
Expand Down

0 comments on commit 8f38139

Please sign in to comment.