set timestamp by default. This behavior cannot be changed by users
This commit is contained in:
parent
f9b016dbe7
commit
c037cc70ca
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user