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

Initialize biggest ref to existing ref when reading a segment #676

Merged
merged 5 commits into from
Jun 22, 2021
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
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