MCPcopy Index your code
hub / github.com/prometheus/prometheus / TestQueryHistogramFromBlocksWithCompaction

Function TestQueryHistogramFromBlocksWithCompaction

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

Source from the content-addressed store, hash-verified

8854}
8855
8856func TestQueryHistogramFromBlocksWithCompaction(t *testing.T) {
8857 t.Parallel()
8858 minute := func(m int) int64 { return int64(m) * time.Minute.Milliseconds() }
8859
8860 testBlockQuerying := func(t *testing.T, blockSeries ...[]storage.Series) {
8861 t.Helper()
8862
8863 opts := DefaultOptions()
8864 db := newTestDB(t, withOpts(opts))
8865
8866 var it chunkenc.Iterator
8867 exp := make(map[string][]chunks.Sample)
8868 for _, series := range blockSeries {
8869 createBlock(t, db.Dir(), series)
8870
8871 for _, s := range series {
8872 lbls := s.Labels().String()
8873 slice := exp[lbls]
8874 it = s.Iterator(it)
8875 smpls, err := storage.ExpandSamples(it, nil)
8876 require.NoError(t, err)
8877 slice = append(slice, smpls...)
8878 sort.Slice(slice, func(i, j int) bool {
8879 return slice[i].T() < slice[j].T()
8880 })
8881 exp[lbls] = slice
8882 }
8883 }
8884
8885 require.Empty(t, db.Blocks())
8886 require.NoError(t, db.reload())
8887 require.Len(t, db.Blocks(), len(blockSeries))
8888
8889 q, err := db.Querier(math.MinInt64, math.MaxInt64)
8890 require.NoError(t, err)
8891 res := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "__name__", ".*"))
8892 compareSeries(t, exp, res)
8893
8894 // Compact all the blocks together and query again.
8895 blocks := db.Blocks()
8896 blockDirs := make([]string, 0, len(blocks))
8897 for _, b := range blocks {
8898 blockDirs = append(blockDirs, b.Dir())
8899 }
8900 ids, err := db.compactor.Compact(db.Dir(), blockDirs, blocks)
8901 require.NoError(t, err)
8902 require.Len(t, ids, 1)
8903 require.NoError(t, db.reload())
8904 require.Len(t, db.Blocks(), 1)
8905
8906 q, err = db.Querier(math.MinInt64, math.MaxInt64)
8907 require.NoError(t, err)
8908 res = query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "__name__", ".*"))
8909
8910 // After compaction, we do not require "unknown" counter resets
8911 // due to origin from different overlapping chunks anymore.
8912 for _, ss := range exp {
8913 for i, s := range ss[1:] {

Callers

nothing calls this directly

Calls 15

ExpandSamplesFunction · 0.92
MustNewMatcherFunction · 0.92
newTestDBFunction · 0.85
withOptsFunction · 0.85
createBlockFunction · 0.85
compareSeriesFunction · 0.85
genHistogramSeriesFunction · 0.85
DefaultOptionsFunction · 0.70
queryFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…