MCPcopy
hub / github.com/prometheus/prometheus / testOOOAppendAndQuery

Function testOOOAppendAndQuery

tsdb/db_test.go:6777–6897  ·  view source on GitHub ↗
(t *testing.T, scenario sampleTypeScenario)

Source from the content-addressed store, hash-verified

6775}
6776
6777func testOOOAppendAndQuery(t *testing.T, scenario sampleTypeScenario) {
6778 opts := DefaultOptions()
6779 opts.OutOfOrderCapMax = 30
6780 opts.OutOfOrderTimeWindow = 4 * time.Hour.Milliseconds()
6781
6782 db := newTestDB(t, withOpts(opts))
6783 db.DisableCompactions()
6784
6785 s1 := labels.FromStrings("foo", "bar1")
6786 s2 := labels.FromStrings("foo", "bar2")
6787
6788 minutes := func(m int64) int64 { return m * time.Minute.Milliseconds() }
6789 appendedSamples := make(map[string][]chunks.Sample)
6790 totalSamples := 0
6791 addSample := func(lbls labels.Labels, fromMins, toMins int64, faceError bool) {
6792 app := db.Appender(context.Background())
6793 key := lbls.String()
6794 from, to := minutes(fromMins), minutes(toMins)
6795 for m := from; m <= to; m += time.Minute.Milliseconds() {
6796 val := rand.Intn(1000)
6797 _, s, err := scenario.appendFunc(app, lbls, m, int64(val))
6798 if faceError {
6799 require.Error(t, err)
6800 } else {
6801 require.NoError(t, err)
6802 appendedSamples[key] = append(appendedSamples[key], s)
6803 totalSamples++
6804 }
6805 }
6806 if faceError {
6807 require.NoError(t, app.Rollback())
6808 } else {
6809 require.NoError(t, app.Commit())
6810 }
6811 }
6812
6813 testQuery := func(from, to int64) {
6814 querier, err := db.Querier(from, to)
6815 require.NoError(t, err)
6816
6817 seriesSet := query(t, querier, labels.MustNewMatcher(labels.MatchRegexp, "foo", "bar."))
6818
6819 for k, v := range appendedSamples {
6820 sort.Slice(v, func(i, j int) bool {
6821 return v[i].T() < v[j].T()
6822 })
6823 appendedSamples[k] = v
6824 }
6825
6826 expSamples := make(map[string][]chunks.Sample)
6827 for k, samples := range appendedSamples {
6828 for _, s := range samples {
6829 if s.T() < from {
6830 continue
6831 }
6832 if s.T() > to {
6833 continue
6834 }

Callers 1

TestOOOAppendAndQueryFunction · 0.85

Calls 15

FromStringsFunction · 0.92
MustNewMatcherFunction · 0.92
newTestDBFunction · 0.85
withOptsFunction · 0.85
requireEqualSeriesFunction · 0.85
requireEqualOOOSamplesFunction · 0.85
addSampleFunction · 0.85
DisableCompactionsMethod · 0.80
MinOOOTimeMethod · 0.80
MaxOOOTimeMethod · 0.80
DefaultOptionsFunction · 0.70
queryFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…