mirror of https://github.com/prometheus/prometheus
removed some unused code and moved mockSeriesSet in querier_test (#394)
Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>pull/5805/head
parent
d38516b1c2
commit
d05611c027
6
block.go
6
block.go
|
@ -185,16 +185,10 @@ type BlockMetaCompaction struct {
|
||||||
Failed bool `json:"failed,omitempty"`
|
Failed bool `json:"failed,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
flagNone = 0
|
|
||||||
flagStd = 1
|
|
||||||
)
|
|
||||||
|
|
||||||
const indexFilename = "index"
|
const indexFilename = "index"
|
||||||
const metaFilename = "meta.json"
|
const metaFilename = "meta.json"
|
||||||
|
|
||||||
func chunkDir(dir string) string { return filepath.Join(dir, "chunks") }
|
func chunkDir(dir string) string { return filepath.Join(dir, "chunks") }
|
||||||
func walDir(dir string) string { return filepath.Join(dir, "wal") }
|
|
||||||
|
|
||||||
func readMetaFile(dir string) (*BlockMeta, error) {
|
func readMetaFile(dir string) (*BlockMeta, error) {
|
||||||
b, err := ioutil.ReadFile(filepath.Join(dir, metaFilename))
|
b, err := ioutil.ReadFile(filepath.Join(dir, metaFilename))
|
||||||
|
|
|
@ -247,7 +247,7 @@ Outer:
|
||||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||||
}
|
}
|
||||||
|
|
||||||
expss := newListSeriesSet([]Series{
|
expss := newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ Outer:
|
||||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||||
}
|
}
|
||||||
|
|
||||||
expss := newListSeriesSet([]Series{
|
expss := newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ func TestTombstoneClean(t *testing.T) {
|
||||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||||
}
|
}
|
||||||
|
|
||||||
expss := newListSeriesSet([]Series{
|
expss := newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ Outer:
|
||||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||||
}
|
}
|
||||||
|
|
||||||
expss := newListSeriesSet([]Series{
|
expss := newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -553,7 +553,7 @@ func TestDelete_e2e(t *testing.T) {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expSs := newListSeriesSet(matchedSeries)
|
expSs := newMockSeriesSet(matchedSeries)
|
||||||
// Compare both SeriesSets.
|
// Compare both SeriesSets.
|
||||||
for {
|
for {
|
||||||
eok, rok := expSs.Next(), ss.Next()
|
eok, rok := expSs.Next(), ss.Next()
|
||||||
|
|
24
querier.go
24
querier.go
|
@ -892,30 +892,6 @@ func (it *deletedIterator) Err() error {
|
||||||
return it.it.Err()
|
return it.it.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockSeriesSet struct {
|
|
||||||
next func() bool
|
|
||||||
series func() Series
|
|
||||||
err func() error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *mockSeriesSet) Next() bool { return m.next() }
|
|
||||||
func (m *mockSeriesSet) At() Series { return m.series() }
|
|
||||||
func (m *mockSeriesSet) Err() error { return m.err() }
|
|
||||||
|
|
||||||
func newListSeriesSet(list []Series) *mockSeriesSet {
|
|
||||||
i := -1
|
|
||||||
return &mockSeriesSet{
|
|
||||||
next: func() bool {
|
|
||||||
i++
|
|
||||||
return i < len(list)
|
|
||||||
},
|
|
||||||
series: func() Series {
|
|
||||||
return list[i]
|
|
||||||
},
|
|
||||||
err: func() error { return nil },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type errSeriesSet struct {
|
type errSeriesSet struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,30 @@ import (
|
||||||
"github.com/prometheus/tsdb/testutil"
|
"github.com/prometheus/tsdb/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type mockSeriesSet struct {
|
||||||
|
next func() bool
|
||||||
|
series func() Series
|
||||||
|
err func() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockSeriesSet) Next() bool { return m.next() }
|
||||||
|
func (m *mockSeriesSet) At() Series { return m.series() }
|
||||||
|
func (m *mockSeriesSet) Err() error { return m.err() }
|
||||||
|
|
||||||
|
func newMockSeriesSet(list []Series) *mockSeriesSet {
|
||||||
|
i := -1
|
||||||
|
return &mockSeriesSet{
|
||||||
|
next: func() bool {
|
||||||
|
i++
|
||||||
|
return i < len(list)
|
||||||
|
},
|
||||||
|
series: func() Series {
|
||||||
|
return list[i]
|
||||||
|
},
|
||||||
|
err: func() error { return nil },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type mockSeriesIterator struct {
|
type mockSeriesIterator struct {
|
||||||
seek func(int64) bool
|
seek func(int64) bool
|
||||||
at func() (int64, float64)
|
at func() (int64, float64)
|
||||||
|
@ -101,14 +125,14 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||||
exp SeriesSet
|
exp SeriesSet
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
a: newListSeriesSet([]Series{
|
a: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
}, []sample{
|
}, []sample{
|
||||||
{t: 1, v: 1},
|
{t: 1, v: 1},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
b: newListSeriesSet([]Series{
|
b: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
}, []sample{
|
}, []sample{
|
||||||
|
@ -120,7 +144,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||||
{t: 1, v: 1},
|
{t: 1, v: 1},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
}, []sample{
|
}, []sample{
|
||||||
|
@ -135,7 +159,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: newListSeriesSet([]Series{
|
a: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"handler": "prometheus",
|
"handler": "prometheus",
|
||||||
"instance": "127.0.0.1:9090",
|
"instance": "127.0.0.1:9090",
|
||||||
|
@ -149,7 +173,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||||
{t: 1, v: 2},
|
{t: 1, v: 2},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
b: newListSeriesSet([]Series{
|
b: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"handler": "prometheus",
|
"handler": "prometheus",
|
||||||
"instance": "127.0.0.1:9090",
|
"instance": "127.0.0.1:9090",
|
||||||
|
@ -163,7 +187,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||||
{t: 2, v: 2},
|
{t: 2, v: 2},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"handler": "prometheus",
|
"handler": "prometheus",
|
||||||
"instance": "127.0.0.1:9090",
|
"instance": "127.0.0.1:9090",
|
||||||
|
@ -397,25 +421,25 @@ func TestBlockQuerier(t *testing.T) {
|
||||||
mint: 0,
|
mint: 0,
|
||||||
maxt: 0,
|
maxt: 0,
|
||||||
ms: []labels.Matcher{},
|
ms: []labels.Matcher{},
|
||||||
exp: newListSeriesSet([]Series{}),
|
exp: newMockSeriesSet([]Series{}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mint: 0,
|
mint: 0,
|
||||||
maxt: 0,
|
maxt: 0,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{}),
|
exp: newMockSeriesSet([]Series{}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mint: 1,
|
mint: 1,
|
||||||
maxt: 0,
|
maxt: 0,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{}),
|
exp: newMockSeriesSet([]Series{}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mint: 2,
|
mint: 2,
|
||||||
maxt: 6,
|
maxt: 6,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
},
|
},
|
||||||
|
@ -433,7 +457,7 @@ func TestBlockQuerier(t *testing.T) {
|
||||||
mint: 2,
|
mint: 2,
|
||||||
maxt: 6,
|
maxt: 6,
|
||||||
ms: []labels.Matcher{labels.NewPrefixMatcher("p", "abc")},
|
ms: []labels.Matcher{labels.NewPrefixMatcher("p", "abc")},
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "ab",
|
"a": "ab",
|
||||||
"p": "abce",
|
"p": "abce",
|
||||||
|
@ -567,7 +591,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||||
mint: 2,
|
mint: 2,
|
||||||
maxt: 7,
|
maxt: 7,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
},
|
},
|
||||||
|
@ -585,7 +609,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||||
mint: 2,
|
mint: 2,
|
||||||
maxt: 7,
|
maxt: 7,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("b", "b")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("b", "b")},
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
"b": "b",
|
"b": "b",
|
||||||
|
@ -603,7 +627,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||||
mint: 1,
|
mint: 1,
|
||||||
maxt: 4,
|
maxt: 4,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{
|
exp: newMockSeriesSet([]Series{
|
||||||
newSeries(map[string]string{
|
newSeries(map[string]string{
|
||||||
"a": "a",
|
"a": "a",
|
||||||
"b": "b",
|
"b": "b",
|
||||||
|
@ -616,7 +640,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||||
mint: 1,
|
mint: 1,
|
||||||
maxt: 3,
|
maxt: 3,
|
||||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||||
exp: newListSeriesSet([]Series{}),
|
exp: newMockSeriesSet([]Series{}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -1266,7 +1290,7 @@ func BenchmarkMergedSeriesSet(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
var sets []SeriesSet
|
var sets []SeriesSet
|
||||||
for _, s := range in {
|
for _, s := range in {
|
||||||
sets = append(sets, newListSeriesSet(s))
|
sets = append(sets, newMockSeriesSet(s))
|
||||||
}
|
}
|
||||||
ms := sel(sets)
|
ms := sel(sets)
|
||||||
|
|
||||||
|
|
9
wal.go
9
wal.go
|
@ -750,15 +750,6 @@ func (w *SegmentWAL) Close() error {
|
||||||
return errors.Wrapf(w.dirFile.Close(), "closing WAL dir %s", w.dirFile.Name())
|
return errors.Wrapf(w.dirFile.Close(), "closing WAL dir %s", w.dirFile.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
minSectorSize = 512
|
|
||||||
|
|
||||||
// walPageBytes is the alignment for flushing records to the backing Writer.
|
|
||||||
// It should be a multiple of the minimum sector size so that WAL can safely
|
|
||||||
// distinguish between torn writes and ordinary data corruption.
|
|
||||||
walPageBytes = 16 * minSectorSize
|
|
||||||
)
|
|
||||||
|
|
||||||
func (w *SegmentWAL) write(t WALEntryType, flag uint8, buf []byte) error {
|
func (w *SegmentWAL) write(t WALEntryType, flag uint8, buf []byte) error {
|
||||||
// Cut to the next segment if the entry exceeds the file size unless it would also
|
// Cut to the next segment if the entry exceeds the file size unless it would also
|
||||||
// exceed the size of a new segment.
|
// exceed the size of a new segment.
|
||||||
|
|
Loading…
Reference in New Issue