Skip to content

Commit

Permalink
[ML] fixing ML composite agg restart test (#78329) (#78403)
Browse files Browse the repository at this point in the history
The test failure is due to data generation. This isn't caused by a bug, but is instead a test set up failure.

The issue is that scroll is seeing the data as a partial result, and aggs is not. Consequently, the first bucket is sometimes only present in scroll, but missing in aggs.

This is acceptable.

This commit fixes the test to make it more deterministic.

closes #76075
  • Loading branch information
benwtrent committed Sep 28, 2021
1 parent e31551e commit 8f8afd4
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.elasticsearch.xpack.core.ml.job.config.JobState;
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts;
import org.elasticsearch.xpack.core.ml.job.results.Bucket;
import org.elasticsearch.xpack.core.ml.utils.Intervals;
import org.hamcrest.Matcher;
import org.junit.After;

Expand Down Expand Up @@ -350,12 +351,32 @@ public void testStopAndRestartCompositeDatafeed() throws Exception {
.addMapping("type", "time", "type=date")
.get();
long numDocs = randomIntBetween(32, 2048);
final long intervalMillis = TimeValue.timeValueHours(1).millis();
long now = System.currentTimeMillis();
long oneWeekAgo = now - 604800000;
long twoWeeksAgo = oneWeekAgo - 604800000;
indexDocs(logger, indexName, numDocs, twoWeeksAgo, oneWeekAgo);
indexDocs(
logger,
indexName,
1,
Intervals.alignToCeil(twoWeeksAgo, intervalMillis),
Intervals.alignToCeil(twoWeeksAgo, intervalMillis) + 1
);
indexDocs(
logger,
indexName,
numDocs - 1,
Intervals.alignToCeil(twoWeeksAgo, intervalMillis) + intervalMillis,
Intervals.alignToFloor(oneWeekAgo, intervalMillis)
);
long numDocs2 = randomIntBetween(32, 2048);
indexDocs(logger, indexName, numDocs2, oneWeekAgo, now);
indexDocs(
logger,
indexName,
numDocs2,
Intervals.alignToCeil(oneWeekAgo, intervalMillis),
Intervals.alignToFloor(now, intervalMillis)
);
client().admin().cluster().prepareHealth(indexName).setWaitForYellowStatus().get();

String scrollJobId = "stop-restart-scroll";
Expand Down Expand Up @@ -464,7 +485,10 @@ public void testStopAndRestartCompositeDatafeed() throws Exception {
Bucket scrollBucket = scrollBuckets.get(i);
Bucket compositeBucket = compositeBuckets.get(i);
try {
assertThat(compositeBucket.getTimestamp(), equalTo(scrollBucket.getTimestamp()));
assertThat("scroll buckets " + scrollBuckets + " composite buckets " + compositeBuckets,
compositeBucket.getTimestamp(),
equalTo(scrollBucket.getTimestamp())
);
assertThat(
"composite bucket [" + compositeBucket.getTimestamp() + "] [" + compositeBucket.getEventCount() + "] does not equal"
+ " scroll bucket [" + scrollBucket.getTimestamp() + "] [" + scrollBucket.getEventCount() + "]",
Expand Down

0 comments on commit 8f8afd4

Please sign in to comment.