-
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
package org.elasticsearch.search.aggregations.bucket.histogram; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.rounding.DateTimeUnit; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.aggregations.InternalAggregations; | ||
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; | ||
|
@@ -28,17 +29,18 @@ | |
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; | ||
import org.elasticsearch.test.InternalMultiBucketAggregationTestCase; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.*; | ||
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. Jenkins is not amused ;) There's a setting in IntelliJ to avoid wildcard imports (at least until it hits an unreasonable number, I use 9999) and probably in other IDEs too. |
||
|
||
import static org.elasticsearch.common.unit.TimeValue.timeValueHours; | ||
import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; | ||
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; | ||
import static org.elasticsearch.search.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.createRounding; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class InternalAutoDateHistogramTests extends InternalMultiBucketAggregationTestCase<InternalAutoDateHistogram> { | ||
|
||
|
@@ -77,6 +79,22 @@ protected InternalAutoDateHistogram createTestInstance(String name, | |
return new InternalAutoDateHistogram(name, buckets, targetBuckets, bucketInfo, format, pipelineAggregators, metaData); | ||
} | ||
|
||
public void testGetAppropriateRounding() { | ||
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. This test seems to be testing a specific scenario rather than testing the method in general. Could we maybe make the name reflect this so its not assumed that its testing the method in general? Would it also be helpful to add a comment/javaDoc which explains the scenario it is testing? |
||
RoundingInfo[] roundings = new RoundingInfo[6]; | ||
DateTimeZone timeZone = DateTimeZone.UTC; | ||
roundings[0] = new RoundingInfo(createRounding(DateTimeUnit.SECOND_OF_MINUTE, timeZone), | ||
1000L, 1000); | ||
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. using a large innerInterval for the first rounding used by the function is important to trigger the problematic code path |
||
roundings[1] = new RoundingInfo(createRounding(DateTimeUnit.MINUTES_OF_HOUR, timeZone), | ||
60 * 1000L, 1, 5, 10, 30); | ||
roundings[2] = new RoundingInfo(createRounding(DateTimeUnit.HOUR_OF_DAY, timeZone), | ||
60 * 60 * 1000L, 1, 3, 12); | ||
|
||
OffsetDateTime timestamp = Instant.parse("2018-01-01T00:00:01.000Z").atOffset(ZoneOffset.UTC); | ||
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; | ||
|
@@ -100,9 +118,11 @@ protected void assertReduced(InternalAutoDateHistogram reduced, List<InternalAut | |
} | ||
} | ||
} | ||
|
||
long normalizedDuration = (highest - lowest) / roundingInfo.getRoughEstimateDurationMillis(); | ||
long innerIntervalToUse = 0; | ||
for (int interval : roundingInfo.innerIntervals) { | ||
for (int j = roundingInfo.innerIntervals.length-1; j >= 0; j--) { | ||
int interval = roundingInfo.innerIntervals[j]; | ||
if (normalizedDuration / interval < maxNumberOfBuckets()) { | ||
innerIntervalToUse = interval; | ||
} | ||
|
@@ -137,12 +157,6 @@ protected void assertReduced(InternalAutoDateHistogram reduced, List<InternalAut | |
assertEquals(expectedCounts, actualCounts); | ||
} | ||
|
||
@Override | ||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32215") | ||
public void testReduceRandom() { | ||
super.testReduceRandom(); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<InternalAutoDateHistogram> instanceReader() { | ||
return InternalAutoDateHistogram::new; | ||
|
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.
Whitespace nit: indentation looks wrong, and spaces around the
-
sign?