MCPcopy
hub / github.com/prometheus/prometheus / TestBlockWriter

Function TestBlockWriter

tsdb/blockwriter_test.go:30–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestBlockWriter(t *testing.T) {
31 ctx := context.Background()
32 outputDir := t.TempDir()
33 w, err := NewBlockWriter(promslog.NewNopLogger(), outputDir, DefaultBlockDuration)
34 require.NoError(t, err)
35
36 // Add some series.
37 app := w.Appender(ctx)
38 ts1, v1 := int64(44), float64(7)
39 _, err = app.Append(0, labels.FromStrings("a", "b"), ts1, v1)
40 require.NoError(t, err)
41 ts2, v2 := int64(55), float64(12)
42 _, err = app.Append(0, labels.FromStrings("c", "d"), ts2, v2)
43 require.NoError(t, err)
44 require.NoError(t, app.Commit())
45 id, err := w.Flush(ctx)
46 require.NoError(t, err)
47
48 // Confirm the block has the correct data.
49 blockpath := filepath.Join(outputDir, id.String())
50 b, err := OpenBlock(nil, blockpath, nil, nil)
51 require.NoError(t, err)
52 defer func() { require.NoError(t, b.Close()) }()
53 q, err := NewBlockQuerier(b, math.MinInt64, math.MaxInt64)
54 require.NoError(t, err)
55 series := query(t, q, labels.MustNewMatcher(labels.MatchRegexp, "", ".*"))
56 sample1 := []chunks.Sample{sample{t: ts1, f: v1}}
57 sample2 := []chunks.Sample{sample{t: ts2, f: v2}}
58 expectedSeries := map[string][]chunks.Sample{"{a=\"b\"}": sample1, "{c=\"d\"}": sample2}
59 require.Equal(t, expectedSeries, series)
60
61 require.NoError(t, w.Close())
62}
63
64func TestBlockWriter_AppenderV2(t *testing.T) {
65 ctx := context.Background()

Callers

nothing calls this directly

Calls 13

AppenderMethod · 0.95
FlushMethod · 0.95
CloseMethod · 0.95
FromStringsFunction · 0.92
MustNewMatcherFunction · 0.92
NewBlockWriterFunction · 0.85
OpenBlockFunction · 0.85
NewBlockQuerierFunction · 0.85
queryFunction · 0.70
AppendMethod · 0.65
CommitMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…