Skip to content

Commit

Permalink
rpk/start: Disable cloud vendor checks when --check=false
Browse files Browse the repository at this point in the history
Disable all checks when `--check=false` to reduce startup time.

Before:

0.09s user 0.06s system 6% cpu 2.195 total

After

0.07s user 0.07s system 13% cpu 1.040 total

Measured with:

time rpk redpanda start --check=false  -- --unknown-rp-flag

--unknown-rp-flag is passed so redpanda exits upon encountering
an invalid flag.
  • Loading branch information
David Castillo committed Apr 17, 2021
1 parent 2ef1dfc commit bb1ec2e
Show file tree
Hide file tree
Showing 2 changed files with 47 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
51 changes: 32 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,10 @@ 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 +605,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 +879,7 @@ func sendEnv(
mgr config.Manager,
env api.EnvironmentPayload,
conf *config.Config,
skipChecks bool,
err error,
) {
if err != nil {
Expand All @@ -891,7 +904,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 bb1ec2e

Please sign in to comment.