From bb1ec2ea4012bd7601d13597e77c2a7efabf239b Mon Sep 17 00:00:00 2001 From: David Castillo Date: Fri, 16 Apr 2021 17:50:08 -0500 Subject: [PATCH] rpk/start: Disable cloud vendor checks when --check=false 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. --- src/go/rpk/pkg/api/api.go | 24 ++++++----- src/go/rpk/pkg/cli/cmd/redpanda/start.go | 51 +++++++++++++++--------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/go/rpk/pkg/api/api.go b/src/go/rpk/pkg/api/api.go index 9a829d8f7a10b..c41c551e9c38e 100644 --- a/src/go/rpk/pkg/api/api.go +++ b/src/go/rpk/pkg/api/api.go @@ -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) @@ -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 + } } } diff --git a/src/go/rpk/pkg/cli/cmd/redpanda/start.go b/src/go/rpk/pkg/cli/cmd/redpanda/start.go index a236cffc60c4b..afb7bb0fb1ad7 100644 --- a/src/go/rpk/pkg/cli/cmd/redpanda/start.go +++ b/src/go/rpk/pkg/cli/cmd/redpanda/start.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -261,7 +261,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 advRPCApi != nil { @@ -269,7 +269,7 @@ func NewStartCommand( } 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( @@ -277,9 +277,10 @@ func NewStartCommand( 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( @@ -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...") @@ -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) @@ -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) } } } @@ -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, ":") @@ -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 { @@ -867,6 +879,7 @@ func sendEnv( mgr config.Manager, env api.EnvironmentPayload, conf *config.Config, + skipChecks bool, err error, ) { if err != nil { @@ -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) }