MCPcopy
hub / github.com/prometheus/prometheus / createHead

Function createHead

tsdb/block_test.go:656–699  ·  view source on GitHub ↗
(tb testing.TB, w *wlog.WL, series []storage.Series, chunkDir string)

Source from the content-addressed store, hash-verified

654}
655
656func createHead(tb testing.TB, w *wlog.WL, series []storage.Series, chunkDir string) *Head {
657 opts := DefaultHeadOptions()
658 opts.ChunkDirRoot = chunkDir
659 head, err := NewHead(nil, nil, w, nil, opts, nil)
660 require.NoError(tb, err)
661
662 var it chunkenc.Iterator
663 ctx := context.Background()
664 app := head.Appender(ctx)
665 for _, s := range series {
666 ref := storage.SeriesRef(0)
667 it = s.Iterator(it)
668 lset := s.Labels()
669 typ := it.Next()
670 lastTyp := typ
671 for ; typ != chunkenc.ValNone; typ = it.Next() {
672 if lastTyp != typ {
673 // The behaviour of appender is undefined if samples of different types
674 // are appended to the same series in a single Commit().
675 require.NoError(tb, app.Commit())
676 app = head.Appender(ctx)
677 }
678
679 switch typ {
680 case chunkenc.ValFloat:
681 t, v := it.At()
682 ref, err = app.Append(ref, lset, t, v)
683 case chunkenc.ValHistogram:
684 t, h := it.AtHistogram(nil)
685 ref, err = app.AppendHistogram(ref, lset, t, h, nil)
686 case chunkenc.ValFloatHistogram:
687 t, fh := it.AtFloatHistogram(nil)
688 ref, err = app.AppendHistogram(ref, lset, t, nil, fh)
689 default:
690 err = fmt.Errorf("unknown sample type %s", typ.String())
691 }
692 require.NoError(tb, err)
693 lastTyp = typ
694 }
695 require.NoError(tb, it.Err())
696 }
697 require.NoError(tb, app.Commit())
698 return head
699}
700
701func createHeadWithOOOSamples(tb testing.TB, w *wlog.WL, series []storage.Series, chunkDir string, oooSampleFrequency int) *Head {
702 opts := DefaultHeadOptions()

Callers 3

BenchmarkQueriesFunction · 0.85
TestDBReadOnlyFunction · 0.85
TestDBReadOnly_AppendV2Function · 0.85

Calls 15

AppenderMethod · 0.95
NextMethod · 0.95
AtMethod · 0.95
AtHistogramMethod · 0.95
AtFloatHistogramMethod · 0.95
ErrMethod · 0.95
SeriesRefTypeAlias · 0.92
DefaultHeadOptionsFunction · 0.85
NewHeadFunction · 0.85
IteratorMethod · 0.65
LabelsMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…