Skip to content

Commit

Permalink
[BACKPORT 2024.1][PLAT-13096] Handling comma separated hosts in YBA-i…
Browse files Browse the repository at this point in the history
…nstaller

Summary:
Currently if multiple hostnames are set in yba-ctl.yml we do not handle it completely in all parts of the code. Specifically, our template files would generate incorrect configs and the status command would also appear strange. Also adds waiting for YBA during reconfigure, which is just a nice to have simple improvement.
Original commit: d393043 / D33426

Test Plan: yba-ctl install with no host set, single host set, and multiple hosts set

Reviewers: dshubin, sanketh

Reviewed By: dshubin

Subscribers: yugaware

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D36230
  • Loading branch information
mchiddy committed Jun 28, 2024
1 parent e3caa8d commit 94ff887
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 34 deletions.
2 changes: 2 additions & 0 deletions managed/yba-installer/cmd/reconfigure.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ var reconfigureCmd = &cobra.Command{
services[name].Start()
}

common.WaitForYBAReady(ybaCtl.Version())

for _, name := range serviceOrder {
status, err := services[name].Status()
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions managed/yba-installer/config/templates/yba-installer-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ services:
swamper.rulesPath = "{{ baseInstall }}/data/prometheus/swamper_rules"
{{ if eq (yamlPath "prometheus.enableHttps") "true" }}
metrics.protocol = https
metrics.url = "https://{{ yamlPath "host" }}:{{ yamlPath "prometheus.port" }}/api/v1"
metrics.url = "https://{{ index (splitInput (yamlPath "host")) 0 }}:{{ yamlPath "prometheus.port" }}/api/v1"
{{ else }}
metrics.protocol = http
metrics.url = "http://{{ yamlPath "host" }}:{{ yamlPath "prometheus.port" }}/api/v1"
metrics.url = "http://{{ index (splitInput (yamlPath "host")) 0 }}:{{ yamlPath "prometheus.port" }}/api/v1"
{{ end }}
{{ if eq (yamlPath "prometheus.enableAuth") "true" }}
metrics.auth = true
Expand Down Expand Up @@ -174,8 +174,14 @@ services:
cors {
pathPrefixes = ["/"]
allowedOrigins = [
"https://{{ yamlPath "host" }}",
"{{ yamlPath "platform.support_origin_url"}}"
{{- range $index, $hostname := splitInput (yamlPath "host") }}
{{ if $index }},{{ end -}}
"{{ $hostname }}"
{{- end }},
{{- range $index, $hostname := splitInput (yamlPath "platform.support_origin_url") }}
{{ if $index }},{{ end -}}
"{{ $hostname }}"
{{- end }}
]
supportsCredentials=true
allowedHttpMethods = ["GET", "POST", "PUT", "OPTIONS", "DELETE"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
password: {{ yamlPath "prometheus.authPassword" }}
{{ end }}
static_configs:
- targets: ['{{ yamlPath "host" }}:{{ yamlPath "prometheus.port" }}']
- targets: ['{{ index (splitInput (yamlPath "host")) 0 }}:{{ yamlPath "prometheus.port" }}']
- job_name: 'platform'
scheme: https
Expand All @@ -45,7 +45,7 @@
scrape_timeout: {{ yamlPath "prometheus.scrapeTimeout" }}
metrics_path: "/api/v1/prometheus_metrics"
static_configs:
- targets: ['{{ yamlPath "host" }}:{{ yamlPath "platform.port" }}']
- targets: ['{{ index (splitInput (yamlPath "host")) 0 }}:{{ yamlPath "platform.port" }}']
- job_name: 'node-agent'
scrape_timeout: {{ yamlPath "prometheus.scrapeTimeout" }}
Expand Down
62 changes: 34 additions & 28 deletions managed/yba-installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,41 +490,47 @@ func WaitForYBAReady(version string) {
// Needed to access https URL without x509: certificate signed by unknown authority error
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}

url := fmt.Sprintf("https://%s:%s/api/v1/app_version",
viper.GetString("host"),
viper.GetString("platform.port"))
hostnames := SplitInput(viper.GetString("host"))

var resp *http.Response
var err error
// Check YBA version every 10 seconds
retriesCount := 20
for _, host := range hostnames {

for i := 0; i < retriesCount; i++ {
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 {
break
url := fmt.Sprintf("https://%s:%s/api/v1/app_version",
host,
viper.GetString("platform.port"))

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

for i := 0; i < retriesCount; i++ {
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 {
break
}
}
}

if resp != nil {
defer resp.Body.Close()
}
if resp != nil {
defer resp.Body.Close()
}

// Validate version in prod
if os.Getenv("YBA_MODE") != "dev" {
if err == nil {
var result map[string]string
json.NewDecoder(resp.Body).Decode(&result)
if result["version"] != version {
log.Fatal(fmt.Sprintf("Running YBA version %s does not match expected version %s",
result["version"], version))
// Validate version in prod
if os.Getenv("YBA_MODE") != "dev" {
if err == nil {
var result map[string]string
json.NewDecoder(resp.Body).Decode(&result)
if result["version"] != version {
log.Fatal(fmt.Sprintf("Running YBA version %s does not match expected version %s",
result["version"], version))
}
} else {
log.Fatal(fmt.Sprintf("Error waiting for YBA ready: %s", err.Error()))
}
} else {
log.Fatal(fmt.Sprintf("Error waiting for YBA ready: %s", err.Error()))
}

}

}
1 change: 1 addition & 0 deletions managed/yba-installer/pkg/config/templatedConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func readConfigAndTemplate(configYmlFileName string, service common.Component) (
"installVersionDir": common.GetInstallerSoftwareDir,
"baseInstall": common.GetBaseInstall,
"removeQuotes": common.RemoveQuotes,
"splitInput": common.SplitInput,
}

tmpl, err := template.New(configYmlFileName).
Expand Down

0 comments on commit 94ff887

Please sign in to comment.