Skip to content

Commit

Permalink
[PLAT-14443] YBA Installer wait for ready time configurable.
Browse files Browse the repository at this point in the history
Summary:
We should be able to configure how long yba installer will wait for
yba to be "ready" after an install or upgrade.

I also improved how we set the current schema version to not require devs to update a constant.

Test Plan: tested install and an install + upgrade with the new confi goption

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36067
  • Loading branch information
shubin-yb committed Jun 26, 2024
1 parent 199f679 commit 86a865d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
20 changes: 16 additions & 4 deletions managed/yba-installer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,29 @@ func handleRootCheck(cmdName string) {
log.Fatal("Could not determine current user: " + err.Error())
}

if !viper.IsSet("as_root") && cmdName == "yba-ctl upgrade" {
// Upgrading from before "as_root" exists. perform legacy check for /opt/yba-ctl
_, err := os.Stat(common.YbactlRootInstallDir)
if user.Uid == "0" && err != nil {
log.Fatal("no root install found at /opt/yba-ctl, cannot upgrade with root")
} else if user.Uid != "0" && err == nil {
log.Fatal("Detected root install at /opt/yba-ctl, cannot upgrade as non-root")
}
log.Debug("legacy root check passed for upgrade")
return
}

// First, validate that the user (root access) matches the config 'as_root'
if user.Uid == "0" && !viper.GetBool("as_root") {
log.Fatal("running as root user with 'as_root' set to false is not supported")
} else if user.Uid != "0" &&
(viper.GetBool("as_root") || common.Exists(common.YbactlRootInstallDir)) {
// Allow running certain commands as non-root in root install mode
switch cmdName {
case "yba-ctl version", "yba-ctl status", "yba-ctl createBackup":
break
default:
log.Fatal("running as non-root user with 'as_root' set to true is not supported")
case "yba-ctl version", "yba-ctl status", "yba-ctl createBackup":
break
default:
log.Fatal("running as non-root user with 'as_root' set to true is not supported")
}
}
}
11 changes: 8 additions & 3 deletions managed/yba-installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,23 @@ func WaitForYBAReady(version string) error {

var resp *http.Response
var err error
// Check YBA version every 10 seconds
retriesCount := 20

for i := 0; i < retriesCount; i++ {
waitSecs := viper.GetInt("wait_for_yba_ready_secs")
endTime := time.Now().Add(time.Duration(waitSecs) * time.Second)
success := false
for time.Now().Before(endTime) {
resp, err = http.Get(url)
if err != nil {
log.Info(fmt.Sprintf("YBA at %s not ready. Checking again in 10 seconds.", url))
time.Sleep(10 * time.Second)
} else {
success = true
break
}
}
if !success {
return fmt.Errorf("YBA at %s not ready after %d minutes", url, waitSecs/60)
}

if resp != nil {
defer resp.Body.Close()
Expand Down
37 changes: 35 additions & 2 deletions managed/yba-installer/pkg/ybactlstate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ const ymlTypeFixMV = 4
const promOomConfgMV = 5
const promTLSCipherSuites = 6
const asRoot = 7
const ybaWait = 8

// Please do not use this in ybactlstate package, only use getSchemaVersion()
var schemaVersionCache = -1

func handleMigration(state *State) error {
for state._internalFields.SchemaVersion < schemaVersion {
for state._internalFields.SchemaVersion < getSchemaVersion() {
nextSchema := state._internalFields.SchemaVersion + 1
migrate := getMigrationHandler(nextSchema)
if err := migrate(state); err != nil {
Expand Down Expand Up @@ -183,7 +187,24 @@ func migrateAsRootConfig(state *State) error {
return nil
}

// TODO: Also need to remember to update schemaVersion when adding migration! (automate testing?)
func migrateYbaWait(state *State) error {
if !viper.IsSet("wait_for_yba_ready_secs") {
log.Info("wait for ready not set")
viper.ReadConfig(bytes.NewBufferString(config.ReferenceYbaCtlConfig))
log.Info(fmt.Sprintf("setting to %d", viper.GetInt("wait_for_yba_ready_secs")))
err := common.SetYamlValue(common.InputFile(), "wait_for_yba_ready_secs",
viper.GetInt("wait_for_yba_ready_secs"))
if err != nil {
return fmt.Errorf("Error migrating yb_wait config: %s", err.Error())
}
} else {
log.Info("wait for ready set")
}

common.InitViper()
return nil
}

var migrations map[int]migrator = map[int]migrator{
defaultMigratorValue: defaultMigrate,
promConfigMV: migratePrometheus,
Expand All @@ -192,6 +213,7 @@ var migrations map[int]migrator = map[int]migrator{
promOomConfgMV: migratePrometheusOOMConfig,
promTLSCipherSuites: migratePrometheusTLSCipherSuites,
asRoot: migrateAsRootConfig,
ybaWait: migrateYbaWait,
}

func getMigrationHandler(toSchema int) migrator {
Expand All @@ -201,3 +223,14 @@ func getMigrationHandler(toSchema int) migrator {
}
return m
}

func getSchemaVersion() int {
if schemaVersionCache == -1 {
for k := range migrations {
if k > schemaVersionCache {
schemaVersionCache = k
}
}
}
return schemaVersionCache
}
5 changes: 2 additions & 3 deletions managed/yba-installer/pkg/ybactlstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
)

const (
StateFileName = ".yba_installer.state"
schemaVersion int = 6
StateFileName = ".yba_installer.state"
)

type State struct {
Expand Down Expand Up @@ -63,7 +62,7 @@ func New() *State {
},
_internalFields: internalFields{
ChangeID: 0,
SchemaVersion: schemaVersion,
SchemaVersion: getSchemaVersion(),
},
}
}
Expand Down
3 changes: 3 additions & 0 deletions managed/yba-installer/yba-ctl.yml.reference
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ service_username: "yugabyte"
# by service_username.
as_root: true

# Number of seconds to wait for yba to start
wait_for_yba_ready_secs: 300

# Config parameters for YB-Platform:
# =======================================

Expand Down

0 comments on commit 86a865d

Please sign in to comment.