|
|
|
@ -23,14 +23,15 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
"github.com/prometheus/tsdb/labels" |
|
|
|
|
"github.com/prometheus/tsdb/testutil" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func openTestDB(t testing.TB, opts *Options) (db *DB, close func()) { |
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test") |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
db, err = Open(tmpdir, nil, nil, opts) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
// Do not close the test database by default as it will deadlock on test failures.
|
|
|
|
|
return db, func() { os.RemoveAll(tmpdir) } |
|
|
|
@ -39,7 +40,7 @@ func openTestDB(t testing.TB, opts *Options) (db *DB, close func()) {
|
|
|
|
|
// query runs a matcher query against the querier and fully expands its data.
|
|
|
|
|
func query(t testing.TB, q Querier, matchers ...labels.Matcher) map[string][]sample { |
|
|
|
|
ss, err := q.Select(matchers...) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
result := map[string][]sample{} |
|
|
|
|
|
|
|
|
@ -52,12 +53,12 @@ func query(t testing.TB, q Querier, matchers ...labels.Matcher) map[string][]sam
|
|
|
|
|
t, v := it.At() |
|
|
|
|
samples = append(samples, sample{t: t, v: v}) |
|
|
|
|
} |
|
|
|
|
Ok(t, it.Err()) |
|
|
|
|
testutil.Ok(t, it.Err()) |
|
|
|
|
|
|
|
|
|
name := series.Labels().String() |
|
|
|
|
result[name] = samples |
|
|
|
|
} |
|
|
|
|
Ok(t, ss.Err()) |
|
|
|
|
testutil.Ok(t, ss.Err()) |
|
|
|
|
|
|
|
|
|
return result |
|
|
|
|
} |
|
|
|
@ -69,25 +70,25 @@ func TestDataAvailableOnlyAfterCommit(t *testing.T) {
|
|
|
|
|
app := db.Appender() |
|
|
|
|
|
|
|
|
|
_, err := app.Add(labels.FromStrings("foo", "bar"), 0, 0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
querier, err := db.Querier(0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
seriesSet := query(t, querier, labels.NewEqualMatcher("foo", "bar")) |
|
|
|
|
|
|
|
|
|
Equals(t, seriesSet, map[string][]sample{}) |
|
|
|
|
Ok(t, querier.Close()) |
|
|
|
|
testutil.Equals(t, seriesSet, map[string][]sample{}) |
|
|
|
|
testutil.Ok(t, querier.Close()) |
|
|
|
|
|
|
|
|
|
err = app.Commit() |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
querier, err = db.Querier(0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
defer querier.Close() |
|
|
|
|
|
|
|
|
|
seriesSet = query(t, querier, labels.NewEqualMatcher("foo", "bar")) |
|
|
|
|
|
|
|
|
|
Equals(t, seriesSet, map[string][]sample{`{foo="bar"}`: []sample{{t: 0, v: 0}}}) |
|
|
|
|
testutil.Equals(t, seriesSet, map[string][]sample{`{foo="bar"}`: []sample{{t: 0, v: 0}}}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDataNotAvailableAfterRollback(t *testing.T) { |
|
|
|
@ -96,18 +97,18 @@ func TestDataNotAvailableAfterRollback(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err := app.Add(labels.FromStrings("foo", "bar"), 0, 0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
err = app.Rollback() |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
querier, err := db.Querier(0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
defer querier.Close() |
|
|
|
|
|
|
|
|
|
seriesSet := query(t, querier, labels.NewEqualMatcher("foo", "bar")) |
|
|
|
|
|
|
|
|
|
Equals(t, seriesSet, map[string][]sample{}) |
|
|
|
|
testutil.Equals(t, seriesSet, map[string][]sample{}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDBAppenderAddRef(t *testing.T) { |
|
|
|
@ -117,41 +118,41 @@ func TestDBAppenderAddRef(t *testing.T) {
|
|
|
|
|
app1 := db.Appender() |
|
|
|
|
|
|
|
|
|
ref1, err := app1.Add(labels.FromStrings("a", "b"), 123, 0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
// Reference should already work before commit.
|
|
|
|
|
err = app1.AddFast(ref1, 124, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
err = app1.Commit() |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
app2 := db.Appender() |
|
|
|
|
|
|
|
|
|
// first ref should already work in next transaction.
|
|
|
|
|
err = app2.AddFast(ref1, 125, 0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
ref2, err := app2.Add(labels.FromStrings("a", "b"), 133, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
Assert(t, ref1 == ref2, "") |
|
|
|
|
testutil.Assert(t, ref1 == ref2, "") |
|
|
|
|
|
|
|
|
|
// Reference must be valid to add another sample.
|
|
|
|
|
err = app2.AddFast(ref2, 143, 2) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
err = app2.AddFast(9999999, 1, 1) |
|
|
|
|
Equals(t, errors.Cause(err), ErrNotFound) |
|
|
|
|
testutil.Equals(t, errors.Cause(err), ErrNotFound) |
|
|
|
|
|
|
|
|
|
Ok(t, app2.Commit()) |
|
|
|
|
testutil.Ok(t, app2.Commit()) |
|
|
|
|
|
|
|
|
|
q, err := db.Querier(0, 200) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
res := query(t, q, labels.NewEqualMatcher("a", "b")) |
|
|
|
|
|
|
|
|
|
Equals(t, map[string][]sample{ |
|
|
|
|
testutil.Equals(t, map[string][]sample{ |
|
|
|
|
labels.FromStrings("a", "b").String(): []sample{ |
|
|
|
|
{t: 123, v: 0}, |
|
|
|
|
{t: 124, v: 1}, |
|
|
|
@ -161,7 +162,7 @@ func TestDBAppenderAddRef(t *testing.T) {
|
|
|
|
|
}, |
|
|
|
|
}, res) |
|
|
|
|
|
|
|
|
|
Ok(t, q.Close()) |
|
|
|
|
testutil.Ok(t, q.Close()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDeleteSimple(t *testing.T) { |
|
|
|
@ -178,7 +179,7 @@ func TestDeleteSimple(t *testing.T) {
|
|
|
|
|
app.Add(labels.Labels{{"a", "b"}}, i, smpls[i]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
cases := []struct { |
|
|
|
|
intervals Intervals |
|
|
|
|
remaint []int64 |
|
|
|
@ -194,15 +195,15 @@ Outer:
|
|
|
|
|
// TODO(gouthamve): Reset the tombstones somehow.
|
|
|
|
|
// Delete the ranges.
|
|
|
|
|
for _, r := range c.intervals { |
|
|
|
|
Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
testutil.Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Compare the result.
|
|
|
|
|
q, err := db.Querier(0, numSamples) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
res, err := q.Select(labels.NewEqualMatcher("a", "b")) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
expSamples := make([]sample, 0, len(c.remaint)) |
|
|
|
|
for _, ts := range c.remaint { |
|
|
|
@ -214,13 +215,13 @@ Outer:
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if len(expSamples) == 0 { |
|
|
|
|
Assert(t, res.Next() == false, "") |
|
|
|
|
testutil.Assert(t, res.Next() == false, "") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
eok, rok := expss.Next(), res.Next() |
|
|
|
|
Equals(t, eok, rok) |
|
|
|
|
testutil.Equals(t, eok, rok) |
|
|
|
|
|
|
|
|
|
if !eok { |
|
|
|
|
continue Outer |
|
|
|
@ -228,13 +229,13 @@ Outer:
|
|
|
|
|
sexp := expss.At() |
|
|
|
|
sres := res.At() |
|
|
|
|
|
|
|
|
|
Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
testutil.Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
|
|
|
|
|
smplExp, errExp := expandSeriesIterator(sexp.Iterator()) |
|
|
|
|
smplRes, errRes := expandSeriesIterator(sres.Iterator()) |
|
|
|
|
|
|
|
|
|
Equals(t, errExp, errRes) |
|
|
|
|
Equals(t, smplExp, smplRes) |
|
|
|
|
testutil.Equals(t, errExp, errRes) |
|
|
|
|
testutil.Equals(t, smplExp, smplRes) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -245,13 +246,13 @@ func TestAmendDatapointCausesError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err := app.Add(labels.Labels{}, 0, 0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
app = db.Appender() |
|
|
|
|
_, err = app.Add(labels.Labels{}, 0, 1) |
|
|
|
|
Equals(t, ErrAmendSample, err) |
|
|
|
|
Ok(t, app.Rollback()) |
|
|
|
|
testutil.Equals(t, ErrAmendSample, err) |
|
|
|
|
testutil.Ok(t, app.Rollback()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDuplicateNaNDatapointNoAmendError(t *testing.T) { |
|
|
|
@ -260,12 +261,12 @@ func TestDuplicateNaNDatapointNoAmendError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err := app.Add(labels.Labels{}, 0, math.NaN()) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
app = db.Appender() |
|
|
|
|
_, err = app.Add(labels.Labels{}, 0, math.NaN()) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestNonDuplicateNaNDatapointsCausesAmendError(t *testing.T) { |
|
|
|
@ -274,12 +275,12 @@ func TestNonDuplicateNaNDatapointsCausesAmendError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err := app.Add(labels.Labels{}, 0, math.Float64frombits(0x7ff0000000000001)) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
app = db.Appender() |
|
|
|
|
_, err = app.Add(labels.Labels{}, 0, math.Float64frombits(0x7ff0000000000002)) |
|
|
|
|
Equals(t, ErrAmendSample, err) |
|
|
|
|
testutil.Equals(t, ErrAmendSample, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestSkippingInvalidValuesInSameTxn(t *testing.T) { |
|
|
|
@ -289,40 +290,40 @@ func TestSkippingInvalidValuesInSameTxn(t *testing.T) {
|
|
|
|
|
// Append AmendedValue.
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err := app.Add(labels.Labels{{"a", "b"}}, 0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
_, err = app.Add(labels.Labels{{"a", "b"}}, 0, 2) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
// Make sure the right value is stored.
|
|
|
|
|
q, err := db.Querier(0, 10) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
ssMap := query(t, q, labels.NewEqualMatcher("a", "b")) |
|
|
|
|
|
|
|
|
|
Equals(t, map[string][]sample{ |
|
|
|
|
testutil.Equals(t, map[string][]sample{ |
|
|
|
|
labels.New(labels.Label{"a", "b"}).String(): []sample{{0, 1}}, |
|
|
|
|
}, ssMap) |
|
|
|
|
|
|
|
|
|
Ok(t, q.Close()) |
|
|
|
|
testutil.Ok(t, q.Close()) |
|
|
|
|
|
|
|
|
|
// Append Out of Order Value.
|
|
|
|
|
app = db.Appender() |
|
|
|
|
_, err = app.Add(labels.Labels{{"a", "b"}}, 10, 3) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
_, err = app.Add(labels.Labels{{"a", "b"}}, 7, 5) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
q, err = db.Querier(0, 10) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
ssMap = query(t, q, labels.NewEqualMatcher("a", "b")) |
|
|
|
|
|
|
|
|
|
Equals(t, map[string][]sample{ |
|
|
|
|
testutil.Equals(t, map[string][]sample{ |
|
|
|
|
labels.New(labels.Label{"a", "b"}).String(): []sample{{0, 1}, {10, 3}}, |
|
|
|
|
}, ssMap) |
|
|
|
|
Ok(t, q.Close()) |
|
|
|
|
testutil.Ok(t, q.Close()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDB_Snapshot(t *testing.T) { |
|
|
|
@ -334,28 +335,28 @@ func TestDB_Snapshot(t *testing.T) {
|
|
|
|
|
mint := int64(1414141414000) |
|
|
|
|
for i := 0; i < 1000; i++ { |
|
|
|
|
_, err := app.Add(labels.FromStrings("foo", "bar"), mint+int64(i), 1.0) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
} |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
Ok(t, app.Rollback()) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, app.Rollback()) |
|
|
|
|
|
|
|
|
|
// create snapshot
|
|
|
|
|
snap, err := ioutil.TempDir("", "snap") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, db.Snapshot(snap)) |
|
|
|
|
Ok(t, db.Close()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, db.Snapshot(snap)) |
|
|
|
|
testutil.Ok(t, db.Close()) |
|
|
|
|
|
|
|
|
|
// reopen DB from snapshot
|
|
|
|
|
db, err = Open(snap, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
querier, err := db.Querier(mint, mint+1000) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
defer querier.Close() |
|
|
|
|
|
|
|
|
|
// sum values
|
|
|
|
|
seriesSet, err := querier.Select(labels.NewEqualMatcher("foo", "bar")) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
sum := 0.0 |
|
|
|
|
for seriesSet.Next() { |
|
|
|
@ -364,10 +365,10 @@ func TestDB_Snapshot(t *testing.T) {
|
|
|
|
|
_, v := series.At() |
|
|
|
|
sum += v |
|
|
|
|
} |
|
|
|
|
Ok(t, series.Err()) |
|
|
|
|
testutil.Ok(t, series.Err()) |
|
|
|
|
} |
|
|
|
|
Ok(t, seriesSet.Err()) |
|
|
|
|
Equals(t, sum, 1000.0) |
|
|
|
|
testutil.Ok(t, seriesSet.Err()) |
|
|
|
|
testutil.Equals(t, sum, 1000.0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestDB_SnapshotWithDelete(t *testing.T) { |
|
|
|
@ -384,7 +385,7 @@ func TestDB_SnapshotWithDelete(t *testing.T) {
|
|
|
|
|
app.Add(labels.Labels{{"a", "b"}}, i, smpls[i]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
cases := []struct { |
|
|
|
|
intervals Intervals |
|
|
|
|
remaint []int64 |
|
|
|
@ -400,25 +401,25 @@ Outer:
|
|
|
|
|
// TODO(gouthamve): Reset the tombstones somehow.
|
|
|
|
|
// Delete the ranges.
|
|
|
|
|
for _, r := range c.intervals { |
|
|
|
|
Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
testutil.Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// create snapshot
|
|
|
|
|
snap, err := ioutil.TempDir("", "snap") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, db.Snapshot(snap)) |
|
|
|
|
Ok(t, db.Close()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, db.Snapshot(snap)) |
|
|
|
|
testutil.Ok(t, db.Close()) |
|
|
|
|
|
|
|
|
|
// reopen DB from snapshot
|
|
|
|
|
db, err = Open(snap, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
// Compare the result.
|
|
|
|
|
q, err := db.Querier(0, numSamples) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
res, err := q.Select(labels.NewEqualMatcher("a", "b")) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
expSamples := make([]sample, 0, len(c.remaint)) |
|
|
|
|
for _, ts := range c.remaint { |
|
|
|
@ -430,13 +431,13 @@ Outer:
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if len(expSamples) == 0 { |
|
|
|
|
Assert(t, res.Next() == false, "") |
|
|
|
|
testutil.Assert(t, res.Next() == false, "") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
eok, rok := expss.Next(), res.Next() |
|
|
|
|
Equals(t, eok, rok) |
|
|
|
|
testutil.Equals(t, eok, rok) |
|
|
|
|
|
|
|
|
|
if !eok { |
|
|
|
|
continue Outer |
|
|
|
@ -444,13 +445,13 @@ Outer:
|
|
|
|
|
sexp := expss.At() |
|
|
|
|
sres := res.At() |
|
|
|
|
|
|
|
|
|
Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
testutil.Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
|
|
|
|
|
smplExp, errExp := expandSeriesIterator(sexp.Iterator()) |
|
|
|
|
smplRes, errRes := expandSeriesIterator(sres.Iterator()) |
|
|
|
|
|
|
|
|
|
Equals(t, errExp, errRes) |
|
|
|
|
Equals(t, smplExp, smplRes) |
|
|
|
|
testutil.Equals(t, errExp, errRes) |
|
|
|
|
testutil.Equals(t, smplExp, smplRes) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -528,7 +529,7 @@ func TestDB_e2e(t *testing.T) {
|
|
|
|
|
series = append(series, sample{ts, v}) |
|
|
|
|
|
|
|
|
|
_, err := app.Add(lset, ts, v) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
ts += rand.Int63n(timeInterval) + 1 |
|
|
|
|
} |
|
|
|
@ -536,7 +537,7 @@ func TestDB_e2e(t *testing.T) {
|
|
|
|
|
seriesMap[lset.String()] = series |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
// Query each selector on 1000 random time-ranges.
|
|
|
|
|
queries := []struct { |
|
|
|
@ -587,10 +588,10 @@ func TestDB_e2e(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
q, err := db.Querier(mint, maxt) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
ss, err := q.Select(qry.ms...) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
result := map[string][]sample{} |
|
|
|
|
|
|
|
|
@ -598,15 +599,15 @@ func TestDB_e2e(t *testing.T) {
|
|
|
|
|
x := ss.At() |
|
|
|
|
|
|
|
|
|
smpls, err := expandSeriesIterator(x.Iterator()) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
if len(smpls) > 0 { |
|
|
|
|
result[x.Labels().String()] = smpls |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(t, ss.Err()) |
|
|
|
|
Equals(t, expected, result) |
|
|
|
|
testutil.Ok(t, ss.Err()) |
|
|
|
|
testutil.Equals(t, expected, result) |
|
|
|
|
|
|
|
|
|
q.Close() |
|
|
|
|
} |
|
|
|
@ -617,30 +618,30 @@ func TestDB_e2e(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestWALFlushedOnDBClose(t *testing.T) { |
|
|
|
|
tmpdir, err := ioutil.TempDir("", "test") |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
defer os.RemoveAll(tmpdir) |
|
|
|
|
|
|
|
|
|
db, err := Open(tmpdir, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
lbls := labels.Labels{labels.Label{Name: "labelname", Value: "labelvalue"}} |
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err = app.Add(lbls, 0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
db.Close() |
|
|
|
|
|
|
|
|
|
db, err = Open(tmpdir, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
q, err := db.Querier(0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
values, err := q.LabelValues("labelname") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Equals(t, values, []string{"labelvalue"}) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Equals(t, values, []string{"labelvalue"}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestTombstoneClean(t *testing.T) { |
|
|
|
@ -657,7 +658,7 @@ func TestTombstoneClean(t *testing.T) {
|
|
|
|
|
app.Add(labels.Labels{{"a", "b"}}, i, smpls[i]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
cases := []struct { |
|
|
|
|
intervals Intervals |
|
|
|
|
remaint []int64 |
|
|
|
@ -673,27 +674,27 @@ func TestTombstoneClean(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// create snapshot
|
|
|
|
|
snap, err := ioutil.TempDir("", "snap") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, db.Snapshot(snap)) |
|
|
|
|
Ok(t, db.Close()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, db.Snapshot(snap)) |
|
|
|
|
testutil.Ok(t, db.Close()) |
|
|
|
|
|
|
|
|
|
// reopen DB from snapshot
|
|
|
|
|
db, err = Open(snap, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
for _, r := range c.intervals { |
|
|
|
|
Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
testutil.Ok(t, db.Delete(r.Mint, r.Maxt, labels.NewEqualMatcher("a", "b"))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// All of the setup for THIS line.
|
|
|
|
|
Ok(t, db.CleanTombstones()) |
|
|
|
|
testutil.Ok(t, db.CleanTombstones()) |
|
|
|
|
|
|
|
|
|
// Compare the result.
|
|
|
|
|
q, err := db.Querier(0, numSamples) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
res, err := q.Select(labels.NewEqualMatcher("a", "b")) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
expSamples := make([]sample, 0, len(c.remaint)) |
|
|
|
|
for _, ts := range c.remaint { |
|
|
|
@ -705,13 +706,13 @@ func TestTombstoneClean(t *testing.T) {
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if len(expSamples) == 0 { |
|
|
|
|
Assert(t, res.Next() == false, "") |
|
|
|
|
testutil.Assert(t, res.Next() == false, "") |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
eok, rok := expss.Next(), res.Next() |
|
|
|
|
Equals(t, eok, rok) |
|
|
|
|
testutil.Equals(t, eok, rok) |
|
|
|
|
|
|
|
|
|
if !eok { |
|
|
|
|
break |
|
|
|
@ -719,17 +720,17 @@ func TestTombstoneClean(t *testing.T) {
|
|
|
|
|
sexp := expss.At() |
|
|
|
|
sres := res.At() |
|
|
|
|
|
|
|
|
|
Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
testutil.Equals(t, sexp.Labels(), sres.Labels()) |
|
|
|
|
|
|
|
|
|
smplExp, errExp := expandSeriesIterator(sexp.Iterator()) |
|
|
|
|
smplRes, errRes := expandSeriesIterator(sres.Iterator()) |
|
|
|
|
|
|
|
|
|
Equals(t, errExp, errRes) |
|
|
|
|
Equals(t, smplExp, smplRes) |
|
|
|
|
testutil.Equals(t, errExp, errRes) |
|
|
|
|
testutil.Equals(t, smplExp, smplRes) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, b := range db.blocks { |
|
|
|
|
Equals(t, emptyTombstoneReader, b.tombstones) |
|
|
|
|
testutil.Equals(t, emptyTombstoneReader, b.tombstones) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -739,39 +740,39 @@ func TestDB_Retention(t *testing.T) {
|
|
|
|
|
defer os.RemoveAll(tmpdir) |
|
|
|
|
|
|
|
|
|
db, err := Open(tmpdir, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
lbls := labels.Labels{labels.Label{Name: "labelname", Value: "labelvalue"}} |
|
|
|
|
|
|
|
|
|
app := db.Appender() |
|
|
|
|
_, err = app.Add(lbls, 0, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
// create snapshot to make it create a block.
|
|
|
|
|
// TODO(gouthamve): Add a method to compact headblock.
|
|
|
|
|
snap, err := ioutil.TempDir("", "snap") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, db.Snapshot(snap)) |
|
|
|
|
Ok(t, db.Close()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, db.Snapshot(snap)) |
|
|
|
|
testutil.Ok(t, db.Close()) |
|
|
|
|
defer os.RemoveAll(snap) |
|
|
|
|
|
|
|
|
|
// reopen DB from snapshot
|
|
|
|
|
db, err = Open(snap, nil, nil, nil) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
Equals(t, 1, len(db.blocks)) |
|
|
|
|
testutil.Equals(t, 1, len(db.blocks)) |
|
|
|
|
|
|
|
|
|
app = db.Appender() |
|
|
|
|
_, err = app.Add(lbls, 100, 1) |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, app.Commit()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, app.Commit()) |
|
|
|
|
|
|
|
|
|
// Snapshot again to create another block.
|
|
|
|
|
snap, err = ioutil.TempDir("", "snap") |
|
|
|
|
Ok(t, err) |
|
|
|
|
Ok(t, db.Snapshot(snap)) |
|
|
|
|
Ok(t, db.Close()) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Ok(t, db.Snapshot(snap)) |
|
|
|
|
testutil.Ok(t, db.Close()) |
|
|
|
|
defer os.RemoveAll(snap) |
|
|
|
|
|
|
|
|
|
// reopen DB from snapshot
|
|
|
|
@ -779,14 +780,14 @@ func TestDB_Retention(t *testing.T) {
|
|
|
|
|
RetentionDuration: 10, |
|
|
|
|
BlockRanges: []int64{50}, |
|
|
|
|
}) |
|
|
|
|
Ok(t, err) |
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
|
|
|
|
|
Equals(t, 2, len(db.blocks)) |
|
|
|
|
testutil.Equals(t, 2, len(db.blocks)) |
|
|
|
|
|
|
|
|
|
// Now call rentention.
|
|
|
|
|
changes, err := db.retentionCutoff() |
|
|
|
|
Ok(t, err) |
|
|
|
|
Assert(t, changes, "there should be changes") |
|
|
|
|
Equals(t, 1, len(db.blocks)) |
|
|
|
|
Equals(t, int64(100), db.blocks[0].meta.MaxTime) // To verify its the right block.
|
|
|
|
|
testutil.Ok(t, err) |
|
|
|
|
testutil.Assert(t, changes, "there should be changes") |
|
|
|
|
testutil.Equals(t, 1, len(db.blocks)) |
|
|
|
|
testutil.Equals(t, int64(100), db.blocks[0].meta.MaxTime) // To verify its the right block.
|
|
|
|
|
} |
|
|
|
|