diff --git a/storage/memory/stats_buffer.go b/storage/memory/stats_buffer.go index a1ed7458..f5438c65 100644 --- a/storage/memory/stats_buffer.go +++ b/storage/memory/stats_buffer.go @@ -47,13 +47,19 @@ func (self *StatsBuffer) Add(item *info.ContainerStats) { } // Returns up to maxResult elements in the specified time period (inclusive). -// Results are from first to last. maxResults of -1 means no limit. +// Results are from first to last. maxResults of -1 means no limit. When first +// and last are specified, maxResults is ignored. func (self *StatsBuffer) InTimeRange(start, end time.Time, maxResults int) []*info.ContainerStats { // No stats, return empty. if self.size == 0 { return []*info.ContainerStats{} } + // Return all results in a time range if specified. + if !start.IsZero() && !end.IsZero() { + maxResults = -1 + } + // NOTE: Since we store the elments in descending timestamp order "start" will // be a higher index than "end". diff --git a/storage/memory/stats_buffer_test.go b/storage/memory/stats_buffer_test.go index 4ac28e63..f142e931 100644 --- a/storage/memory/stats_buffer_test.go +++ b/storage/memory/stats_buffer_test.go @@ -161,6 +161,9 @@ func TestInTimeRange(t *testing.T) { expectElements(t, sb.InTimeRange(createTime(3), createTime(5), 10), []int32{3, 4}) assert.Empty(sb.InTimeRange(createTime(5), createTime(5), 10)) + // Start and end time ignores maxResults. + expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 1), []int32{1, 2, 3, 4}) + // No start time. expectElements(t, sb.InTimeRange(empty, createTime(5), 10), []int32{1, 2, 3, 4}) expectElements(t, sb.InTimeRange(empty, createTime(4), 10), []int32{1, 2, 3, 4})