Skip to content

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

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,19 @@ public void testGetHistogramAggregation_MissingHistogramAgg() {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;

Expand Down Expand Up @@ -112,7 +113,7 @@ public void testToMap() throws IOException {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,14 @@ public void testCreateDataExtractorFactoryGivenRollupAndValidAggregation() {
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()
);
Expand All @@ -245,13 +248,16 @@ public void testCreateDataExtractorFactoryGivenRollupAndRemoteIndex() {
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()
);
Expand Down Expand Up @@ -302,11 +308,14 @@ public void testCreateDataExtractorFactoryGivenRollupAndValidAggregationAndAutoC
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()
);
Expand Down Expand Up @@ -347,15 +356,18 @@ public void testCreateDataExtractorFactoryGivenRollupWithBadInterval() {
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 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(
Expand All @@ -374,14 +386,17 @@ public void testCreateDataExtractorFactoryGivenRollupMissingTerms() {
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(
Expand All @@ -400,14 +415,17 @@ public void testCreateDataExtractorFactoryGivenRollupMissingMetric() {
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(
Expand All @@ -427,7 +445,9 @@ private void givenAggregatableRollup(String field, String type, int minuteInterv
"*/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);
Expand Down