Skip to content

Commit

Permalink
Handle case where prometheus calls Seek() on an empty SeriesIterator
Browse files Browse the repository at this point in the history
Found a case where sometimes prometheus's buffer calls Seek() on an
iterator that previously returned false in Next(). This keeps it from
panicing
  • Loading branch information
jacksontj committed Apr 27, 2018
1 parent e056a20 commit 03d3cba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions promclient/iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (s *SeriesIterator) Seek(t int64) bool {
case *model.Sample: // From a vector
return int64(valueTyped.Timestamp) >= t
case *model.SampleStream: // from a Matrix
// If someone calls Seek() on an empty SampleStream, just return false
if len(valueTyped.Values) == 0 {
return false
}
for i := s.offset; i < len(valueTyped.Values); i++ {
s.offset = i
if int64(valueTyped.Values[s.offset].Timestamp) >= t {
Expand Down

0 comments on commit 03d3cba

Please sign in to comment.