re-added TestDeleteUntilCurMax TestDelete_e2e (#382)

no logic changes just uncommented and fixed the issues.

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2018-09-17 14:28:55 +03:00 committed by GitHub
parent cb7f320d42
commit ad459ca1f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ import (
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
"sort"
"testing" "testing"
"github.com/prometheus/tsdb/chunkenc" "github.com/prometheus/tsdb/chunkenc"
@ -386,231 +387,203 @@ Outer:
} }
} }
// func TestDeleteUntilCurMax(t *testing.T) { func TestDeleteUntilCurMax(t *testing.T) {
// numSamples := int64(10) numSamples := int64(10)
hb, err := NewHead(nil, nil, nil, 1000000)
testutil.Ok(t, err)
app := hb.Appender()
smpls := make([]float64, numSamples)
for i := int64(0); i < numSamples; i++ {
smpls[i] = rand.Float64()
_, err := app.Add(labels.Labels{{"a", "b"}}, i, smpls[i])
testutil.Ok(t, err)
}
testutil.Ok(t, app.Commit())
testutil.Ok(t, hb.Delete(0, 10000, labels.NewEqualMatcher("a", "b")))
// dir, _ := ioutil.TempDir("", "test") // Test the series have been deleted.
// defer os.RemoveAll(dir) q, err := NewBlockQuerier(hb, 0, 100000)
testutil.Ok(t, err)
res, err := q.Select(labels.NewEqualMatcher("a", "b"))
testutil.Ok(t, err)
testutil.Assert(t, !res.Next(), "series didn't get deleted")
// hb := createTestHead(t, dir, 0, 2*numSamples) // Add again and test for presence.
// app := hb.Appender() app = hb.Appender()
_, err = app.Add(labels.Labels{{"a", "b"}}, 11, 1)
// smpls := make([]float64, numSamples) testutil.Ok(t, err)
// for i := int64(0); i < numSamples; i++ { testutil.Ok(t, app.Commit())
// smpls[i] = rand.Float64() q, err = NewBlockQuerier(hb, 0, 100000)
// app.Add(labels.Labels{{"a", "b"}}, i, smpls[i]) testutil.Ok(t, err)
// } res, err = q.Select(labels.NewEqualMatcher("a", "b"))
testutil.Ok(t, err)
// testutil.Ok(t, app.Commit()) testutil.Assert(t, res.Next(), "series don't exist")
// testutil.Ok(t, hb.Delete(0, 10000, labels.NewEqualMatcher("a", "b"))) exps := res.At()
// app = hb.Appender() it := exps.Iterator()
// _, err := app.Add(labels.Labels{{"a", "b"}}, 11, 1) ressmpls, err := expandSeriesIterator(it)
// testutil.Ok(t, err) testutil.Ok(t, err)
// testutil.Ok(t, app.Commit()) testutil.Equals(t, []sample{{11, 1}}, ressmpls)
}
// q := hb.Querier(0, 100000) func TestDelete_e2e(t *testing.T) {
// res := q.Select(labels.NewEqualMatcher("a", "b")) numDatapoints := 1000
numRanges := 1000
// require.True(t, res.Next()) timeInterval := int64(2)
// exps := res.At() // Create 8 series with 1000 data-points of different ranges, delete and run queries.
// it := exps.Iterator() lbls := [][]labels.Label{
// ressmpls, err := expandSeriesIterator(it) {
// testutil.Ok(t, err) {"a", "b"},
// testutil.Equals(t, []sample{{11, 1}}, ressmpls) {"instance", "localhost:9090"},
// } {"job", "prometheus"},
},
// func TestDelete_e2e(t *testing.T) { {
// numDatapoints := 1000 {"a", "b"},
// numRanges := 1000 {"instance", "127.0.0.1:9090"},
// timeInterval := int64(2) {"job", "prometheus"},
// maxTime := int64(2 * 1000) },
// minTime := int64(200) {
// // Create 8 series with 1000 data-points of different ranges, delete and run queries. {"a", "b"},
// lbls := [][]labels.Label{ {"instance", "127.0.0.1:9090"},
// { {"job", "prom-k8s"},
// {"a", "b"}, },
// {"instance", "localhost:9090"}, {
// {"job", "prometheus"}, {"a", "b"},
// }, {"instance", "localhost:9090"},
// { {"job", "prom-k8s"},
// {"a", "b"}, },
// {"instance", "127.0.0.1:9090"}, {
// {"job", "prometheus"}, {"a", "c"},
// }, {"instance", "localhost:9090"},
// { {"job", "prometheus"},
// {"a", "b"}, },
// {"instance", "127.0.0.1:9090"}, {
// {"job", "prom-k8s"}, {"a", "c"},
// }, {"instance", "127.0.0.1:9090"},
// { {"job", "prometheus"},
// {"a", "b"}, },
// {"instance", "localhost:9090"}, {
// {"job", "prom-k8s"}, {"a", "c"},
// }, {"instance", "127.0.0.1:9090"},
// { {"job", "prom-k8s"},
// {"a", "c"}, },
// {"instance", "localhost:9090"}, {
// {"job", "prometheus"}, {"a", "c"},
// }, {"instance", "localhost:9090"},
// { {"job", "prom-k8s"},
// {"a", "c"}, },
// {"instance", "127.0.0.1:9090"}, }
// {"job", "prometheus"}, seriesMap := map[string][]sample{}
// }, for _, l := range lbls {
// { seriesMap[labels.New(l...).String()] = []sample{}
// {"a", "c"}, }
// {"instance", "127.0.0.1:9090"}, dir, _ := ioutil.TempDir("", "test")
// {"job", "prom-k8s"}, defer os.RemoveAll(dir)
// }, hb, err := NewHead(nil, nil, nil, 100000)
// { testutil.Ok(t, err)
// {"a", "c"}, app := hb.Appender()
// {"instance", "localhost:9090"}, for _, l := range lbls {
// {"job", "prom-k8s"}, ls := labels.New(l...)
// }, series := []sample{}
// } ts := rand.Int63n(300)
for i := 0; i < numDatapoints; i++ {
// seriesMap := map[string][]sample{} v := rand.Float64()
// for _, l := range lbls { _, err := app.Add(ls, ts, v)
// seriesMap[labels.New(l...).String()] = []sample{} testutil.Ok(t, err)
// } series = append(series, sample{ts, v})
ts += rand.Int63n(timeInterval) + 1
// dir, _ := ioutil.TempDir("", "test") }
// defer os.RemoveAll(dir) seriesMap[labels.New(l...).String()] = series
}
// hb := createTestHead(t, dir, minTime, maxTime) testutil.Ok(t, app.Commit())
// app := hb.Appender() // Delete a time-range from each-selector.
dels := []struct {
// for _, l := range lbls { ms []labels.Matcher
// ls := labels.New(l...) drange Intervals
// series := []sample{} }{
{
// ts := rand.Int63n(300) ms: []labels.Matcher{labels.NewEqualMatcher("a", "b")},
// for i := 0; i < numDatapoints; i++ { drange: Intervals{{300, 500}, {600, 670}},
// v := rand.Float64() },
// if ts >= minTime && ts <= maxTime { {
// series = append(series, sample{ts, v}) ms: []labels.Matcher{
// } labels.NewEqualMatcher("a", "b"),
labels.NewEqualMatcher("job", "prom-k8s"),
// _, err := app.Add(ls, ts, v) },
// if ts >= minTime && ts <= maxTime { drange: Intervals{{300, 500}, {100, 670}},
// testutil.Ok(t, err) },
// } else { {
// testutil.EqualsError(t, err, ErrOutOfBounds.Error()) ms: []labels.Matcher{
// } labels.NewEqualMatcher("a", "c"),
labels.NewEqualMatcher("instance", "localhost:9090"),
// ts += rand.Int63n(timeInterval) + 1 labels.NewEqualMatcher("job", "prometheus"),
// } },
drange: Intervals{{300, 400}, {100, 6700}},
// seriesMap[labels.New(l...).String()] = series },
// } // TODO: Add Regexp Matchers.
}
// testutil.Ok(t, app.Commit()) for _, del := range dels {
// Reset the deletes everytime.
// // Delete a time-range from each-selector. hb.tombstones = NewMemTombstones()
// dels := []struct { for _, r := range del.drange {
// ms []labels.Matcher testutil.Ok(t, hb.Delete(r.Mint, r.Maxt, del.ms...))
// drange Intervals }
// }{ matched := labels.Slice{}
// { for _, ls := range lbls {
// ms: []labels.Matcher{labels.NewEqualMatcher("a", "b")}, s := labels.Selector(del.ms)
// drange: Intervals{{300, 500}, {600, 670}}, if s.Matches(ls) {
// }, matched = append(matched, ls)
// { }
// ms: []labels.Matcher{ }
// labels.NewEqualMatcher("a", "b"), sort.Sort(matched)
// labels.NewEqualMatcher("job", "prom-k8s"), for i := 0; i < numRanges; i++ {
// }, q, err := NewBlockQuerier(hb, 0, 100000)
// drange: Intervals{{300, 500}, {100, 670}}, testutil.Ok(t, err)
// }, defer q.Close()
// { ss, err := q.Select(del.ms...)
// ms: []labels.Matcher{ testutil.Ok(t, err)
// labels.NewEqualMatcher("a", "c"), // Build the mockSeriesSet.
// labels.NewEqualMatcher("instance", "localhost:9090"), matchedSeries := make([]Series, 0, len(matched))
// labels.NewEqualMatcher("job", "prometheus"), for _, m := range matched {
// }, smpls := seriesMap[m.String()]
// drange: Intervals{{300, 400}, {100, 6700}}, smpls = deletedSamples(smpls, del.drange)
// }, // Only append those series for which samples exist as mockSeriesSet
// // TODO: Add Regexp Matchers. // doesn't skip series with no samples.
// } // TODO: But sometimes SeriesSet returns an empty SeriesIterator
if len(smpls) > 0 {
// for _, del := range dels { matchedSeries = append(matchedSeries, newSeries(
// // Reset the deletes everytime. m.Map(),
// writeTombstoneFile(hb.dir, newEmptyTombstoneReader()) smpls,
// hb.tombstones = newEmptyTombstoneReader() ))
}
// for _, r := range del.drange { }
// testutil.Ok(t, hb.Delete(r.Mint, r.Maxt, del.ms...)) expSs := newListSeriesSet(matchedSeries)
// } // Compare both SeriesSets.
for {
// matched := labels.Slice{} eok, rok := expSs.Next(), ss.Next()
// for _, ls := range lbls { // Skip a series if iterator is empty.
// s := labels.Selector(del.ms) if rok {
// if s.Matches(ls) { for !ss.At().Iterator().Next() {
// matched = append(matched, ls) rok = ss.Next()
// } if !rok {
// } break
}
// sort.Sort(matched) }
}
// for i := 0; i < numRanges; i++ { testutil.Equals(t, eok, rok)
// mint := rand.Int63n(200) if !eok {
// maxt := mint + rand.Int63n(timeInterval*int64(numDatapoints)) break
}
// q := hb.Querier(mint, maxt) sexp := expSs.At()
// ss := q.Select(del.ms...) sres := ss.At()
testutil.Equals(t, sexp.Labels(), sres.Labels())
// // Build the mockSeriesSet. smplExp, errExp := expandSeriesIterator(sexp.Iterator())
// matchedSeries := make([]Series, 0, len(matched)) smplRes, errRes := expandSeriesIterator(sres.Iterator())
// for _, m := range matched { testutil.Equals(t, errExp, errRes)
// smpls := boundedSamples(seriesMap[m.String()], mint, maxt) testutil.Equals(t, smplExp, smplRes)
// smpls = deletedSamples(smpls, del.drange) }
}
// // Only append those series for which samples exist as mockSeriesSet }
// // doesn't skip series with no samples. return
// // TODO: But sometimes SeriesSet returns an empty SeriesIterator }
// if len(smpls) > 0 {
// matchedSeries = append(matchedSeries, newSeries(
// m.Map(),
// smpls,
// ))
// }
// }
// expSs := newListSeriesSet(matchedSeries)
// // Compare both SeriesSets.
// for {
// eok, rok := expSs.Next(), ss.Next()
// // Skip a series if iterator is empty.
// if rok {
// for !ss.At().Iterator().Next() {
// rok = ss.Next()
// if !rok {
// break
// }
// }
// }
// testutil.Equals(t, eok, rok, "next")
// if !eok {
// break
// }
// sexp := expSs.At()
// sres := ss.At()
// testutil.Equals(t, sexp.Labels(), sres.Labels(), "labels")
// smplExp, errExp := expandSeriesIterator(sexp.Iterator())
// smplRes, errRes := expandSeriesIterator(sres.Iterator())
// testutil.Equals(t, errExp, errRes, "samples error")
// testutil.Equals(t, smplExp, smplRes, "samples")
// }
// }
// }
// return
// }
func boundedSamples(full []sample, mint, maxt int64) []sample { func boundedSamples(full []sample, mint, maxt int64) []sample {
for len(full) > 0 { for len(full) > 0 {