Skip to content

Commit b39a175

Browse files
committed
fix failure scenario
1 parent f289de3 commit b39a175

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

pkg/diagnostic/cz/check.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"fmt"
88
net "net/http"
9+
"strings"
910

1011
"github.com/sirupsen/logrus"
1112

@@ -38,14 +39,17 @@ func (c *checker) Check(ctx context.Context, client *net.Client, accessor status
3839
_, err := http.Do(
3940
ctx, client, net.MethodGet,
4041
map[string]string{
41-
http.HeaderAuthorization: fmt.Sprintf("Bearer %s", c.cfg.Cloudzero.Credential),
42+
http.HeaderAuthorization: strings.TrimSpace(c.cfg.Cloudzero.Credential),
4243
http.HeaderAcceptEncoding: http.ContentTypeJSON,
4344
},
44-
map[string]string{
45-
http.QueryParamAccountID: c.cfg.Deployment.AccountID,
46-
http.QueryParamRegion: c.cfg.Deployment.Region,
47-
http.QueryParamClusterName: c.cfg.Deployment.ClusterName,
48-
}, url, nil,
45+
nil,
46+
// TODO: Add HEAD endpoint for container-metrics/status and pass these to check the API key
47+
// map[string]string{
48+
// http.QueryParamAccountID: c.cfg.Deployment.AccountID,
49+
// http.QueryParamRegion: c.cfg.Deployment.Region,
50+
// http.QueryParamClusterName: c.cfg.Deployment.ClusterName,
51+
// },
52+
url, nil,
4953
)
5054
if err == nil {
5155
accessor.AddCheck(&status.StatusCheck{Name: DiagnosticAPIKey, Passing: true})

pkg/diagnostic/runner/runner.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,29 @@ func (r *runner) Run(ctx context.Context) (status.Accessor, error) {
125125
}
126126

127127
// check the results (and set correct end code)
128+
processFailures(ctx, recorder, r)()
129+
130+
return recorder, nil
131+
}
132+
133+
// this function returns a function which will set an error code if necessary
134+
func processFailures(ctx context.Context, recorder status.Accessor, r *runner) func() {
135+
var handleFailure func() = func() {}
128136
recorder.ReadFromReport(func(cs *status.ClusterStatus) {
129137
if r.stage != config.ContextStageInit {
130138
return
131139
}
132140
for _, c := range cs.Checks {
133141
if !c.Passing {
134142
if chkr := r.reg.Get(config.DiagnosticInternalInitFailed); len(chkr) > 0 {
135-
_ = chkr[0].Check(ctx, r.client, recorder)
143+
// set to read handler since we already hold the lock
144+
handleFailure = func() {
145+
_ = chkr[0].Check(ctx, r.client, recorder)
146+
}
136147
}
137148
break
138149
}
139150
}
140151
})
141-
142-
return recorder, nil
152+
return handleFailure
143153
}

pkg/http/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Do(
6060
return http.StatusInternalServerError, errors.Wrap(err, fmt.Sprintf("network error: %s", req.URL.String()))
6161
}
6262
logrus.WithError(err).Error("Failed to make request")
63-
return http.StatusInternalServerError, ErrStatusInternalServerError
63+
return http.StatusInternalServerError, err
6464
}
6565
return resp.StatusCode, ToError(resp.StatusCode)
6666
}

0 commit comments

Comments
 (0)