[ML] using new fixed interval in ml tests (#56021) (#56031)

This commit removes deprecated references to DateHistogram.interval from ml tests
This commit is contained in:
Benjamin Trent 2020-04-30 10:26:39 -04:00 committed by GitHub
parent e4e02e133e
commit 04b1f6498b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 21 deletions

View File

@ -75,24 +75,19 @@ public class ExtractorUtilsTests extends ESTestCase {
public void testGetHistogramIntervalMillis_GivenDateHistogramWithInvalidTimeZone() {
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
DateHistogramAggregationBuilder dateHistogram = AggregationBuilders.dateHistogram("bucket").field("time")
.interval(300000L).timeZone(ZoneId.of("CET")).subAggregation(maxTime);
.fixedInterval(new DateHistogramInterval(300000 + "ms")).timeZone(ZoneId.of("CET")).subAggregation(maxTime);
ElasticsearchException e = expectThrows(ElasticsearchException.class,
() -> ExtractorUtils.getHistogramIntervalMillis(dateHistogram));
assertThat(e.getMessage(), equalTo("ML requires date_histogram.time_zone to be UTC"));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
"or [calendar_interval] in the future.");
}
public void testGetHistogramIntervalMillis_GivenUtcTimeZonesDeprecated() {
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
ZoneId zone = randomFrom(ZoneOffset.UTC, ZoneId.of("UTC"));
DateHistogramAggregationBuilder dateHistogram = AggregationBuilders.dateHistogram("bucket").field("time")
.interval(300000L).timeZone(zone).subAggregation(maxTime);
.fixedInterval(new DateHistogramInterval(300000L + "ms")).timeZone(zone).subAggregation(maxTime);
assertThat(ExtractorUtils.getHistogramIntervalMillis(dateHistogram), is(300_000L));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
"or [calendar_interval] in the future.");
}
public void testGetHistogramIntervalMillis_GivenUtcTimeZones() {

View File

@ -20,6 +20,7 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
import org.elasticsearch.test.ESTestCase;
@ -112,7 +113,7 @@ public class XContentObjectTransformerTests extends ESTestCase {
long aggHistogramInterval = randomNonNegativeLong();
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
aggs.addAggregator(AggregationBuilders.dateHistogram("buckets")
.interval(aggHistogramInterval).subAggregation(maxTime).field("time"));
.fixedInterval(new DateHistogramInterval(aggHistogramInterval + "ms")).subAggregation(maxTime).field("time"));
assertXContentAreEqual(aggs, aggTransformer.toMap(aggs));
assertXContentAreEqual(aggTransformer.fromMap(aggTransformer.toMap(aggs)), aggTransformer.toMap(aggs));

View File

@ -220,11 +220,14 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> {
assertThat(dataExtractorFactory, instanceOf(RollupDataExtractorFactory.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
},
e -> fail()
);
@ -245,13 +248,16 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
// Test with remote index, aggregation, and no chunking
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> {
assertThat(dataExtractorFactory, instanceOf(AggregationDataExtractorFactory.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
},
e -> fail()
);
@ -302,11 +308,14 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> {
assertThat(dataExtractorFactory, instanceOf(ChunkedDataExtractorFactory.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
},
e -> fail()
);
@ -347,7 +356,11 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> fail(),
e -> {
@ -355,7 +368,6 @@ public class DataExtractorFactoryTests extends ESTestCase {
containsString("Rollup capabilities do not have a [date_histogram] aggregation with an interval " +
"that is a multiple of the datafeed's interval."));
assertThat(e, instanceOf(IllegalArgumentException.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
}
);
DataExtractorFactory.create(
@ -374,14 +386,17 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> fail(),
e -> {
assertThat(e.getMessage(),
containsString("Rollup capabilities do not support all the datafeed aggregations at the desired interval."));
assertThat(e, instanceOf(IllegalArgumentException.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
}
);
DataExtractorFactory.create(
@ -400,14 +415,17 @@ public class DataExtractorFactoryTests extends ESTestCase {
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("otherField");
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
AggregationBuilders.dateHistogram("time")
.fixedInterval(new DateHistogramInterval("600000ms"))
.subAggregation(maxTime)
.subAggregation(myTerm)
.field("time")));
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
dataExtractorFactory -> fail(),
e -> {
assertThat(e.getMessage(),
containsString("Rollup capabilities do not support all the datafeed aggregations at the desired interval."));
assertThat(e, instanceOf(IllegalArgumentException.class));
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
}
);
DataExtractorFactory.create(
@ -427,7 +445,9 @@ public class DataExtractorFactoryTests extends ESTestCase {
"*/30 * * * * ?",
300,
new GroupConfig(
new DateHistogramGroupConfig("time", DateHistogramInterval.minutes(minuteInterval)), null, termsGroupConfig),
new DateHistogramGroupConfig.FixedInterval("time", DateHistogramInterval.minutes(minuteInterval)),
null,
termsGroupConfig),
metricConfigs,
null);
RollupJobCaps rollupJobCaps = new RollupJobCaps(rollupJobConfig);