mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix off by one error in concreteSeriesSet (#3262)
This commit is contained in:
parent
abf7c975c9
commit
37ec2d5283
|
@ -151,11 +151,11 @@ type concreteSeriesSet struct {
|
||||||
|
|
||||||
func (c *concreteSeriesSet) Next() bool {
|
func (c *concreteSeriesSet) Next() bool {
|
||||||
c.cur++
|
c.cur++
|
||||||
return c.cur < len(c.series)
|
return c.cur-1 < len(c.series)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *concreteSeriesSet) At() storage.Series {
|
func (c *concreteSeriesSet) At() storage.Series {
|
||||||
return c.series[c.cur]
|
return c.series[c.cur-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *concreteSeriesSet) Err() error {
|
func (c *concreteSeriesSet) Err() error {
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
|
"github.com/prometheus/prometheus/prompb"
|
||||||
|
"github.com/prometheus/prometheus/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustNewLabelMatcher(mt labels.MatchType, name, val string) *labels.Matcher {
|
func mustNewLabelMatcher(mt labels.MatchType, name, val string) *labels.Matcher {
|
||||||
|
@ -92,3 +94,32 @@ func TestAddExternalLabels(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConcreteSeriesSet(t *testing.T) {
|
||||||
|
series1 := &concreteSeries{
|
||||||
|
labels: labels.FromStrings("foo", "bar"),
|
||||||
|
samples: []*prompb.Sample{&prompb.Sample{Value: 1, Timestamp: 2}},
|
||||||
|
}
|
||||||
|
series2 := &concreteSeries{
|
||||||
|
labels: labels.FromStrings("foo", "baz"),
|
||||||
|
samples: []*prompb.Sample{&prompb.Sample{Value: 3, Timestamp: 4}},
|
||||||
|
}
|
||||||
|
c := &concreteSeriesSet{
|
||||||
|
series: []storage.Series{series1, series2},
|
||||||
|
}
|
||||||
|
if !c.Next() {
|
||||||
|
t.Fatalf("Expected Next() to be true.")
|
||||||
|
}
|
||||||
|
if c.At() != series1 {
|
||||||
|
t.Fatalf("Unexpected series returned.")
|
||||||
|
}
|
||||||
|
if !c.Next() {
|
||||||
|
t.Fatalf("Expected Next() to be true.")
|
||||||
|
}
|
||||||
|
if c.At() != series2 {
|
||||||
|
t.Fatalf("Unexpected series returned.")
|
||||||
|
}
|
||||||
|
if c.Next() {
|
||||||
|
t.Fatalf("Expected Next() to be false.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue