Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eliminate stats log noise from stopped containers #1687

Merged
merged 2 commits into from
Jul 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions probe/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *container) StartGatheringStats() error {
}

go func() {
log.Infof("docker container: collecting stats for %s", c.container.ID)
log.Debugf("docker container: collecting stats for %s", c.container.ID)
req, err := http.NewRequest("GET", fmt.Sprintf("/containers/%s/stats", c.container.ID), nil)
if err != nil {
log.Errorf("docker container: %v", err)
Expand Down Expand Up @@ -221,20 +221,28 @@ func (c *container) StartGatheringStats() error {
c.Lock()
defer c.Unlock()

log.Infof("docker container: stopped collecting stats for %s", c.container.ID)
log.Debugf("docker container: stopped collecting stats for %s", c.container.ID)
c.statsConn = nil
}()

var stats docker.Stats
// Use a buffer since the codec library doesn't implicitly do it
bufReader := bufio.NewReader(resp.Body)
decoder := codec.NewDecoder(bufReader, &codec.JsonHandle{})
for err := decoder.Decode(&stats); err != io.EOF; err = decoder.Decode(&stats) {
if err != nil {
log.Errorf("docker container: error reading event for %s, did container stop? %v", c.container.ID, err)
return
for {
var stats docker.Stats
if err := decoder.Decode(&stats); err != nil {
if err == io.EOF {
break
}
// Unfortunately we typically get a different error
// than io.EOF. Yes, this is really the best we can do
// in go - https://github.com/golang/go/issues/4373
if opErr, ok := err.(*net.OpError); ok && opErr.Err.Error() == "use of closed network connection" {
break
}
log.Errorf("docker container: error reading event for %s: %v", c.container.ID, err)
break
}

c.Lock()
if c.numPending >= len(c.pendingStats) {
log.Warnf("docker container: dropping stats for %s", c.container.ID)
Expand All @@ -244,8 +252,6 @@ func (c *container) StartGatheringStats() error {
c.numPending++
}
c.Unlock()

stats = docker.Stats{}
}
}()

Expand Down