From 78af2b02e1d640adc51a62173aafe1b071be7244 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Fri, 28 Feb 2020 14:49:57 -0800 Subject: [PATCH] Adjust period after each fh.update() call Signed-off-by: Ted Yu --- container/common/fsHandler.go | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/container/common/fsHandler.go b/container/common/fsHandler.go index 9de6a0f07f..f3f7e81fe9 100644 --- a/container/common/fsHandler.go +++ b/container/common/fsHandler.go @@ -106,31 +106,30 @@ func (fh *realFsHandler) update() error { } func (fh *realFsHandler) trackUsage() { - fh.update() longOp := time.Second for { + start := time.Now() + if err := fh.update(); err != nil { + klog.Errorf("failed to collect filesystem stats - %v", err) + fh.period = fh.period * 2 + if fh.period > maxBackoffFactor*fh.minPeriod { + fh.period = maxBackoffFactor * fh.minPeriod + } + } else { + fh.period = fh.minPeriod + } + duration := time.Since(start) + if duration > longOp { + // adapt longOp time so that message doesn't continue to print + // if the long duration is persistent either because of slow + // disk or lots of containers. + longOp = longOp + time.Second + klog.V(2).Infof("fs: disk usage and inodes count on following dirs took %v: %v; will not log again for this container unless duration exceeds %v", duration, []string{fh.rootfs, fh.extraDir}, longOp) + } select { case <-fh.stopChan: return case <-time.After(fh.period): - start := time.Now() - if err := fh.update(); err != nil { - klog.Errorf("failed to collect filesystem stats - %v", err) - fh.period = fh.period * 2 - if fh.period > maxBackoffFactor*fh.minPeriod { - fh.period = maxBackoffFactor * fh.minPeriod - } - } else { - fh.period = fh.minPeriod - } - duration := time.Since(start) - if duration > longOp { - // adapt longOp time so that message doesn't continue to print - // if the long duration is persistent either because of slow - // disk or lots of containers. - longOp = longOp + time.Second - klog.V(2).Infof("fs: disk usage and inodes count on following dirs took %v: %v; will not log again for this container unless duration exceeds %v", duration, []string{fh.rootfs, fh.extraDir}, longOp) - } } } }