Merge pull request #1985 from lichuqiang/master

Return best-effort result when AllDockerContainers hits the cache not synced issue
This commit is contained in:
David Ashpole 2018-07-04 09:49:06 -07:00 committed by GitHub
commit 28c3221262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -15,7 +15,7 @@
package memory
import (
"fmt"
"errors"
"sync"
"time"
@ -26,6 +26,9 @@ import (
"github.com/golang/glog"
)
// ErrDataNotFound is the error resulting if failed to find a container in memory cache.
var ErrDataNotFound = errors.New("unable to find data in memory cache")
// TODO(vmarmol): See about refactoring this class, we have an unecessary redirection of containerCache and InMemoryCache.
// containerCache is used to store per-container information
type containerCache struct {
@ -101,7 +104,7 @@ func (self *InMemoryCache) RecentStats(name string, start, end time.Time, maxSta
self.lock.RLock()
defer self.lock.RUnlock()
if cstore, ok = self.containerCacheMap[name]; !ok {
return fmt.Errorf("unable to find data for container %v", name)
return ErrDataNotFound
}
return nil
}()

View File

@ -628,6 +628,11 @@ func (self *manager) AllDockerContainers(query *info.ContainerInfoRequest) (map[
for name, cont := range containers {
inf, err := self.containerDataToContainerInfo(cont, query)
if err != nil {
// Ignore the error because of race condition and return best-effort result.
if err == memory.ErrDataNotFound {
glog.Warningf("Error getting data for container %s because of race condition", name)
continue
}
return nil, err
}
output[name] = *inf