-
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 AutoIntervalDateHistogram.testReduce random failures #32301
Changes from 4 commits
2fcf1ee
4cccc87
3bddd14
f9fa709
1d2f50b
54243e9
55a06aa
873d9f1
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,8 +20,6 @@ | |
package org.elasticsearch.search.aggregations.bucket.histogram; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.common.rounding.DateTimeUnit; | ||
import org.elasticsearch.common.rounding.Rounding; | ||
import org.elasticsearch.search.DocValueFormat; | ||
import org.elasticsearch.search.aggregations.InternalAggregations; | ||
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation; | ||
|
@@ -51,14 +49,9 @@ public class InternalAutoDateHistogramTests extends InternalMultiBucketAggregati | |
public void setUp() throws Exception { | ||
super.setUp(); | ||
format = randomNumericDocValueFormat(); | ||
|
||
roundingInfos = new RoundingInfo[6]; | ||
roundingInfos[0] = new RoundingInfo(Rounding.builder(DateTimeUnit.SECOND_OF_MINUTE).build(), 1, 5, 10, 30); | ||
roundingInfos[1] = new RoundingInfo(Rounding.builder(DateTimeUnit.MINUTES_OF_HOUR).build(), 1, 5, 10, 30); | ||
roundingInfos[2] = new RoundingInfo(Rounding.builder(DateTimeUnit.HOUR_OF_DAY).build(), 1, 3, 12); | ||
roundingInfos[3] = new RoundingInfo(Rounding.builder(DateTimeUnit.DAY_OF_MONTH).build(), 1, 7); | ||
roundingInfos[4] = new RoundingInfo(Rounding.builder(DateTimeUnit.MONTH_OF_YEAR).build(), 1, 3); | ||
roundingInfos[5] = new RoundingInfo(Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).build(), 1, 10, 20, 50, 100); | ||
AutoDateHistogramAggregationBuilder aggregationBuilder = new AutoDateHistogramAggregationBuilder("_name"); | ||
// TODO[PCS]: timezone set automagically here? | ||
roundingInfos = aggregationBuilder.buildRoundings(); | ||
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 actually not sure how the time zone would be picked up here which makes me think that its not being used currently and we are testing with only UTC at the moment so we probably need to fix that but we could do that in a follow up PR and just pass in UTC to create the roundings for this PR. I also think we need to create the roundings in 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. Looking at |
||
} | ||
|
||
@Override | ||
|
@@ -92,13 +85,50 @@ protected void assertReduced(InternalAutoDateHistogram reduced, List<InternalAut | |
roundingIdx = histogram.getBucketInfo().roundingIdx; | ||
} | ||
} | ||
Map<Long, Long> expectedCounts = new TreeMap<>(); | ||
for (Histogram histogram : inputs) { | ||
RoundingInfo roundingInfo = roundingInfos[roundingIdx]; | ||
|
||
long lowest = Long.MAX_VALUE; | ||
long highest = 0; | ||
for (InternalAutoDateHistogram histogram : inputs) { | ||
for (Histogram.Bucket bucket : histogram.getBuckets()) { | ||
expectedCounts.compute(roundingInfos[roundingIdx].rounding.round(((DateTime) bucket.getKey()).getMillis()), | ||
(key, oldValue) -> (oldValue == null ? 0 : oldValue) + bucket.getDocCount()); | ||
long bucketKey = ((DateTime) bucket.getKey()).getMillis(); | ||
if (bucketKey < lowest) { | ||
lowest = bucketKey; | ||
} | ||
if (bucketKey > highest) { | ||
highest = bucketKey; | ||
} | ||
} | ||
} | ||
long normalizedDuration = (highest - lowest) / roundingInfo.getRoughEstimateDurationMillis(); | ||
long innerIntervalToUse = 0; | ||
for (int interval : roundingInfo.innerIntervals) { | ||
if (normalizedDuration / interval < maxNumberOfBuckets()) { | ||
innerIntervalToUse = interval; | ||
} | ||
} | ||
Map<Long, Long> expectedCounts = new TreeMap<>(); | ||
long intervalInMillis = innerIntervalToUse*roundingInfo.getRoughEstimateDurationMillis(); | ||
for (long keyForBucket = roundingInfo.rounding.round(lowest); | ||
keyForBucket <= highest; | ||
keyForBucket = keyForBucket + intervalInMillis) { | ||
expectedCounts.put(keyForBucket, 0L); | ||
|
||
for (InternalAutoDateHistogram histogram : inputs) { | ||
for (Histogram.Bucket bucket : histogram.getBuckets()) { | ||
long bucketKey = ((DateTime) bucket.getKey()).getMillis(); | ||
long roundedBucketKey = roundingInfo.rounding.round(bucketKey); | ||
if (roundedBucketKey >= keyForBucket | ||
&& roundedBucketKey < keyForBucket + intervalInMillis) { | ||
long count = bucket.getDocCount(); | ||
expectedCounts.compute(keyForBucket, | ||
(key, oldValue) -> (oldValue == null ? 0 : oldValue) + count); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
Map<Long, Long> actualCounts = new TreeMap<>(); | ||
for (Histogram.Bucket bucket : reduced.getBuckets()) { | ||
actualCounts.compute(((DateTime) bucket.getKey()).getMillis(), | ||
|
@@ -117,12 +147,6 @@ protected Class<? extends ParsedMultiBucketAggregation> implementationClass() { | |
return ParsedAutoDateHistogram.class; | ||
} | ||
|
||
@Override | ||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32215") | ||
public void testReduceRandom() { | ||
super.testReduceRandom(); | ||
} | ||
|
||
@Override | ||
protected InternalAutoDateHistogram mutateInstance(InternalAutoDateHistogram instance) { | ||
String name = instance.getName(); | ||
|
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.
Another thing we could do here (to avoid having to create an instance of the builder in the
InternalAutoDateHistogramTests
) is to make the signature here:static RoundingInfo[] buildRoundings(DateTimeZone)
and then pass the time zone into it the method both ininnerBuild()
and inInternalAutoDateHistogramTests
. We will also need to makecreateRounding(DateTimeUnit, DateTimeZone)
static as well but thats fine I think.