MCPcopy Index your code
hub / github.com/cortexproject/cortex / CreateNHBlock

Function CreateNHBlock

integration/e2e/util.go:262–352  ·  view source on GitHub ↗
(
	ctx context.Context,
	rnd *rand.Rand,
	dir string,
	series []labels.Labels,
	numNHSamples int,
	mint, maxt int64,
	scrapeInterval int64,
	seriesSize int64,
)

Source from the content-addressed store, hash-verified

260}
261
262func CreateNHBlock(
263 ctx context.Context,
264 rnd *rand.Rand,
265 dir string,
266 series []labels.Labels,
267 numNHSamples int,
268 mint, maxt int64,
269 scrapeInterval int64,
270 seriesSize int64,
271) (id ulid.ULID, err error) {
272 headOpts := tsdb.DefaultHeadOptions()
273 headOpts.ChunkDirRoot = filepath.Join(dir, "chunks")
274 headOpts.ChunkRange = 10000000000
275 random := rand.New(rand.NewSource(time.Now().UnixNano()))
276 h, err := tsdb.NewHead(nil, nil, nil, nil, headOpts, nil)
277 if err != nil {
278 return id, errors.Wrap(err, "create head block")
279 }
280 defer func() {
281 runutil.CloseWithErrCapture(&err, h, "TSDB Head")
282 if e := os.RemoveAll(headOpts.ChunkDirRoot); e != nil {
283 err = errors.Wrap(e, "delete chunks dir")
284 }
285 }()
286
287 app := h.Appender(ctx)
288 for i := range series {
289 num := random.Intn(i + 1)
290 var ref storage.SeriesRef
291 start := RandRange(rnd, mint, maxt)
292 for j := range numNHSamples {
293 switch num % 4 {
294 case 0:
295 // append float histogram
296 ref, err = app.AppendHistogram(ref, series[i], start, nil, tsdbutil.GenerateTestFloatHistogram(int64(i+j)))
297 case 1:
298 // append int histogram
299 ref, err = app.AppendHistogram(ref, series[i], start, tsdbutil.GenerateTestHistogram(int64(i+j)), nil)
300 case 2:
301 // append float histogram with custom bucket
302 ref, err = app.AppendHistogram(ref, series[i], start, nil, tsdbutil.GenerateTestCustomBucketsFloatHistogram(int64(i+j)))
303 case 3:
304 // append int histogram with custom bucket
305 ref, err = app.AppendHistogram(ref, series[i], start, tsdbutil.GenerateTestCustomBucketsHistogram(int64(i+j)), nil)
306 }
307 if err != nil {
308 if rerr := app.Rollback(); rerr != nil {
309 err = errors.Wrapf(err, "rollback failed: %v", rerr)
310 }
311 return id, errors.Wrap(err, "add NH sample")
312 }
313 start += scrapeInterval
314 if start > maxt {
315 break
316 }
317 }
318 }
319 if err := app.Commit(); err != nil {

Callers 1

TestNativeHistogramFuzzFunction · 0.92

Calls 9

RandRangeFunction · 0.85
JoinMethod · 0.80
RollbackMethod · 0.80
WrapMethod · 0.65
StringMethod · 0.65
AppenderMethod · 0.45
AppendHistogramMethod · 0.45
CommitMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestNativeHistogramFuzzFunction · 0.74