Merge pull request #2402 from tedyu/period-adjuster

Adjust period after each fh.update() call
This commit is contained in:
David Ashpole 2020-02-28 15:01:05 -08:00 committed by GitHub
commit ad437f296a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}
}
}
}