Skip to content

Commit

Permalink
Merge pull request google#1010 from piosz/num-stats
Browse files Browse the repository at this point in the history
Added possibility to not ignore NumStats field in ContainerInfoRequest
  • Loading branch information
jimmidyson committed Dec 9, 2015
2 parents 1d2d38d + 9e739ec commit fde344c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (self ContainerReferenceSlice) Less(i, j int) bool { return self[i].Name <
// It specifies how much data users want to get about a container
type ContainerInfoRequest struct {
// Max number of stats to return. Specify -1 for all stats currently available.
// If start and end time are specified this limit is ignored.
// Default: 60
NumStats int `json:"num_stats,omitempty"`

Expand Down
8 changes: 1 addition & 7 deletions utils/timed_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,13 @@ func (self *TimedStore) Add(timestamp time.Time, item interface{}) {
}

// Returns up to maxResult elements in the specified time period (inclusive).
// Results are from first to last. maxResults of -1 means no limit. When first
// and last are specified, maxResults is ignored.
// Results are from first to last. maxResults of -1 means no limit.
func (self *TimedStore) InTimeRange(start, end time.Time, maxResults int) []interface{} {
// No stats, return empty.
if len(self.buffer) == 0 {
return []interface{}{}
}

// Return all results in a time range if specified.
if !start.IsZero() && !end.IsZero() {
maxResults = -1
}

var startIndex int
if start.IsZero() {
// None specified, start at the beginning.
Expand Down
4 changes: 2 additions & 2 deletions utils/timed_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func TestInTimeRange(t *testing.T) {
expectElements(t, sb.InTimeRange(createTime(3), createTime(5), 10), []int{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), []int{1, 2, 3, 4})
// Start and end time does't ignore maxResults.
expectElements(t, sb.InTimeRange(createTime(1), createTime(5), 1), []int{4})

// No start time.
expectElements(t, sb.InTimeRange(empty, createTime(5), 10), []int{1, 2, 3, 4})
Expand Down

0 comments on commit fde344c

Please sign in to comment.