Skip to content

Commit

Permalink
Add scalar support to promclient seriesIterator
Browse files Browse the repository at this point in the history
Fixes #219
  • Loading branch information
jacksontj committed Sep 25, 2019
1 parent ea447b6 commit 0af6618
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/promclient/iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type SeriesIterator struct {
// the given timestamp.
func (s *SeriesIterator) Seek(t int64) bool {
switch valueTyped := s.V.(type) {
case *model.Scalar: // From a vector
return int64(valueTyped.Timestamp) >= t
case *model.Sample: // From a vector
return int64(valueTyped.Timestamp) >= t
case *model.SampleStream: // from a Matrix
Expand All @@ -75,6 +77,8 @@ func (s *SeriesIterator) Seek(t int64) bool {
// At returns the current timestamp/value pair.
func (s *SeriesIterator) At() (t int64, v float64) {
switch valueTyped := s.V.(type) {
case *model.Scalar:
return int64(valueTyped.Timestamp), float64(valueTyped.Value)
case *model.Sample: // From a vector
return int64(valueTyped.Timestamp), float64(valueTyped.Value)
case *model.SampleStream: // from a Matrix
Expand All @@ -89,6 +93,12 @@ func (s *SeriesIterator) At() (t int64, v float64) {
// Next advances the iterator by one.
func (s *SeriesIterator) Next() bool {
switch valueTyped := s.V.(type) {
case *model.Scalar:
if s.offset < 0 {
s.offset = 0
return true
}
return false
case *model.Sample: // From a vector
if s.offset < 0 {
s.offset = 0
Expand All @@ -103,6 +113,7 @@ func (s *SeriesIterator) Next() bool {
return false
default:
msg := fmt.Sprintf("Unknown data type %v", reflect.TypeOf(s.V))
fmt.Println(msg)
panic(msg)
}
}
Expand All @@ -116,7 +127,7 @@ func (s *SeriesIterator) Err() error {
func (s *SeriesIterator) Labels() labels.Labels {
switch valueTyped := s.V.(type) {
case *model.Scalar:
panic("Unknown metric() scalar?")
return nil
case *model.Sample: // From a vector
ret := make(labels.Labels, 0, len(valueTyped.Metric))
for k, v := range valueTyped.Metric {
Expand Down

0 comments on commit 0af6618

Please sign in to comment.