Skip to content

Commit

Permalink
Allow out of order samples to be written to the WAL. (#5487)
Browse files Browse the repository at this point in the history
* Allow out of order samples to be written to the WAL.

* changelog
  • Loading branch information
mattdurham authored Oct 16, 2023
1 parent a202b0a commit da2cd08
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Main (unreleased)

- Allow converting labels to structured metadata with Loki's structured_metadata stage. (@gonzalesraul)

- Allow Out of Order writing to the WAL for metrics. (@mattdurham)

### Other changes

- Use Go 1.21.3 for builds. (@tpaschalis)
Expand Down
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

0 comments on commit da2cd08

Please sign in to comment.