Skip to content

Commit

Permalink
buildlet: include details in GCEError.Error
Browse files Browse the repository at this point in the history
Some of our logging in the coordinator includes pointers and repetition,
like so:

2022/09/27 19:16:27 failed with errors: [0xc02b50e120]
2022/09/27 19:16:27 Failed to create VM: "failed with errors: [0xc02b50e120]". Retrying after 1 second (attempt: 2).

The GCE error types only have MarshalJSON methods, so use that to show
more information. (This builds on the previous attempt in CL 428114.)
Remove the duplicate log, since the caller can log or otherwise handle
the error.

For golang/go#48857.

Change-Id: I0d31cac833ea617b4d722751e3ffe9a6689aeb87
Reviewed-on: https://go-review.googlesource.com/c/build/+/435379
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Run-TryBot: Dmitri Shuralyov <[email protected]>
Reviewed-by: Jenny Rakoczy <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Sep 28, 2022
1 parent cbf6b04 commit 21af757
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions buildlet/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
package buildlet

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -45,7 +46,20 @@ type GCEError struct {
}

func (q *GCEError) Error() string {
return fmt.Sprintf("failed with errors: %+v", q.OpErrors)
var buf bytes.Buffer
fmt.Fprintf(&buf, "%d GCE operation errors: ", len(q.OpErrors))
for i, e := range q.OpErrors {
if i != 0 {
buf.WriteString("; ")
}
b, err := json.Marshal(e)
if err != nil {
fmt.Fprintf(&buf, "json.Marshal(OpErrors[%d]): %v", i, err)
continue
}
buf.Write(b)
}
return buf.String()
}

func (q *GCEError) Is(target error) bool {
Expand Down Expand Up @@ -239,7 +253,6 @@ OpLoop:
if op.Error != nil {
err := &GCEError{OpErrors: make([]*compute.OperationErrorErrors, len(op.Error.Errors))}
copy(err.OpErrors, op.Error.Errors)
log.Println(err.Error())
return nil, err
}
break OpLoop
Expand Down
2 changes: 1 addition & 1 deletion internal/coordinator/pool/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (p *GCEBuildlet) GetBuildlet(ctx context.Context, hostType string, lg Logge
Zone: zone,
})
if errors.Is(err, buildlet.ErrQuotaExceeded) && ctx.Err() == nil {
log.Printf("Failed to create VM: %q. Retrying after 1 second (attempt: %d).", err, attempts)
log.Printf("Failed to create VM because quota exceeded. Retrying after 1 second (attempt: %d).", attempts)
attempts++
time.Sleep(time.Second)
continue
Expand Down

0 comments on commit 21af757

Please sign in to comment.