GCE provider: Log full contents of long operations

Dump JSON of long running (>1m) GCE operations.
This commit is contained in:
Zach Loafman 2016-06-07 06:56:49 -07:00
parent 7476d97781
commit ce6537aa48

View File

@ -402,19 +402,33 @@ func (gce *GCECloud) waitForOp(op *compute.Operation, getOperation func(operatio
return getErrorFromOp(op) return getErrorFromOp(op)
} }
opStart := time.Now()
opName := op.Name opName := op.Name
return wait.Poll(operationPollInterval, operationPollTimeoutDuration, func() (bool, error) { return wait.Poll(operationPollInterval, operationPollTimeoutDuration, func() (bool, error) {
start := time.Now() start := time.Now()
gce.operationPollRateLimiter.Accept() gce.operationPollRateLimiter.Accept()
duration := time.Now().Sub(start) duration := time.Now().Sub(start)
if duration > 5*time.Second { if duration > 5*time.Second {
glog.Infof("pollOperation: waited %v for %v", duration, opName) glog.Infof("pollOperation: throttled %v for %v", duration, opName)
} }
pollOp, err := getOperation(opName) pollOp, err := getOperation(opName)
if err != nil { if err != nil {
glog.Warningf("GCE poll operation %s failed: pollOp: [%v] err: [%v] getErrorFromOp: [%v]", opName, pollOp, err, getErrorFromOp(pollOp)) glog.Warningf("GCE poll operation %s failed: pollOp: [%v] err: [%v] getErrorFromOp: [%v]", opName, pollOp, err, getErrorFromOp(pollOp))
} }
return opIsDone(pollOp), getErrorFromOp(pollOp) done := opIsDone(pollOp)
if done {
duration := time.Now().Sub(opStart)
if duration > 1*time.Minute {
// Log the JSON. It's cleaner than the %v structure.
enc, err := op.MarshalJSON()
if err != nil {
glog.Warningf("waitForOperation: long operation (%v): %v (failed to encode to JSON: %v)", duration, op, err)
} else {
glog.Infof("waitForOperation: long operation (%v): %v", duration, string(enc))
}
}
}
return done, getErrorFromOp(pollOp)
}) })
} }