Skip to content

Commit 7943ccb

Browse files
authored
[ML] using new fixed interval in ml tests (#56021)
This commit removes deprecated references to DateHistogram.interval from ml tests
1 parent 475790c commit 7943ccb

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/datafeed/extractor/ExtractorUtilsTests.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,19 @@ public void testGetHistogramAggregation_MissingHistogramAgg() {
7575
public void testGetHistogramIntervalMillis_GivenDateHistogramWithInvalidTimeZone() {
7676
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
7777
DateHistogramAggregationBuilder dateHistogram = AggregationBuilders.dateHistogram("bucket").field("time")
78-
.interval(300000L).timeZone(ZoneId.of("CET")).subAggregation(maxTime);
78+
.fixedInterval(new DateHistogramInterval(300000 + "ms")).timeZone(ZoneId.of("CET")).subAggregation(maxTime);
7979
ElasticsearchException e = expectThrows(ElasticsearchException.class,
8080
() -> ExtractorUtils.getHistogramIntervalMillis(dateHistogram));
8181

8282
assertThat(e.getMessage(), equalTo("ML requires date_histogram.time_zone to be UTC"));
83-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
84-
"or [calendar_interval] in the future.");
8583
}
8684

8785
public void testGetHistogramIntervalMillis_GivenUtcTimeZonesDeprecated() {
8886
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
8987
ZoneId zone = randomFrom(ZoneOffset.UTC, ZoneId.of("UTC"));
9088
DateHistogramAggregationBuilder dateHistogram = AggregationBuilders.dateHistogram("bucket").field("time")
91-
.interval(300000L).timeZone(zone).subAggregation(maxTime);
89+
.fixedInterval(new DateHistogramInterval(300000L + "ms")).timeZone(zone).subAggregation(maxTime);
9290
assertThat(ExtractorUtils.getHistogramIntervalMillis(dateHistogram), is(300_000L));
93-
94-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] " +
95-
"or [calendar_interval] in the future.");
9691
}
9792

9893
public void testGetHistogramIntervalMillis_GivenUtcTimeZones() {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/XContentObjectTransformerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.search.SearchModule;
2121
import org.elasticsearch.search.aggregations.AggregationBuilders;
2222
import org.elasticsearch.search.aggregations.AggregatorFactories;
23+
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
2324
import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
2425
import org.elasticsearch.test.ESTestCase;
2526

@@ -112,7 +113,7 @@ public void testToMap() throws IOException {
112113
long aggHistogramInterval = randomNonNegativeLong();
113114
MaxAggregationBuilder maxTime = AggregationBuilders.max("time").field("time");
114115
aggs.addAggregator(AggregationBuilders.dateHistogram("buckets")
115-
.interval(aggHistogramInterval).subAggregation(maxTime).field("time"));
116+
.fixedInterval(new DateHistogramInterval(aggHistogramInterval + "ms")).subAggregation(maxTime).field("time"));
116117

117118
assertXContentAreEqual(aggs, aggTransformer.toMap(aggs));
118119
assertXContentAreEqual(aggTransformer.fromMap(aggTransformer.toMap(aggs)), aggTransformer.toMap(aggs));

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/DataExtractorFactoryTests.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,14 @@ public void testCreateDataExtractorFactoryGivenRollupAndValidAggregation() {
220220
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
221221
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
222222
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
223-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
223+
AggregationBuilders.dateHistogram("time")
224+
.fixedInterval(new DateHistogramInterval("600000ms"))
225+
.subAggregation(maxTime)
226+
.subAggregation(myTerm)
227+
.field("time")));
224228
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
225229
dataExtractorFactory -> {
226230
assertThat(dataExtractorFactory, instanceOf(RollupDataExtractorFactory.class));
227-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
228231
},
229232
e -> fail()
230233
);
@@ -245,13 +248,16 @@ public void testCreateDataExtractorFactoryGivenRollupAndRemoteIndex() {
245248
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
246249
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
247250
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
248-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
251+
AggregationBuilders.dateHistogram("time")
252+
.fixedInterval(new DateHistogramInterval("600000ms"))
253+
.subAggregation(maxTime)
254+
.subAggregation(myTerm)
255+
.field("time")));
249256

