If start and end specified, ignore maxResults.
This commit is contained in:
parent
814c65059a
commit
bacf817e6a
@ -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".
|
||||
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user