MCPcopy
hub / github.com/prometheus/prometheus / testAppendableV2

Function testAppendableV2

util/teststorage/appender_test.go:84–129  ·  view source on GitHub ↗
(t *testing.T, appTest *Appendable, a storage.AppendableV2)

Source from the content-addressed store, hash-verified

82}
83
84func testAppendableV2(t *testing.T, appTest *Appendable, a storage.AppendableV2) {
85 for _, commit := range []bool{true, false} {
86 appTest.ResultReset()
87
88 app := a.AppenderV2(t.Context())
89
90 m1 := metadata.Metadata{Type: "gauge", Unit: "", Help: "other help text"}
91 e1 := exemplar.Exemplar{Labels: labels.FromStrings(model.MetricNameLabel, "yolo"), HasTs: true, Ts: 1}
92 _, err := app.Append(0, labels.FromStrings(model.MetricNameLabel, "test_metric1", "app", "v2"), -1, 1, 2, nil, nil, storage.AOptions{
93 MetricFamilyName: "test_metric1",
94 Metadata: m1,
95 Exemplars: []exemplar.Exemplar{e1},
96 })
97 require.NoError(t, err)
98
99 h := tsdbutil.GenerateTestHistogram(0)
100 _, err = app.Append(0, labels.FromStrings(model.MetricNameLabel, "test_metric2", "app", "v2"), -2, 2, 0, h, nil, storage.AOptions{})
101 require.NoError(t, err)
102
103 fh := tsdbutil.GenerateTestFloatHistogram(0)
104 _, err = app.Append(0, labels.FromStrings(model.MetricNameLabel, "test_metric3", "app", "v2"), -3, 3, 0, nil, fh, storage.AOptions{})
105 require.NoError(t, err)
106
107 exp := []Sample{
108 {L: labels.FromStrings(model.MetricNameLabel, "test_metric1", "app", "v2"), MF: "test_metric1", M: m1, ST: -1, T: 1, V: 2, ES: []exemplar.Exemplar{e1}},
109 {L: labels.FromStrings(model.MetricNameLabel, "test_metric2", "app", "v2"), ST: -2, T: 2, H: h},
110 {L: labels.FromStrings(model.MetricNameLabel, "test_metric3", "app", "v2"), ST: -3, T: 3, FH: fh},
111 }
112 testutil.RequireEqual(t, exp, appTest.PendingSamples())
113 require.Nil(t, appTest.ResultSamples())
114 require.Nil(t, appTest.RolledbackSamples())
115
116 if commit {
117 require.NoError(t, app.Commit())
118 require.Nil(t, appTest.PendingSamples())
119 testutil.RequireEqual(t, exp, appTest.ResultSamples())
120 require.Nil(t, appTest.RolledbackSamples())
121 break
122 }
123
124 require.NoError(t, app.Rollback())
125 require.Nil(t, appTest.PendingSamples())
126 require.Nil(t, appTest.ResultSamples())
127 testutil.RequireEqual(t, exp, appTest.RolledbackSamples())
128 }
129}
130
131func TestAppendable(t *testing.T) {
132 appTest := NewAppendable()

Callers 2

TestAppendableFunction · 0.85
TestAppendable_ThenFunction · 0.85

Calls 13

FromStringsFunction · 0.92
GenerateTestHistogramFunction · 0.92
RequireEqualFunction · 0.92
ResultResetMethod · 0.80
PendingSamplesMethod · 0.80
ResultSamplesMethod · 0.80
RolledbackSamplesMethod · 0.80
AppenderV2Method · 0.65
AppendMethod · 0.65
CommitMethod · 0.65
RollbackMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…