250257
// Test with remote index, aggregation, and no chunking
251258
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
252259
dataExtractorFactory -> {
253260
assertThat(dataExtractorFactory, instanceOf(AggregationDataExtractorFactory.class));
254-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
255261
},
256262
e -> fail()
257263
);
@@ -302,11 +308,14 @@ public void testCreateDataExtractorFactoryGivenRollupAndValidAggregationAndAutoC
302308
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
303309
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
304310
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
305-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
311+
AggregationBuilders.dateHistogram("time")
312+
.fixedInterval(new DateHistogramInterval("600000ms"))
313+
.subAggregation(maxTime)
314+
.subAggregation(myTerm)
315+
.field("time")));
306316
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
307317
dataExtractorFactory -> {
308318
assertThat(dataExtractorFactory, instanceOf(ChunkedDataExtractorFactory.class));
309-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
310319
},
311320
e -> fail()
312321
);
@@ -347,15 +356,18 @@ public void testCreateDataExtractorFactoryGivenRollupWithBadInterval() {
347356
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
348357
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
349358
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
350-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
359+
AggregationBuilders.dateHistogram("time")
360+
.fixedInterval(new DateHistogramInterval("600000ms"))
361+
.subAggregation(maxTime)
362+
.subAggregation(myTerm)
363+
.field("time")));
351364
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
352365
dataExtractorFactory -> fail(),
353366
e -> {
354367
assertThat(e.getMessage(),
355368
containsString("Rollup capabilities do not have a [date_histogram] aggregation with an interval " +
356369
"that is a multiple of the datafeed's interval."));
357370
assertThat(e, instanceOf(IllegalArgumentException.class));
358-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
359371
}
360372
);
361373
DataExtractorFactory.create(
@@ -374,14 +386,17 @@ public void testCreateDataExtractorFactoryGivenRollupMissingTerms() {
374386
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("myField");
375387
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
376388
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
377-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
389+
AggregationBuilders.dateHistogram("time")
390+
.fixedInterval(new DateHistogramInterval("600000ms"))
391+
.subAggregation(maxTime)
392+
.subAggregation(myTerm)
393+
.field("time")));
378394
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
379395
dataExtractorFactory -> fail(),
380396
e -> {
381397
assertThat(e.getMessage(),
382398
containsString("Rollup capabilities do not support all the datafeed aggregations at the desired interval."));
383399
assertThat(e, instanceOf(IllegalArgumentException.class));
384-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
385400
}
386401
);
387402
DataExtractorFactory.create(
@@ -400,14 +415,17 @@ public void testCreateDataExtractorFactoryGivenRollupMissingMetric() {
400415
MaxAggregationBuilder myField = AggregationBuilders.max("myField").field("otherField");
401416
TermsAggregationBuilder myTerm = AggregationBuilders.terms("termAgg").field("termField").subAggregation(myField);
402417
datafeedConfig.setParsedAggregations(AggregatorFactories.builder().addAggregator(
403-
AggregationBuilders.dateHistogram("time").interval(600_000).subAggregation(maxTime).subAggregation(myTerm).field("time")));
418+
AggregationBuilders.dateHistogram("time")
419+
.fixedInterval(new DateHistogramInterval("600000ms"))
420+
.subAggregation(maxTime)
421+
.subAggregation(myTerm)
422+
.field("time")));
404423
ActionListener<DataExtractorFactory> listener = ActionListener.wrap(
405424
dataExtractorFactory -> fail(),
406425
e -> {
407426
assertThat(e.getMessage(),
408427
containsString("Rollup capabilities do not support all the datafeed aggregations at the desired interval."));
409428
assertThat(e, instanceOf(IllegalArgumentException.class));
410-
assertWarnings("[interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval] in the future.");
411429
}
412430
);
413431
DataExtractorFactory.create(
@@ -427,7 +445,9 @@ private void givenAggregatableRollup(String field, String type, int minuteInterv
427445
"*/30 * * * * ?",
428446
300,
429447
new GroupConfig(
430-
new DateHistogramGroupConfig("time", DateHistogramInterval.minutes(minuteInterval)), null, termsGroupConfig),
448+
new DateHistogramGroupConfig.FixedInterval("time", DateHistogramInterval.minutes(minuteInterval)),
449+
null,
450+
termsGroupConfig),
431451
metricConfigs,
432452
null);
433453
RollupJobCaps rollupJobCaps = new RollupJobCaps(rollupJobConfig);

0 commit comments

Comments
 (0)