Skip to content

Commit 12f831b

Browse files
authored
Improve error handling for private operator timeouts (#1415)
1 parent ef3cf06 commit 12f831b

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

cli/cluster/errors.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func ErrorFailedToConnectOperator(originalError error, envName string, operatorU
5454
msg += fmt.Sprintf(" → otherwise you can ignore this message, and prevent it in the future with `cortex env delete %s`\n", envName)
5555
msg += "\nif you have a cluster running:\n"
5656
msg += fmt.Sprintf(" → run `cortex cluster info --env %s` to update your environment (include `--config <cluster.yaml>` if you have a cluster configuration file)\n", envName)
57+
// CORTEX_VERSION_MINOR
58+
msg += " → if you set `operator_load_balancer_scheme: internal` in your cluster configuration file, your CLI must run from within a VPC that has access to your cluster's VPC (see https://docs.cortex.dev/v/master/guides/vpc-peering)\n"
5759

5860
return errors.WithStack(&errors.Error{
5961
Kind: ErrFailedToConnectOperator,

cli/cluster/lib_http_client.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,12 @@ func (oc OperatorConfig) AuthHeader() string {
5151
return fmt.Sprintf("CortexAWS %s|%s", oc.AWSAccessKeyID, oc.AWSSecretAccessKey)
5252
}
5353

54-
var _operatorClient = &OperatorClient{
55-
Client: &http.Client{
56-
Timeout: 600 * time.Second,
57-
Transport: &http.Transport{
58-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
59-
},
60-
},
61-
}
62-
6354
func HTTPGet(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
6455
req, err := operatorRequest(operatorConfig, "GET", endpoint, nil, qParams)
6556
if err != nil {
6657
return nil, err
6758
}
68-
return _operatorClient.MakeRequest(operatorConfig, req)
59+
return makeOperatorRequest(operatorConfig, req)
6960
}
7061

7162
func HTTPPostObjAsJSON(operatorConfig OperatorConfig, endpoint string, requestData interface{}, qParams ...map[string]string) ([]byte, error) {
@@ -83,23 +74,23 @@ func HTTPPostJSON(operatorConfig OperatorConfig, endpoint string, jsonRequestDat
8374
return nil, err
8475
}
8576
req.Header.Set("Content-Type", "application/json")
86-
return _operatorClient.MakeRequest(operatorConfig, req)
77+
return makeOperatorRequest(operatorConfig, req)
8778
}
8879

8980
func HTTPPostNoBody(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
9081
req, err := operatorRequest(operatorConfig, http.MethodPost, endpoint, nil, qParams)
9182
if err != nil {
9283
return nil, err
9384
}
94-
return _operatorClient.MakeRequest(operatorConfig, req)
85+
return makeOperatorRequest(operatorConfig, req)
9586
}
9687

9788
func HTTPDelete(operatorConfig OperatorConfig, endpoint string, qParams ...map[string]string) ([]byte, error) {
9889
req, err := operatorRequest(operatorConfig, http.MethodDelete, endpoint, nil, qParams)
9990
if err != nil {
10091
return nil, err
10192
}
102-
return _operatorClient.MakeRequest(operatorConfig, req)
93+
return makeOperatorRequest(operatorConfig, req)
10394
}
10495

10596
type HTTPUploadInput struct {
@@ -139,7 +130,7 @@ func HTTPUpload(operatorConfig OperatorConfig, endpoint string, input *HTTPUploa
139130
}
140131

141132
req.Header.Set("Content-Type", writer.FormDataContentType())
142-
return _operatorClient.MakeRequest(operatorConfig, req)
133+
return makeOperatorRequest(operatorConfig, req)
143134
}
144135

145136
func addFileToMultipart(fileName string, writer *multipart.Writer, reader io.Reader) error {
@@ -185,7 +176,7 @@ func operatorRequest(operatorConfig OperatorConfig, method string, endpoint stri
185176
return req, nil
186177
}
187178

188-
func (client *OperatorClient) MakeRequest(operatorConfig OperatorConfig, request *http.Request) ([]byte, error) {
179+
func makeOperatorRequest(operatorConfig OperatorConfig, request *http.Request) ([]byte, error) {
189180
if operatorConfig.Telemetry {
190181
values := request.URL.Query()
191182
values.Set("clientID", operatorConfig.ClientID)
@@ -195,6 +186,18 @@ func (client *OperatorClient) MakeRequest(operatorConfig OperatorConfig, request
195186
request.Header.Set("Authorization", operatorConfig.AuthHeader())
196187
request.Header.Set("CortexAPIVersion", consts.CortexVersion)
197188

189+
timeout := 600 * time.Second
190+
if request.URL.Path == "/info" {
191+
timeout = 10 * time.Second
192+
}
193+
194+
client := &http.Client{
195+
Timeout: timeout,
196+
Transport: &http.Transport{
197+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
198+
},
199+
}
200+
198201
response, err := client.Do(request)
199202
if err != nil {
200203
if operatorConfig.EnvName == "" {

cli/cmd/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ func printInfoOperatorResponse(clusterConfig clusterconfig.Config, operatorEndpo
802802

803803
infoResponse, err := cluster.Info(operatorConfig)
804804
if err != nil {
805+
fmt.Println(clusterConfig.UserStr())
805806
return err
806807
}
807808
infoResponse.ClusterConfig.Config = clusterConfig

0 commit comments

Comments
 (0)