Skip to content

Commit

Permalink
Initialize biggest ref to existing ref when reading a segment (#676)
Browse files Browse the repository at this point in the history
* initialize biggest ref to existing ref when reading a segment

* changelog

* allow new test to be less hard-coded

* explain error if test fails

* clarify changelog issue
  • Loading branch information
rfratto authored Jun 22, 2021
1 parent 868e5aa commit 9e6247a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- [FEATURE] Add TLS config options for tempo `remote_write`s. (@mapno)

- [BUGFIX] Fix issue where replaying a WAL caused incorrect metrics to be sent
over remote write. (@rfratto)

# v0.16.0 (2021-06-17)

- [FEATURE] (beta) A Grafana Agent Operator is now available. (@rfratto)
Expand Down
2 changes: 1 addition & 1 deletion pkg/prom/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (w *Storage) loadWAL(r *wal.Reader) (err error) {
}
}()

var biggestRef uint64 = 0
var biggestRef uint64 = w.ref.Load()

for d := range decoded {
switch v := d.(type) {
Expand Down
32 changes: 32 additions & 0 deletions pkg/prom/wal/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/go-kit/kit/log"
"github.com/grafana/agent/pkg/util"
"github.com/prometheus/prometheus/pkg/exemplar"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/pkg/value"
Expand Down Expand Up @@ -168,6 +169,37 @@ func TestStorage_ExistingWAL(t *testing.T) {
require.Equal(t, expectedExemplars, actualExemplars)
}

func TestStorage_ExistingWAL_RefID(t *testing.T) {
l := util.TestLogger(t)

walDir, err := ioutil.TempDir(os.TempDir(), "wal")
require.NoError(t, err)
defer os.RemoveAll(walDir)

s, err := NewStorage(l, nil, walDir)
require.NoError(t, err)

app := s.Appender(context.Background())
payload := buildSeries([]string{"foo", "bar", "baz", "blerg"})

// Write all the samples
for _, metric := range payload {
metric.Write(t, app)
}
require.NoError(t, app.Commit())

// Truncate the WAL to force creation of a new segment.
require.NoError(t, s.Truncate(0))
require.NoError(t, s.Close())

// Create a new storage and see what the ref ID is initialized to.
s, err = NewStorage(l, nil, walDir)
require.NoError(t, err)
defer require.NoError(t, s.Close())

require.Equal(t, uint64(len(payload)), s.ref.Load(), "cached ref ID should be equal to the number of series written")
}

func TestStorage_Truncate(t *testing.T) {
// Same as before but now do the following:
// after writing all the data, forcefully create 4 more segments,
Expand Down

0 comments on commit 9e6247a

Please sign in to comment.