Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

compact: Verify for chunks outside of compacted time range. Added unit test for populateBlocs. #349

Conversation

bwplotka
Copy link
Contributor

@bwplotka bwplotka commented Jun 13, 2018

Rationales:

  • No "outside" chunks should happen.
  • No clear view what happens for various compact input.

NOTE: This PR should be merged after: #348

Signed-off-by: Bartek Plotka [email protected]

@krasi-georgiev
Copy link
Contributor

why not open the PR against his branch BenoitKnecht:fix-block-boundaries so he can merge and both will get in at the same time.

@bwplotka
Copy link
Contributor Author

Sure I am ok with it as long as we decide what to do in @BenoitKnecht PR (:

@krasi-georgiev
Copy link
Contributor

time for a rebase and a review :)

@krasi-georgiev
Copy link
Contributor

ping @bwplotka

…t test for populateBlocs.

Signed-off-by: Bartek Plotka <[email protected]>
@bwplotka bwplotka force-pushed the issue347-extra-chunk-compaction branch from 52c79b2 to ea2a31b Compare September 21, 2018 19:33
Copy link
Contributor

@krasi-georgiev krasi-georgiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few small suggestions, but overall very easy to follow and very good tests to have,
Thanks Bartek!

compact_test.go Outdated
@@ -401,3 +405,333 @@ type erringBReader struct{}
func (erringBReader) Index() (IndexReader, error) { return nil, errors.New("index") }
func (erringBReader) Chunks() (ChunkReader, error) { return nil, errors.New("chunks") }
func (erringBReader) Tombstones() (TombstoneReader, error) { return nil, errors.New("tombstones") }

type mockedBReader struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets call this just mockBReader , the same for mockIndexWriter

And lets put these in the corresponding files: mockBReader in block_test.go and mockIndexWriter in index_test.go

to make it easier to find when looking for mocks when writing new tests.

compact_test.go Outdated
func (nopChunkWriter) WriteChunks(chunks ...chunks.Meta) error { return nil }
func (nopChunkWriter) Close() error { return nil }

var populateBlocksCases = []struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this inside the TestCompaction_populateBlock defitnition?

compact_test.go Outdated
func (nopChunkWriter) Close() error { return nil }

var populateBlocksCases = []struct {
inputBlocks [][]seriesSamples
Copy link
Contributor

@krasi-georgiev krasi-georgiev Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a slice of seriesSamples why is it called inputBlocks ? later on it is used to created the chunk and index reader so maybe call it inputSeriesSamples or blockInput

the same for expectedBlock - expectedSeriesSamples or expectedBlockOutput

compact_test.go Outdated
var populateBlocksCases = []struct {
inputBlocks [][]seriesSamples
compactMinTime int64
compactMaxTime int64 // by default it is math.MaxInt64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 golang robot : Capital letter and full stop.

btw I had to look down the code to understand what is that comment for so maybe change it to:

// When not defined the test runner sets a default of math.MaxInt64.

compact_test.go Outdated
expectedErr error
}{
{
// Populate block from empty input should return error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of comments why not add as a title?
Title: "Populate block from empty input should return error."
and than use it in t.Run(test.Title, this way if it fails it will also show the title of the test case that failed

compact_test.go Outdated
},
compactMinTime: 0,
compactMaxTime: 20,
expectedErr: errors.New("found chunk with minTime: 10 maxTime: 30 outside of compacted minTime: 0 maxTime: 20"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be an overkill, but instead of error string matching we can define a custom error type and than match it.
expectedErr: tsdb.ErrChunkOutsider
_, ok := err.(tsdb.ErrChunkOutsider) or match the type directly

compact_test.go Outdated
chunks: [][]sample{{{t: 1}, {t: 9}}, {{t: 10}, {t: 19}}},
},
{
// no-chunk series should be dropped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Series without chunks should be dropped.

compact_test.go Outdated
inputBlocks: [][]seriesSamples{
{
{
lset: map[string]string{"a": "issue347"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue347 nice touch 😄 !

@krasi-georgiev
Copy link
Contributor

@bwplotka gentle reminder 😜

@bwplotka
Copy link
Contributor Author

bwplotka commented Oct 8, 2018

Yup, sorry, bit overloaded, will try to address it soon (current ETA is tomorrow)

Krasi Georgiev and others added 2 commits October 12, 2018 12:30
Moved mocks to dedicated file so they can be reused by other tests and
few other small nits.

Signed-off-by: Krasi Georgiev <[email protected]>
move mocks to dedicated file and some small nits
@bwplotka
Copy link
Contributor Author

Thanks @krasi-georgiev for helping out!

@krasi-georgiev krasi-georgiev merged commit 047b1b1 into prometheus-junkyard:master Oct 12, 2018
@bwplotka bwplotka deleted the issue347-extra-chunk-compaction branch October 12, 2018 10:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants