diff --git a/muted-tests.yml b/muted-tests.yml index a2b013eec364d..f1fc07963f8fd 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -546,12 +546,6 @@ tests: - class: org.elasticsearch.gradle.internal.transport.TransportVersionValidationFuncTest method: definitions have primary ids which cannot change issue: https://github.com/elastic/elasticsearch/issues/133131 -- class: org.elasticsearch.xpack.esql.action.RandomizedTimeSeriesIT - method: testGroupBySubset - issue: https://github.com/elastic/elasticsearch/issues/133220 -- class: org.elasticsearch.xpack.esql.action.RandomizedTimeSeriesIT - method: testGroupByNothing - issue: https://github.com/elastic/elasticsearch/issues/133225 - class: org.elasticsearch.gradle.internal.transport.TransportVersionValidationFuncTest method: named and unreferenced definitions cannot have the same name issue: https://github.com/elastic/elasticsearch/issues/133255 diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/RandomizedTimeSeriesIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/RandomizedTimeSeriesIT.java index fb2691b6fe09d..d9881f0c2f172 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/RandomizedTimeSeriesIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/RandomizedTimeSeriesIT.java @@ -183,10 +183,10 @@ public void populateIndex() throws IOException { if (documents == null) { documents = new ArrayList<>(); } - documents.add(document); var indexRequest = client().prepareIndex(DATASTREAM_NAME).setOpType(DocWriteRequest.OpType.CREATE).setSource(document); indexRequest.setRefreshPolicy(org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE); indexRequest.get(); + documents.add(document); } } diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TSDataGenerationHelper.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TSDataGenerationHelper.java index c0d25ae7d36ef..17904e5e28836 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TSDataGenerationHelper.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/TSDataGenerationHelper.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.time.Instant; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -65,6 +66,29 @@ private static Object randomDimensionValue(String dimensionName) { return dimensionsInMetric.stream().map(attr -> new Tuple<>(attr, randomDimensionValue(attr))).collect(Collectors.toList()); }).toList(); + // We want to ensure that all documents have different timestamps. + var now = Instant.now(); + var timestampSet = new HashSet(); + var regens = 0; + for (int i = 0; i < numDocs; i++) { + // Random timestamps within the last 90 days. + while (true) { + var randomIns = Instant.ofEpochMilli( + ESTestCase.randomLongBetween(now.minusSeconds(60 * 60 * 2).toEpochMilli(), now.toEpochMilli()) + ); + if (timestampSet.add(randomIns)) { + break; + } + regens++; + if (regens > numDocs) { + throw new IllegalStateException("Too many collisions when generating timestamps"); + } + } + } + // Timestampset should have exactly numDocs entries - this works as long as the random number generator + // does not cycle early. + assert timestampSet.size() == numDocs : "Expected [" + numDocs + "] timestamps but got [" + timestampSet.size() + "]"; + var timestampsIter = timestampSet.iterator(); spec = DataGeneratorSpecification.builder() .withMaxFieldCountPerLevel(0) .withPredefinedFields( @@ -73,7 +97,7 @@ private static Object randomDimensionValue(String dimensionName) { "@timestamp", FieldType.DATE, Map.of("type", "date"), - fieldMapping -> ESTestCase.randomInstantBetween(Instant.now().minusSeconds(2 * 60 * 60), Instant.now()) + fieldMapping -> timestampsIter.next() ), new PredefinedField.WithGenerator( "attributes",