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 {
|
type statsSummaryContainerHandlerWrapper struct {
|
||||||
handler ContainerHandler
|
handler ContainerHandler
|
||||||
currentSummary *info.ContainerStatsPercentiles
|
currentSummary *info.ContainerStatsPercentiles
|
||||||
prevStats *info.ContainerStats
|
prevStats *info.ContainerStats
|
||||||
numStats uint64
|
numStats uint64
|
||||||
sampler sampling.Sampler
|
sampler sampling.Sampler
|
||||||
lock sync.Mutex
|
dontSetTimestamp bool
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *statsSummaryContainerHandlerWrapper) GetSpec() (*info.ContainerSpec, error) {
|
func (self *statsSummaryContainerHandlerWrapper) GetSpec() (*info.ContainerSpec, error) {
|
||||||
@ -65,8 +66,9 @@ func (self *statsSummaryContainerHandlerWrapper) GetStats() (*info.ContainerStat
|
|||||||
if stats == nil {
|
if stats == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
// Only update timestamp if it is zero.
|
// update timestamp if it is required. This feature is for testibility.
|
||||||
if stats.Timestamp.IsZero() {
|
// In some test, we want the underlying handler to set timestamp.
|
||||||
|
if !self.dontSetTimestamp {
|
||||||
stats.Timestamp = time.Now()
|
stats.Timestamp = time.Now()
|
||||||
}
|
}
|
||||||
self.lock.Lock()
|
self.lock.Lock()
|
||||||
|
@ -164,6 +164,13 @@ func TestSampleCpuUsage(t *testing.T) {
|
|||||||
t.Error(err)
|
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
|
// request stats/obervation N+1 times, so that there will be N samples
|
||||||
for i := 0; i < N+1; i++ {
|
for i := 0; i < N+1; i++ {
|
||||||
_, err = handler.GetStats()
|
_, err = handler.GetStats()
|
||||||
|
Loading…
Reference in New Issue
Block a user