Skip to content

Commit 61bfccf

Browse files
committed
cmd/coordinator: display recent gitmirror failures as warnings
When gitmirror recovers from a recent failure, its status message begins with "ok; " followed by additional helpful context, instead of being just "ok". Start classifying such messages as warnings (yellow) rather than errors (bright red) to reduce false positives that are reported at https://farmer.golang.org/#health. Change-Id: I6fec7330daaec95c6d4b78849100ca54f2a3f34b Reviewed-on: https://go-review.googlesource.com/c/build/+/302650 Trust: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 9b76b08 commit 61bfccf

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

cmd/coordinator/status.go

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,34 @@ func newBasepinChecker() *healthChecker {
171171
}
172172
}
173173

174-
var lastGitMirrorErrors atomic.Value // of []string
174+
// gitMirrorStatus is the latest known status of the gitmirror service.
175+
var gitMirrorStatus = struct {
176+
sync.Mutex
177+
Errors []string
178+
Warnings []string
179+
}{Warnings: []string{"still checking"}}
175180

176181
func monitorGitMirror() {
177182
for {
178-
lastGitMirrorErrors.Store(gitMirrorErrors())
183+
errs, warns := gitMirrorErrors()
184+
gitMirrorStatus.Lock()
185+
gitMirrorStatus.Errors, gitMirrorStatus.Warnings = errs, warns
186+
gitMirrorStatus.Unlock()
179187
time.Sleep(30 * time.Second)
180188
}
181189
}
182190

183191
// gitMirrorErrors queries the status pages of all
184192
// running gitmirror instances and reports errors.
185-
func gitMirrorErrors() (errs []string) {
193+
//
194+
// It makes use of pool.KubeGoClient() to do the query.
195+
func gitMirrorErrors() (errs, warns []string) {
186196
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
187197
defer cancel()
188198
pods, err := pool.KubeGoClient().GetPods(ctx)
189199
if err != nil {
190200
log.Println("gitMirrorErrors: goKubeClient.GetPods:", err)
191-
return []string{"failed to get pods; can't query gitmirror status"}
201+
return []string{"failed to get pods; can't query gitmirror status"}, nil
192202
}
193203
var runningGitMirror []api.Pod
194204
for _, p := range pods {
@@ -198,29 +208,32 @@ func gitMirrorErrors() (errs []string) {
198208
runningGitMirror = append(runningGitMirror, p)
199209
}
200210
if len(runningGitMirror) == 0 {
201-
return []string{"no running gitmirror instances"}
211+
return []string{"no running gitmirror instances"}, nil
202212
}
203213
for _, pod := range runningGitMirror {
204214
// The gitmirror -http=:8585 status page URL is hardcoded here.
205215
// If the ReplicationController configuration changes (rare), this
206216
// health check will begin to fail until it's updated accordingly.
207-
instanceErrors := gitMirrorInstanceErrors(ctx, fmt.Sprintf("http://%s:8585/", pod.Status.PodIP))
208-
for _, err := range instanceErrors {
217+
instErrs, instWarns := gitMirrorInstanceErrors(ctx, fmt.Sprintf("http://%s:8585/", pod.Status.PodIP))
218+
for _, err := range instErrs {
209219
errs = append(errs, fmt.Sprintf("instance %s: %s", pod.Name, err))
210220
}
221+
for _, warn := range instWarns {
222+
warns = append(warns, fmt.Sprintf("instance %s: %s", pod.Name, warn))
223+
}
211224
}
212-
return errs
225+
return errs, warns
213226
}
214227

215-
func gitMirrorInstanceErrors(ctx context.Context, url string) (errs []string) {
228+
func gitMirrorInstanceErrors(ctx context.Context, url string) (errs, warns []string) {
216229
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
217230
res, err := http.DefaultClient.Do(req)
218231
if err != nil {
219-
return []string{err.Error()}
232+
return []string{err.Error()}, nil
220233
}
221234
defer res.Body.Close()
222235
if res.StatusCode != 200 {
223-
return []string{res.Status}
236+
return []string{res.Status}, nil
224237
}
225238
// TODO: add a JSON mode to gitmirror so we don't need to parse HTML.
226239
// This works for now. We control its output.
@@ -240,14 +253,19 @@ func gitMirrorInstanceErrors(ctx context.Context, url string) (errs []string) {
240253
if strings.Contains(line, "</html>") {
241254
break
242255
}
243-
return []string{fmt.Sprintf("error parsing line %q", line)}
256+
return []string{fmt.Sprintf("error parsing line %q", line)}, nil
257+
}
258+
if strings.HasPrefix(m[2], "ok; ") {
259+
// If the status begins with "ok", it can't be that bad.
260+
warns = append(warns, fmt.Sprintf("repo %s: %s", m[1], m[2]))
261+
continue
244262
}
245263
errs = append(errs, fmt.Sprintf("repo %s: %s", m[1], m[2]))
246264
}
247265
if err := bs.Err(); err != nil {
248266
errs = append(errs, err.Error())
249267
}
250-
return errs
268+
return errs, warns
251269
}
252270

253271
// $1 is repo; $2 is error message
@@ -259,14 +277,15 @@ func newGitMirrorChecker() *healthChecker {
259277
Title: "Git mirroring",
260278
DocURL: "https://github.com/golang/build/tree/master/cmd/gitmirror",
261279
Check: func(w *checkWriter) {
262-
ee, ok := lastGitMirrorErrors.Load().([]string)
263-
if !ok {
264-
w.warn("still checking")
265-
return
266-
}
267-
for _, v := range ee {
280+
gitMirrorStatus.Lock()
281+
errs, warns := gitMirrorStatus.Errors, gitMirrorStatus.Warnings
282+
gitMirrorStatus.Unlock()
283+
for _, v := range errs {
268284
w.error(v)
269285
}
286+
for _, v := range warns {
287+
w.warn(v)
288+
}
270289
},
271290
}
272291
}

0 commit comments

Comments
 (0)