Improve logging around SQL ops (#3268)

<!-- This change is generated by MagicModules. -->
/cc @rileykarson
This commit is contained in:
The Magician 2019-03-18 11:38:58 -07:00 committed by Riley Karson
parent 0d6b100f2d
commit b309ccdaab
2 changed files with 31 additions and 6 deletions

View File

@ -98,11 +98,15 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc {
if !isRetryableError(err) {
return nil, "", fmt.Errorf("Not retriable error: %s", err)
}
log.Printf("[DEBUG] Saw error polling for op, but dismissed as retriable: %s", err)
if op == nil {
return nil, "", fmt.Errorf("Cannot continue, Operation is nil. %s", err)
}
}
log.Printf("[DEBUG] working with op %#v", op)
// Try to set the operation (so we can check it's Error/State),
// and fail if we can't.
if err = w.SetOp(op); err != nil {

View File

@ -3,6 +3,7 @@ package google
import (
"bytes"
"fmt"
"log"
sqladmin "google.golang.org/api/sqladmin/v1beta4"
)
@ -14,7 +15,11 @@ type SqlAdminOperationWaiter struct {
}
func (w *SqlAdminOperationWaiter) State() string {
if w == nil || w.Op == nil {
if w == nil {
return "Operation Waiter is nil!"
}
if w.Op == nil {
return "Operation is nil!"
}
@ -29,8 +34,13 @@ func (w *SqlAdminOperationWaiter) Error() error {
}
func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error {
var ok bool
w.Op, ok = op.(*sqladmin.Operation)
if op == nil {
// Starting as a log statement, this may be a useful error in the future
log.Printf("[DEBUG] attempted to set nil op")
}
sqlOp, ok := op.(*sqladmin.Operation)
w.Op = sqlOp
if !ok {
return fmt.Errorf("Unable to set operation. Bad type!")
}
@ -39,19 +49,30 @@ func (w *SqlAdminOperationWaiter) SetOp(op interface{}) error {
}
func (w *SqlAdminOperationWaiter) QueryOp() (interface{}, error) {
if w == nil || w.Op == nil {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, waiter is unset or nil.")
}
if w.Op == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
if w.Service == nil {
return nil, fmt.Errorf("Cannot query operation, service is nil.")
}
return w.Service.Operations.Get(w.Project, w.Op.Name).Do()
}
func (w *SqlAdminOperationWaiter) OpName() string {
if w == nil || w.Op == nil {
return "<nil>"
if w == nil {
return "<nil waiter>"
}
if w.Op == nil {
return "<nil op>"
}
return w.Op.Name
}