-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Fix InternalAutoDateHistogram reproducible failure #32723
Changes from 1 commit
02e20e4
87ce3ba
27f7422
91b0f8e
43cfe4a
ae2957c
9dd6436
18f7abe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,9 +84,16 @@ protected InternalAutoDateHistogram createTestInstance(String name, | |
return new InternalAutoDateHistogram(name, buckets, targetBuckets, bucketInfo, format, pipelineAggregators, metaData); | ||
} | ||
|
||
public void testGetAppropriateRounding() { | ||
/* | ||
This test was added to reproduce a bug where getAppropriateRounding was only ever using the first innerIntervals | ||
passed in, instead of using the interval associated with the loop. | ||
*/ | ||
public void testGetAppropriateRoundingUsesCorrectIntervals() { | ||
RoundingInfo[] roundings = new RoundingInfo[6]; | ||
DateTimeZone timeZone = DateTimeZone.UTC; | ||
// Since we pass 0 as the starting index to getAppropriateRounding, we'll also use | ||
// an innerInterval that is quite large, such that targetBuckets * roundings[i].getMaximumInnerInterval() | ||
// will be larger than the estimate. | ||
roundings[0] = new RoundingInfo(createRounding(DateTimeUnit.SECOND_OF_MINUTE, timeZone), | ||
1000L, 1000); | ||
roundings[1] = new RoundingInfo(createRounding(DateTimeUnit.MINUTES_OF_HOUR, timeZone), | ||
|
@@ -95,20 +102,16 @@ public void testGetAppropriateRounding() { | |
60 * 60 * 1000L, 1, 3, 12); | ||
|
||
OffsetDateTime timestamp = Instant.parse("2018-01-01T00:00:01.000Z").atOffset(ZoneOffset.UTC); | ||
// We want to pass a roundingIdx of zero, because in order to reproduce this bug, we need the function | ||
// to increment the rounding (because the bug was that the function would not use the innerIntervals | ||
// from the new rounding. | ||
int result = InternalAutoDateHistogram.getAppropriateRounding(timestamp.toEpochSecond()*1000, | ||
timestamp.plusDays(1).toEpochSecond()*1000, 0, roundings, 25); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we've also gotta start with an index that we know won't be used: to trigger the code path, the function needs to iterate past the first rounding. |
||
assertThat(result, equalTo(2)); | ||
} | ||
|
||
@Override | ||
protected void assertReduced(InternalAutoDateHistogram reduced, List<InternalAutoDateHistogram> inputs) { | ||
int roundingIdx = 0; | ||
for (InternalAutoDateHistogram histogram : inputs) { | ||
if (histogram.getBucketInfo().roundingIdx > roundingIdx) { | ||
roundingIdx = histogram.getBucketInfo().roundingIdx; | ||
} | ||
} | ||
RoundingInfo roundingInfo = roundingInfos[roundingIdx]; | ||
|
||
long lowest = Long.MAX_VALUE; | ||
long highest = 0; | ||
|
@@ -124,11 +127,14 @@ protected void assertReduced(InternalAutoDateHistogram reduced, List<InternalAut | |
} | ||
} | ||
|
||
int roundingIndex = reduced.getBucketInfo().roundingIdx; | ||
RoundingInfo roundingInfo = roundingInfos[roundingIndex]; | ||
|
||
long normalizedDuration = (highest - lowest) / roundingInfo.getRoughEstimateDurationMillis(); | ||
long innerIntervalToUse = 0; | ||
for (int j = roundingInfo.innerIntervals.length-1; j >= 0; j--) { | ||
int interval = roundingInfo.innerIntervals[j]; | ||
if (normalizedDuration / interval < maxNumberOfBuckets()) { | ||
if (normalizedDuration / interval < reduced.getTargetBuckets()) { | ||
innerIntervalToUse = interval; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
package org.elasticsearch.test; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Seed; | ||
import org.apache.lucene.util.SetOnce; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
|
@@ -229,6 +230,7 @@ protected T createUnmappedInstance(String name, | |
return createTestInstance(name, pipelineAggregators, metaData); | ||
} | ||
|
||
@Seed("ED2D551807CFA25B") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure you intend to commit this? |
||
public void testReduceRandom() { | ||
String name = randomAlphaOfLength(5); | ||
List<T> inputs = new ArrayList<>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a large innerInterval for the first rounding used by the function is important to trigger the problematic code path