@@ -655,28 +655,29 @@ func shouldRetryHasMatchingLog(err error) bool {
655655 strings .Contains (err .Error (), "Internal error encountered" )
656656}
657657
658- // QueryLog looks in the logging backend a log matching the given query,
658+ // QueryLog looks in the logging backend for a log matching the given query,
659659// over the trailing time interval specified by the given window.
660660// Returns the first log entry found, or an error if the log could not be
661661// found after some retries.
662662func QueryLog (ctx context.Context , logger * log.Logger , vm * VM , logNameRegex string , window time.Duration , query string , maxAttempts int ) (* cloudlogging.Entry , error ) {
663663 for attempt := 1 ; attempt <= maxAttempts ; attempt ++ {
664664 matchingLogs , err := findMatchingLogs (ctx , logger , vm , logNameRegex , window , query )
665+ found := len (matchingLogs ) > 0
665666 if err == nil {
666- if len ( matchingLogs ) > 0 {
667+ if found {
667668 // Success.
668669 return matchingLogs [0 ], nil
669670 }
670671 }
671- logger .Printf ("Query returned matchingLogs=%v, err=%v, attempt=%d" , matchingLogs , err , attempt )
672+ logger .Printf ("Query returned found=%t, matchingLogs=%v, err=%v, attempt=%d" , found , matchingLogs , err , attempt )
672673 if err != nil && ! shouldRetryHasMatchingLog (err ) {
673674 // A non-retryable error.
674675 return nil , fmt .Errorf ("QueryLog() failed: %v" , err )
675676 }
676677 // found was false, or we hit a retryable error.
677678 time .Sleep (logQueryBackoffDuration )
678679 }
679- return nil , fmt .Errorf ("QueryAllLogs () failed: %s not found, exhausted retries" , logNameRegex )
680+ return nil , fmt .Errorf ("QueryLog () failed: %s not found, exhausted retries" , logNameRegex )
680681}
681682
682683// QueryAllLogs looks in the logging backend for logs matching the given query,
@@ -694,7 +695,7 @@ func QueryAllLogs(ctx context.Context, logger *log.Logger, vm *VM, logNameRegex
694695 logger .Printf ("Query returned matchingLogs=%v, err=%v, attempt=%d" , matchingLogs , err , attempt )
695696 if err != nil && ! shouldRetryHasMatchingLog (err ) {
696697 // A non-retryable error.
697- return nil , fmt .Errorf ("QueryLog () failed: %v" , err )
698+ return nil , fmt .Errorf ("QueryAllLogs () failed: %v" , err )
698699 }
699700 // found was false, or we hit a retryable error.
700701 time .Sleep (logQueryBackoffDuration )
0 commit comments