MCPcopy
hub / github.com/prometheus/prometheus / TestDeleteSimple

Function TestDeleteSimple

tsdb/db_test.go:506–592  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

504}
505
506func TestDeleteSimple(t *testing.T) {
507 const numSamples int64 = 10
508
509 cases := []struct {
510 Intervals tombstones.Intervals
511 remaint []int64
512 }{
513 {
514 Intervals: tombstones.Intervals{{Mint: 0, Maxt: 3}},
515 remaint: []int64{4, 5, 6, 7, 8, 9},
516 },
517 {
518 Intervals: tombstones.Intervals{{Mint: 1, Maxt: 3}},
519 remaint: []int64{0, 4, 5, 6, 7, 8, 9},
520 },
521 {
522 Intervals: tombstones.Intervals{{Mint: 1, Maxt: 3}, {Mint: 4, Maxt: 7}},
523 remaint: []int64{0, 8, 9},
524 },
525 {
526 Intervals: tombstones.Intervals{{Mint: 1, Maxt: 3}, {Mint: 4, Maxt: 700}},
527 remaint: []int64{0},
528 },
529 { // This case is to ensure that labels and symbols are deleted.
530 Intervals: tombstones.Intervals{{Mint: 0, Maxt: 9}},
531 remaint: []int64{},
532 },
533 }
534
535 for _, c := range cases {
536 t.Run("", func(t *testing.T) {
537 db := newTestDB(t)
538
539 ctx := context.Background()
540 app := db.Appender(ctx)
541
542 smpls := make([]float64, numSamples)
543 for i := range numSamples {
544 smpls[i] = rand.Float64()
545 app.Append(0, labels.FromStrings("a", "b"), i, smpls[i])
546 }
547
548 require.NoError(t, app.Commit())
549
550 // TODO(gouthamve): Reset the tombstones somehow.
551 // Delete the ranges.
552 for _, r := range c.Intervals {
553 require.NoError(t, db.Delete(ctx, r.Mint, r.Maxt, labels.MustNewMatcher(labels.MatchEqual, "a", "b")))
554 }
555
556 // Compare the result.
557 q, err := db.Querier(0, numSamples)
558 require.NoError(t, err)
559
560 res := q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchEqual, "a", "b"))
561
562 expSamples := make([]chunks.Sample, 0, len(c.remaint))
563 for _, ts := range c.remaint {

Callers

nothing calls this directly

Calls 15

FromStringsFunction · 0.92
MustNewMatcherFunction · 0.92
NewListSeriesFunction · 0.92
ExpandSamplesFunction · 0.92
newTestDBFunction · 0.85
newMockSeriesSetFunction · 0.85
RunMethod · 0.65
AppenderMethod · 0.65
AppendMethod · 0.65
CommitMethod · 0.65
DeleteMethod · 0.65
QuerierMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…