Skip to content

Fix flaky chunk tests by being explicit about now #656

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

Merged
merged 3 commits into from
Jan 16, 2018
Merged

Conversation

jml
Copy link
Contributor

@jml jml commented Jan 16, 2018

dummyChunkFor was consulting the system clock itself. This meant that tests
like TestChunkStore_Get would intermittently fail, because sometimes the
created chunks would have timestamps outside the window chosen within
TestChunkStore_Get (which itself consults the system clock).

This fixes the tests by making now a parameter of dummyChunkFor, which
makes the created chunks deterministic.

It also adds a now parameter to dummyChunk, which isn't strictly
necessary, but I believe is less error prone.

Fixes #646

Thanks to @bboreham for the hint about chunksToMatrix, which helped narrow this down.

`dummyChunkFor` was consulting the system clock itself. This meant that tests
like `TestChunkStore_Get` would intermittently fail, because _sometimes_ the
created chunks would have timestamps outside the window chosen within
`TestChunkStore_Get` (which itself consults the system clock).

This fixes the tests by making `now` a parameter of `dummyChunkFor`, which
makes the created chunks deterministic.

It also adds a `now` parameter to `dummyChunk`, which isn't strictly
necessary, but I believe is less error prone.
@jml jml requested a review from bboreham January 16, 2018 09:29
Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

I have no reason to suppose it's a problem, but it did strike me that you had removed a lot of uncertainty but left some still.

@@ -102,7 +102,7 @@ func TestNWayIntersect(t *testing.T) {
}

func BenchmarkByKeyLess(b *testing.B) {
a := ByKey{dummyChunk(), dummyChunk()}
a := ByKey{dummyChunk(model.Now()), dummyChunk(model.Now())}
Copy link
Contributor

Choose a reason for hiding this comment

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

even more deterministic to use the same value for these two calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be. I'd like to communicate that the value doesn't matter and that the values can be different.

@@ -139,10 +139,10 @@ func TestChunksToMatrix(t *testing.T) {
"bar": "baz",
"toms": "code",
}
chunk1 := dummyChunkFor(metric)
chunk1 := dummyChunkFor(model.Now(), metric)
Copy link
Contributor

Choose a reason for hiding this comment

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

even more deterministic to use the same value of now here as at the beginning of the function?

@@ -196,7 +196,7 @@ func TestChunksToMatrix(t *testing.T) {

func benchmarkChunk() Chunk {
// This is a real example from Kubernetes' embedded cAdvisor metrics, lightly obfuscated
return dummyChunkFor(model.Metric{
return dummyChunkFor(model.Now(), model.Metric{
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect now should be a parameter here so the benchmark can be as consistent as it wants to be

@@ -157,7 +157,7 @@ func TestChunksToMatrix(t *testing.T) {
"bar": "baz",
"toms": "code",
}
chunk3 := dummyChunkFor(otherMetric)
chunk3 := dummyChunkFor(model.Now(), otherMetric)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here on using same now

chunk1Samples, err := chunk1.Samples(chunk1.From, chunk1.Through)
require.NoError(t, err)
chunk2 := dummyChunkFor(metric)
chunk2 := dummyChunkFor(model.Now(), metric)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here on using same now

- Be even more deterministic by sharing `now` values
- Be even more deterministic by making benchmark chunk factory accept a `now` value
@@ -127,6 +127,8 @@ func (i *Ingester) Shutdown() {
}

func (i *Ingester) loop() {
level.Debug(util.Logger).Log("msg", "we get logs in failed tests")
Copy link
Contributor

Choose a reason for hiding this comment

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

is this meant to be here?

@jml
Copy link
Contributor Author

jml commented Jan 16, 2018 via email

@jml jml merged commit 7337b81 into master Jan 16, 2018
@jml jml deleted the 646-chunk-test-flake branch January 16, 2018 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chunk test flake
2 participants