Fix usage of housekeeping_interval flag

Defer calculation of `loadDecay`. Flags must be parsed before they can
be read, and therefore cannot be reliably be read at package init time.
This commit is contained in:
Tim St. Clair 2015-12-03 18:39:11 -08:00
parent 0d6015c741
commit 33216870d8

View File

@ -44,9 +44,6 @@ var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second,
var cgroupPathRegExp = regexp.MustCompile(".*devices.*:(.*?)[,;$].*")
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
var loadDecay = math.Exp(float64(-1 * (*HousekeepingInterval).Seconds() / 10))
type containerInfo struct {
info.ContainerReference
Subcontainers []info.ContainerReference
@ -67,6 +64,9 @@ type containerData struct {
lastUpdatedTime time.Time
lastErrorTime time.Time
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
loadDecay float64
// Whether to log the usage of this container when it is updated.
logUsage bool
@ -316,6 +316,8 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
}
cont.info.ContainerReference = ref
cont.loadDecay = math.Exp(float64(-cont.housekeepingInterval.Seconds() / 10))
err = cont.updateSpec()
if err != nil {
return nil, err
@ -460,7 +462,7 @@ func (c *containerData) updateLoad(newLoad uint64) {
if c.loadAvg < 0 {
c.loadAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization.
} else {
c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay)
c.loadAvg = c.loadAvg*c.loadDecay + float64(newLoad)*(1.0-c.loadDecay)
}
}