mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 08:33:06 +00:00
removed some unused code and moved mockSeriesSet in querier_test (#394)
Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
parent
d38516b1c2
commit
d05611c027
6
block.go
6
block.go
@ -185,16 +185,10 @@ type BlockMetaCompaction struct {
|
||||
Failed bool `json:"failed,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
flagNone = 0
|
||||
flagStd = 1
|
||||
)
|
||||
|
||||
const indexFilename = "index"
|
||||
const metaFilename = "meta.json"
|
||||
|
||||
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) {
|
||||
b, err := ioutil.ReadFile(filepath.Join(dir, metaFilename))
|
||||
|
@ -247,7 +247,7 @@ Outer:
|
||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||
}
|
||||
|
||||
expss := newListSeriesSet([]Series{
|
||||
expss := newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||
})
|
||||
|
||||
@ -474,7 +474,7 @@ Outer:
|
||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||
}
|
||||
|
||||
expss := newListSeriesSet([]Series{
|
||||
expss := newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||
})
|
||||
|
||||
@ -753,7 +753,7 @@ func TestTombstoneClean(t *testing.T) {
|
||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||
}
|
||||
|
||||
expss := newListSeriesSet([]Series{
|
||||
expss := newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{"a": "b"}, expSamples),
|
||||
})
|
||||
|
||||
|
@ -355,7 +355,7 @@ Outer:
|
||||
expSamples = append(expSamples, sample{ts, smpls[ts]})
|
||||
}
|
||||
|
||||
expss := newListSeriesSet([]Series{
|
||||
expss := newMockSeriesSet([]Series{
|
||||
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.
|
||||
for {
|
||||
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()
|
||||
}
|
||||
|
||||
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 {
|
||||
err error
|
||||
}
|
||||
|
@ -28,6 +28,30 @@ import (
|
||||
"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 {
|
||||
seek func(int64) bool
|
||||
at func() (int64, float64)
|
||||
@ -101,14 +125,14 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||
exp SeriesSet
|
||||
}{
|
||||
{
|
||||
a: newListSeriesSet([]Series{
|
||||
a: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
}, []sample{
|
||||
{t: 1, v: 1},
|
||||
}),
|
||||
}),
|
||||
b: newListSeriesSet([]Series{
|
||||
b: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
}, []sample{
|
||||
@ -120,7 +144,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||
{t: 1, v: 1},
|
||||
}),
|
||||
}),
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
}, []sample{
|
||||
@ -135,7 +159,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
{
|
||||
a: newListSeriesSet([]Series{
|
||||
a: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"handler": "prometheus",
|
||||
"instance": "127.0.0.1:9090",
|
||||
@ -149,7 +173,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||
{t: 1, v: 2},
|
||||
}),
|
||||
}),
|
||||
b: newListSeriesSet([]Series{
|
||||
b: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"handler": "prometheus",
|
||||
"instance": "127.0.0.1:9090",
|
||||
@ -163,7 +187,7 @@ func TestMergedSeriesSet(t *testing.T) {
|
||||
{t: 2, v: 2},
|
||||
}),
|
||||
}),
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"handler": "prometheus",
|
||||
"instance": "127.0.0.1:9090",
|
||||
@ -397,25 +421,25 @@ func TestBlockQuerier(t *testing.T) {
|
||||
mint: 0,
|
||||
maxt: 0,
|
||||
ms: []labels.Matcher{},
|
||||
exp: newListSeriesSet([]Series{}),
|
||||
exp: newMockSeriesSet([]Series{}),
|
||||
},
|
||||
{
|
||||
mint: 0,
|
||||
maxt: 0,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||
exp: newListSeriesSet([]Series{}),
|
||||
exp: newMockSeriesSet([]Series{}),
|
||||
},
|
||||
{
|
||||
mint: 1,
|
||||
maxt: 0,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||
exp: newListSeriesSet([]Series{}),
|
||||
exp: newMockSeriesSet([]Series{}),
|
||||
},
|
||||
{
|
||||
mint: 2,
|
||||
maxt: 6,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
},
|
||||
@ -433,7 +457,7 @@ func TestBlockQuerier(t *testing.T) {
|
||||
mint: 2,
|
||||
maxt: 6,
|
||||
ms: []labels.Matcher{labels.NewPrefixMatcher("p", "abc")},
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "ab",
|
||||
"p": "abce",
|
||||
@ -567,7 +591,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||
mint: 2,
|
||||
maxt: 7,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
},
|
||||
@ -585,7 +609,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||
mint: 2,
|
||||
maxt: 7,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("b", "b")},
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
"b": "b",
|
||||
@ -603,7 +627,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||
mint: 1,
|
||||
maxt: 4,
|
||||
ms: []labels.Matcher{labels.NewEqualMatcher("a", "a")},
|
||||
exp: newListSeriesSet([]Series{
|
||||
exp: newMockSeriesSet([]Series{
|
||||
newSeries(map[string]string{
|
||||
"a": "a",
|
||||
"b": "b",
|
||||
@ -616,7 +640,7 @@ func TestBlockQuerierDelete(t *testing.T) {
|
||||
mint: 1,
|
||||
maxt: 3,
|
||||
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++ {
|
||||
var sets []SeriesSet
|
||||
for _, s := range in {
|
||||
sets = append(sets, newListSeriesSet(s))
|
||||
sets = append(sets, newMockSeriesSet(s))
|
||||
}
|
||||
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())
|
||||
}
|
||||
|
||||
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 {
|
||||
// Cut to the next segment if the entry exceeds the file size unless it would also
|
||||
// exceed the size of a new segment.
|
||||
|
Loading…
Reference in New Issue
Block a user