diff --git a/components/engine/daemon/stats/collector.go b/components/engine/daemon/stats/collector.go index 24d41a3d2e..6aa030c57a 100644 --- a/components/engine/daemon/stats/collector.go +++ b/components/engine/daemon/stats/collector.go @@ -58,6 +58,10 @@ func (s *Collector) Run() { var pairs []publishersPair for { + // Put sleep at the start so that it will always be hit, + // preventing a tight loop if no stats are collected. + time.Sleep(s.interval) + // it does not make sense in the first iteration, // but saves allocations in further iterations pairs = pairs[:0] @@ -108,8 +112,6 @@ func (s *Collector) Run() { logrus.Errorf("collecting stats for %s: %v", pair.container.ID, err) } } - - time.Sleep(s.interval) } }