-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metadata: Fixed panic when no ext labels are set; Added more tests.
``` caller=fetcher.go:700 msg="block has no labels left, creating one" replica=deduped panic: assignment to entry in nil map goroutine 441 [running]: github.com/thanos-io/thanos/pkg/block.(*ReplicaLabelRemover).Modify(0xc000b19d70, 0x2b261e0, 0xc000c16d00, 0xc0008596e0, 0xc000b1a980, 0x0, 0x0) /remote-source/app/pkg/block/fetcher.go:701 +0x3cf github.com/thanos-io/thanos/pkg/block.(*BaseFetcher).fetch(0xc000d75d40, 0x2b261e0, 0xc000c16d00, 0xc000c16a40, 0xc000c16a00, 0x4, 0x4, 0xc000b0e590, 0x1, 0x1, ...) /remote-source/app/pkg/block/fetcher.go:441 +0x65d github.com/thanos-io/thanos/pkg/block.(*MetaFetcher).Fetch(0xc0002fe480, 0x2b261e0, 0xc000c16d00, 0x5528a0, 0xc000c16340, 0xc0005c6000, 0x8) /remote-source/app/pkg/block/fetcher.go:474 +0x9f github.com/thanos-io/thanos/pkg/compact.(*Syncer).SyncMetas(0xc000c67d80, 0x2b261e0, 0xc000c16d00, 0x0, 0x0) /remote-source/app/pkg/compact/compact.go:127 +0xc0 github.com/thanos-io/thanos/pkg/compact.(*BucketCompactor).Compact(0xc0002fed20, 0x2b261e0, 0xc000c16d00, 0x0, 0x0) /remote-source/app/pkg/compact/compact.go:945 +0x2c2 main.runCompact.func6(0xc000501c80, 0x0) /remote-source/app/cmd/thanos/compact.go:307 +0x15a main.runCompact.func7.1(0xc0006bbd70, 0xc000bbe0a0) /remote-source/app/cmd/thanos/compact.go:367 +0x99 github.com/thanos-io/thanos/pkg/runutil.Repeat(0x45d964b800, 0xc00005a660, 0xc0007e9f30, 0x0, 0x0) /remote-source/app/pkg/runutil/runutil.go:72 +0x91 main.runCompact.func7(0x0, 0x0) /remote-source/app/cmd/thanos/compact.go:366 +0x29a github.com/oklog/run.(*Group).Run.func1(0xc0001f9f20, 0xc000c67e00, 0xc000b0ecb0) /remote-source/deps/gomod/pkg/mod/github.com/oklog/[email protected]/group.go:38 +0x27 created by github.com/oklog/run.(*Group).Run /remote-source/deps/gomod/pkg/mod/github.com/oklog/[email protected]/group.go:37 +0xbb ``` Signed-off-by: Bartlomiej Plotka <[email protected]>
- Loading branch information
Showing
15 changed files
with
250 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package metadata | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/oklog/ulid" | ||
"github.com/prometheus/prometheus/tsdb" | ||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestMeta_ReadWrite(t *testing.T) { | ||
t.Run("empty write/read/write", func(t *testing.T) { | ||
b := bytes.Buffer{} | ||
testutil.Ok(t, Meta{}.Write(&b)) | ||
testutil.Equals(t, `{ | ||
"ulid": "00000000000000000000000000", | ||
"minTime": 0, | ||
"maxTime": 0, | ||
"stats": {}, | ||
"compaction": { | ||
"level": 0 | ||
}, | ||
"version": 0, | ||
"thanos": { | ||
"labels": null, | ||
"downsample": { | ||
"resolution": 0 | ||
}, | ||
"source": "" | ||
} | ||
} | ||
`, b.String()) | ||
_, err := read(ioutil.NopCloser(&b)) | ||
testutil.NotOk(t, err) | ||
testutil.Equals(t, "unexpected meta file version 0", err.Error()) | ||
}) | ||
|
||
t.Run("real write/read/write", func(t *testing.T) { | ||
b := bytes.Buffer{} | ||
m1 := Meta{ | ||
BlockMeta: tsdb.BlockMeta{ | ||
ULID: ulid.MustNew(5, nil), | ||
MinTime: 2424, | ||
MaxTime: 134, | ||
Version: 1, | ||
Compaction: tsdb.BlockMetaCompaction{ | ||
Sources: []ulid.ULID{ulid.MustNew(1, nil), ulid.MustNew(2, nil)}, | ||
Parents: []tsdb.BlockDesc{ | ||
{ | ||
ULID: ulid.MustNew(3, nil), | ||
MinTime: 442, | ||
MaxTime: 24225, | ||
}, | ||
}, | ||
Level: 123, | ||
}, | ||
Stats: tsdb.BlockStats{NumChunks: 14, NumSamples: 245, NumSeries: 4}, | ||
}, | ||
Thanos: Thanos{ | ||
Version: 1, | ||
Labels: map[string]string{"ext": "lset1"}, | ||
Source: ReceiveSource, | ||
Files: []File{ | ||
{RelPath: "index", SizeBytes: 1313}, | ||
}, | ||
Downsample: ThanosDownsample{ | ||
Resolution: 123144, | ||
}, | ||
}, | ||
} | ||
testutil.Ok(t, m1.Write(&b)) | ||
testutil.Equals(t, `{ | ||
"ulid": "00000000050000000000000000", | ||
"minTime": 2424, | ||
"maxTime": 134, | ||
"stats": { | ||
"numSamples": 245, | ||
"numSeries": 4, | ||
"numChunks": 14 | ||
}, | ||
"compaction": { | ||
"level": 123, | ||
"sources": [ | ||
"00000000010000000000000000", | ||
"00000000020000000000000000" | ||
], | ||
"parents": [ | ||
{ | ||
"ulid": "00000000030000000000000000", | ||
"minTime": 442, | ||
"maxTime": 24225 | ||
} | ||
] | ||
}, | ||
"version": 1, | ||
"thanos": { | ||
"version": 1, | ||
"labels": { | ||
"ext": "lset1" | ||
}, | ||
"downsample": { | ||
"resolution": 123144 | ||
}, | ||
"source": "receive", | ||
"files": [ | ||
{ | ||
"rel_path": "index", | ||
"size_bytes": 1313 | ||
} | ||
] | ||
} | ||
} | ||
`, b.String()) | ||
retMeta, err := read(ioutil.NopCloser(&b)) | ||
testutil.Ok(t, err) | ||
testutil.Equals(t, m1, *retMeta) | ||
}) | ||
|
||
t.Run("missing external labels write/read/write", func(t *testing.T) { | ||
b := bytes.Buffer{} | ||
m1 := Meta{ | ||
BlockMeta: tsdb.BlockMeta{ | ||
ULID: ulid.MustNew(5, nil), | ||
MinTime: 2424, | ||
MaxTime: 134, | ||
Version: 1, | ||
Compaction: tsdb.BlockMetaCompaction{ | ||
Sources: []ulid.ULID{ulid.MustNew(1, nil), ulid.MustNew(2, nil)}, | ||
Parents: []tsdb.BlockDesc{ | ||
{ | ||
ULID: ulid.MustNew(3, nil), | ||
MinTime: 442, | ||
MaxTime: 24225, | ||
}, | ||
}, | ||
Level: 123, | ||
}, | ||
Stats: tsdb.BlockStats{NumChunks: 14, NumSamples: 245, NumSeries: 4}, | ||
}, | ||
Thanos: Thanos{ | ||
Version: 1, | ||
Source: ReceiveSource, | ||
Files: []File{ | ||
{RelPath: "index", SizeBytes: 1313}, | ||
}, | ||
Downsample: ThanosDownsample{ | ||
Resolution: 123144, | ||
}, | ||
}, | ||
} | ||
testutil.Ok(t, m1.Write(&b)) | ||
testutil.Equals(t, `{ | ||
"ulid": "00000000050000000000000000", | ||
"minTime": 2424, | ||
"maxTime": 134, | ||
"stats": { | ||
"numSamples": 245, | ||
"numSeries": 4, | ||
"numChunks": 14 | ||
}, | ||
"compaction": { | ||
"level": 123, | ||
"sources": [ | ||
"00000000010000000000000000", | ||
"00000000020000000000000000" | ||
], | ||
"parents": [ | ||
{ | ||
"ulid": "00000000030000000000000000", | ||
"minTime": 442, | ||
"maxTime": 24225 | ||
} | ||
] | ||
}, | ||
"version": 1, | ||
"thanos": { | ||
"version": 1, | ||
"labels": null, | ||
"downsample": { | ||
"resolution": 123144 | ||
}, | ||
"source": "receive", | ||
"files": [ | ||
{ | ||
"rel_path": "index", | ||
"size_bytes": 1313 | ||
} | ||
] | ||
} | ||
} | ||
`, b.String()) | ||
retMeta, err := read(ioutil.NopCloser(&b)) | ||
testutil.Ok(t, err) | ||
|
||
// We expect map to be empty but allocated. | ||
testutil.Equals(t, map[string]string(nil), m1.Thanos.Labels) | ||
m1.Thanos.Labels = map[string]string{} | ||
testutil.Equals(t, m1, *retMeta) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.