Fix and test bug in shardSeriesSet

This commit is contained in:
Fabian Reinartz 2017-01-03 19:02:42 +01:00
parent ac49f8c15e
commit ec99f99d3d
3 changed files with 54 additions and 3 deletions

4
db.go
View File

@ -261,7 +261,7 @@ func OpenShard(path string, i int, logger log.Logger) (*Shard, error) {
s := &Shard{
path: path,
logger: logger,
metrics: newShardMetrics(prometheus.DefaultRegisterer, i),
metrics: newShardMetrics(nil, i),
heads: heads,
persisted: persisted,
cutc: make(chan struct{}, 1),
@ -335,7 +335,7 @@ func (s *Shard) appendBatch(samples []hashedSample) error {
}
// TODO(fabxc): randomize over time and use better scoring function.
if head.bstats.SampleCount/(uint64(head.bstats.ChunkCount)+1) > 400 {
if head.bstats.SampleCount/(uint64(head.bstats.ChunkCount)+1) > 500 {
if err := s.cut(); err != nil {
s.logger.Log("msg", "cut failed", "err", err)
}

View File

@ -381,7 +381,7 @@ func (s *shardSeriesSet) compare() int {
if s.bdone {
return -1
}
return labels.Compare(s.a.At().Labels(), s.a.At().Labels())
return labels.Compare(s.a.At().Labels(), s.b.At().Labels())
}
func (s *shardSeriesSet) Next() bool {

View File

@ -139,6 +139,57 @@ func TestShardSeriesSet(t *testing.T) {
}),
}),
},
{
a: newListSeriesSet([]Series{
newSeries(map[string]string{
"handler": "prometheus",
"instance": "127.0.0.1:9090",
}, []sample{
{t: 1, v: 1},
}),
newSeries(map[string]string{
"handler": "prometheus",
"instance": "localhost:9090",
}, []sample{
{t: 1, v: 2},
}),
}),
b: newListSeriesSet([]Series{
newSeries(map[string]string{
"handler": "prometheus",
"instance": "127.0.0.1:9090",
}, []sample{
{t: 2, v: 1},
}),
newSeries(map[string]string{
"handler": "query",
"instance": "localhost:9090",
}, []sample{
{t: 2, v: 2},
}),
}),
exp: newListSeriesSet([]Series{
newSeries(map[string]string{
"handler": "prometheus",
"instance": "127.0.0.1:9090",
}, []sample{
{t: 1, v: 1},
{t: 2, v: 1},
}),
newSeries(map[string]string{
"handler": "prometheus",
"instance": "localhost:9090",
}, []sample{
{t: 1, v: 2},
}),
newSeries(map[string]string{
"handler": "query",
"instance": "localhost:9090",
}, []sample{
{t: 2, v: 2},
}),
}),
},
}
Outer: