Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow out of order samples to be written to the WAL (#5487) #5490

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions pkg/metrics/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,6 @@ func (a *appender) Append(ref storage.SeriesRef, l labels.Labels, t int64, v flo
series.Lock()
defer series.Unlock()

if t < series.lastTs {
a.w.metrics.totalOutOfOrderSamples.Inc()
return 0, storage.ErrOutOfOrderSample
}

// NOTE(rfratto): always modify pendingSamples and sampleSeries together.
a.pendingSamples = append(a.pendingSamples, record.RefSample{
Ref: series.ref,
Expand Down Expand Up @@ -824,11 +819,6 @@ func (a *appender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int
series.Lock()
defer series.Unlock()

if t < series.lastTs {
a.w.metrics.totalOutOfOrderSamples.Inc()
return 0, storage.ErrOutOfOrderSample
}

switch {
case h != nil:
// NOTE(rfratto): always modify pendingHistograms and histogramSeries
Expand Down
29 changes: 29 additions & 0 deletions pkg/metrics/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,35 @@ func TestGlobalReferenceID_Normal(t *testing.T) {
require.True(t, ref3 == 2)
}

func TestDBAllowOOOSamples(t *testing.T) {
walDir := t.TempDir()

s, err := NewStorage(log.NewNopLogger(), nil, walDir)
require.NoError(t, err)
defer func() {
require.NoError(t, s.Close())
}()

app := s.Appender(context.Background())

// Write some samples
payload := buildSeries([]string{"foo", "bar", "baz"})
for _, metric := range payload {
metric.Write(t, app)
}

require.NoError(t, app.Commit())
for _, metric := range payload {
for _, sa := range metric.samples {
// We want to set the timestamp to before. This should no longer trigger an out of order.
sa.ts = sa.ts - 10_000
}
}
for _, metric := range payload {
metric.Write(t, app)
}
}

func BenchmarkAppendExemplar(b *testing.B) {
walDir := b.TempDir()

Expand Down