Skip to content

Commit

Permalink
Merge pull request #428 from mjlshen/OSD-23471
Browse files Browse the repository at this point in the history
log when we discard proxies and default to the first proxy if all fail healthchecks
  • Loading branch information
openshift-merge-bot[bot] committed May 21, 2024
2 parents 59d5cbc + 987d8a0 commit ca7d234
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pkg/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ var clientDo = func(client *http.Client, req *http.Request) (*http.Response, err
}

func (config *BackplaneConfiguration) getFirstWorkingProxyURL(s []string) string {
bpURL := config.URL + "/healthz"
proxyHealthCheckURL := config.URL + "/healthz"

client := &http.Client{
Timeout: 5 * time.Second,
Expand All @@ -125,17 +125,23 @@ func (config *BackplaneConfiguration) getFirstWorkingProxyURL(s []string) string
}

client.Transport = &http.Transport{Proxy: http.ProxyURL(proxyURL)}
req, _ := http.NewRequest("GET", bpURL, nil)
req, _ := http.NewRequest("GET", proxyHealthCheckURL, nil)
resp, err := clientDo(client, req)

if err != nil {
logger.Infof("Proxy: %s returned an error: %s", proxyURL, err)
continue
}
if resp.StatusCode == http.StatusOK {
return p
}
logger.Infof("proxy: %s did not pass healthcheck, expected response code 200, got %d, discarding", proxyHealthCheckURL, resp.StatusCode)
}

if len(s) > 0 {
logger.Infof("falling back to first proxy-url after all proxies failed health checks: %s", s[0])
return s[0]
}

return ""
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestBackplaneConfiguration_getFirstWorkingProxyURL(t *testing.T) {
{
name: "multiple-invalid-proxies",
proxies: []string{"-", "gellso", ""},
want: "",
want: "-",
},
{
name: "valid-proxies",
Expand Down

0 comments on commit ca7d234

Please sign in to comment.