MCPcopy
hub / github.com/prometheus/prometheus / TestAppendHistogramErrorDoesNotSetPendingCommit

Function TestAppendHistogramErrorDoesNotSetPendingCommit

tsdb/head_test.go:5723–5768  ·  view source on GitHub ↗

TestAppendHistogramErrorDoesNotSetPendingCommit verifies that when AppendHistogram fails with a sample-validation error (e.g. out-of-order), the existing memSeries's pendingCommit flag is not left set to true. A stuck pendingCommit flag keeps the series alive across head GC even though no samples ar

(t *testing.T)

Source from the content-addressed store, hash-verified

5721// A stuck pendingCommit flag keeps the series alive across head GC even
5722// though no samples are pending for it.
5723func TestAppendHistogramErrorDoesNotSetPendingCommit(t *testing.T) {
5724 for _, tc := range []struct {
5725 name string
5726 h *histogram.Histogram
5727 fh *histogram.FloatHistogram
5728 }{
5729 {name: "integer", h: tsdbutil.GenerateTestHistogram(0)},
5730 {name: "float", fh: tsdbutil.GenerateTestFloatHistogram(0)},
5731 } {
5732 t.Run(tc.name, func(t *testing.T) {
5733 head, _ := newTestHead(t, 1000, compression.None, false)
5734 require.NoError(t, head.Init(0))
5735
5736 lbls := labels.FromStrings("a", "b")
5737
5738 // Seed an in-order sample so the series exists with maxTime=200.
5739 app := head.Appender(context.Background())
5740 _, err := app.AppendHistogram(0, lbls, 200, tc.h, tc.fh)
5741 require.NoError(t, err)
5742 require.NoError(t, app.Commit())
5743
5744 ms, _, err := head.getOrCreate(lbls.Hash(), lbls, false)
5745 require.NoError(t, err)
5746 require.NotNil(t, ms)
5747 ms.Lock()
5748 pc := ms.pendingCommit
5749 ms.Unlock()
5750 require.False(t, pc, "pendingCommit should be cleared after a successful commit")
5751
5752 // Attempt an out-of-order append: same series, earlier timestamp,
5753 // OOO time window disabled. appendableHistogram returns
5754 // ErrOutOfOrderSample, so the sample is never recorded in the
5755 // appender's batch and Commit/Rollback never clears pendingCommit
5756 // for this series.
5757 app = head.Appender(context.Background())
5758 _, err = app.AppendHistogram(0, lbls, 100, tc.h, tc.fh)
5759 require.ErrorIs(t, err, storage.ErrOutOfOrderSample)
5760 require.NoError(t, app.Rollback())
5761
5762 ms.Lock()
5763 pc = ms.pendingCommit
5764 ms.Unlock()
5765 require.False(t, pc, "pendingCommit should remain false after a failed AppendHistogram")
5766 })
5767 }
5768}
5769
5770// Tests https://github.com/prometheus/prometheus/issues/9725.
5771func TestChunkSnapshotReplayBug(t *testing.T) {

Callers

nothing calls this directly

Calls 13

GenerateTestHistogramFunction · 0.92
FromStringsFunction · 0.92
newTestHeadFunction · 0.85
InitMethod · 0.80
LockMethod · 0.80
RunMethod · 0.65
AppenderMethod · 0.65
AppendHistogramMethod · 0.65
CommitMethod · 0.65
RollbackMethod · 0.65
getOrCreateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…