From c037cc70ca3d7fea7f0571f081949eda91f9a7f3 Mon Sep 17 00:00:00 2001 From: Nan Deng Date: Thu, 12 Jun 2014 13:33:23 -0700 Subject: [PATCH] set timestamp by default. This behavior cannot be changed by users --- container/statssum.go | 18 ++++++++++-------- container/statssum_test.go | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/container/statssum.go b/container/statssum.go index f4cf227e..e8e6b3a8 100644 --- a/container/statssum.go +++ b/container/statssum.go @@ -23,12 +23,13 @@ import ( ) type statsSummaryContainerHandlerWrapper struct { - handler ContainerHandler - currentSummary *info.ContainerStatsPercentiles - prevStats *info.ContainerStats - numStats uint64 - sampler sampling.Sampler - lock sync.Mutex + handler ContainerHandler + currentSummary *info.ContainerStatsPercentiles + prevStats *info.ContainerStats + numStats uint64 + sampler sampling.Sampler + dontSetTimestamp bool + lock sync.Mutex } func (self *statsSummaryContainerHandlerWrapper) GetSpec() (*info.ContainerSpec, error) { @@ -65,8 +66,9 @@ func (self *statsSummaryContainerHandlerWrapper) GetStats() (*info.ContainerStat if stats == nil { return nil, nil } - // Only update timestamp if it is zero. - if stats.Timestamp.IsZero() { + // update timestamp if it is required. This feature is for testibility. + // In some test, we want the underlying handler to set timestamp. + if !self.dontSetTimestamp { stats.Timestamp = time.Now() } self.lock.Lock() diff --git a/container/statssum_test.go b/container/statssum_test.go index 9a91e21e..325cad11 100644 --- a/container/statssum_test.go +++ b/container/statssum_test.go @@ -164,6 +164,13 @@ func TestSampleCpuUsage(t *testing.T) { t.Error(err) } + // we want to set our own time. + if w, ok := handler.(*statsSummaryContainerHandlerWrapper); ok { + w.dontSetTimestamp = true + } else { + t.Fatal("handler is not an instance of statsSummaryContainerHandlerWrapper") + } + // request stats/obervation N+1 times, so that there will be N samples for i := 0; i < N+1; i++ { _, err = handler.GetStats()