Skip to content

Commit 132feff

Browse files
authored
Enable synthetic _id randomly in TsdbDataStreamRestIT (#138751)
Relates ES-13605
1 parent 3f2ea0d commit 132feff

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/DisabledSecurityDataStreamTestCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1616
import org.elasticsearch.test.cluster.FeatureFlag;
17+
import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider;
1718
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1819
import org.elasticsearch.test.rest.ESRestTestCase;
1920
import org.junit.ClassRule;
@@ -24,12 +25,15 @@
2425
*/
2526
public abstract class DisabledSecurityDataStreamTestCase extends ESRestTestCase {
2627

28+
protected static LocalClusterConfigProvider clusterConfig = c -> {};
29+
2730
@ClassRule
2831
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
2932
.distribution(DistributionType.DEFAULT)
3033
.setting("xpack.security.enabled", "false")
3134
.setting("xpack.watcher.enabled", "false")
3235
.feature(FeatureFlag.INDEX_DIMENSIONS_TSID_OPTIMIZATION_FEATURE_FLAG)
36+
.apply(() -> clusterConfig) // allows sub-classes to apply a custom cluster configuration
3337
.build();
3438

3539
@Override

modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/TsdbDataStreamRestIT.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
*/
99
package org.elasticsearch.datastreams;
1010

11+
import org.elasticsearch.Build;
1112
import org.elasticsearch.client.Request;
1213
import org.elasticsearch.client.ResponseException;
14+
import org.elasticsearch.common.settings.Settings;
1315
import org.elasticsearch.common.time.DateFormatter;
1416
import org.elasticsearch.common.time.DateFormatters;
1517
import org.elasticsearch.common.time.FormatNames;
1618
import org.elasticsearch.index.mapper.DateFieldMapper;
19+
import org.elasticsearch.test.cluster.FeatureFlag;
1720
import org.elasticsearch.test.rest.ObjectPath;
1821
import org.junit.Before;
1922

@@ -25,6 +28,7 @@
2528
import java.util.Set;
2629

2730
import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.backingIndexEqualTo;
31+
import static org.elasticsearch.index.IndexSettings.USE_SYNTHETIC_ID;
2832
import static org.hamcrest.Matchers.containsInAnyOrder;
2933
import static org.hamcrest.Matchers.containsString;
3034
import static org.hamcrest.Matchers.empty;
@@ -36,6 +40,10 @@
3640

3741
public class TsdbDataStreamRestIT extends DisabledSecurityDataStreamTestCase {
3842

43+
static {
44+
clusterConfig = config -> config.feature(FeatureFlag.TSDB_SYNTHETIC_ID_FEATURE_FLAG);
45+
}
46+
3947
private static final String COMPONENT_TEMPLATE = """
4048
{
4149
"template": {
@@ -53,7 +61,7 @@ public class TsdbDataStreamRestIT extends DisabledSecurityDataStreamTestCase {
5361
"number_of_replicas": 1,
5462
"number_of_shards": 2,
5563
"mode": "time_series"
56-
SOURCEMODE
64+
RANDOM_INDEX_SETTINGS
5765
}
5866
},
5967
"mappings":{
@@ -202,9 +210,51 @@ public class TsdbDataStreamRestIT extends DisabledSecurityDataStreamTestCase {
202210
""";
203211

204212
private static String getTemplate() {
205-
return TEMPLATE.replace("SOURCEMODE", randomFrom("", """
206-
, "mapping": { "source": { "mode": "stored" } }""", """
207-
, "mapping": { "source": { "mode": "synthetic" } }"""));
213+
String sourceMode = switch (randomInt(2)) {
214+
case 0 -> null;
215+
case 1 -> """
216+
"source": { "mode": "stored" }
217+
""";
218+
case 2 -> """
219+
"source": { "mode": "synthetic" }
220+
""";
221+
default -> throw new AssertionError("Unknown mode");
222+
};
223+
String idMode = null;
224+
if (Build.current().isSnapshot()) {
225+
idMode = switch (randomInt(2)) {
226+
case 0 -> null;
227+
case 1 -> """
228+
"use_synthetic_id": "false"
229+
""";
230+
case 2 -> """
231+
"use_synthetic_id": "true"
232+
""";
233+
default -> throw new AssertionError("Unknown mode");
234+
};
235+
} else {
236+
assertFalse(
237+
"Setting is enabled by default and must now be tested on non-snapshot build too ",
238+
USE_SYNTHETIC_ID.getDefault(Settings.EMPTY)
239+
);
240+
}
241+
if (sourceMode == null && idMode == null) {
242+
return TEMPLATE.replace("RANDOM_INDEX_SETTINGS", "");
243+
}
244+
var mapping = new StringBuilder("""
245+
, "mapping": {
246+
""");
247+
if (sourceMode != null) {
248+
mapping.append(sourceMode);
249+
}
250+
if (idMode != null) {
251+
if (sourceMode != null) {
252+
mapping.append(',');
253+
}
254+
mapping.append(idMode);
255+
}
256+
mapping.append('}');
257+
return TEMPLATE.replace("RANDOM_INDEX_SETTINGS", mapping.toString());
208258
}
209259

210260
private static boolean trialStarted = false;

server/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445

446446
provides org.apache.lucene.codecs.PostingsFormat
447447
with
448+
org.elasticsearch.index.codec.tsdb.TSDBSyntheticIdPostingsFormat,
448449
org.elasticsearch.index.codec.bloomfilter.ES85BloomFilterPostingsFormat,
449450
org.elasticsearch.index.codec.bloomfilter.ES87BloomFilterPostingsFormat,
450451
org.elasticsearch.index.codec.postings.ES812PostingsFormat;

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public enum FeatureFlag {
2727
),
2828
RANDOM_SAMPLING("es.random_sampling_feature_flag_enabled=true", Version.fromString("9.2.0"), null),
2929
INFERENCE_API_CCM("es.inference_api_ccm_feature_flag_enabled=true", Version.fromString("9.3.0"), null),
30-
GENERIC_VECTOR_FORMAT("es.generic_vector_format_feature_flag_enabled=true", Version.fromString("9.3.0"), null);
30+
GENERIC_VECTOR_FORMAT("es.generic_vector_format_feature_flag_enabled=true", Version.fromString("9.3.0"), null),
31+
TSDB_SYNTHETIC_ID_FEATURE_FLAG("es.tsdb_synthetic_id_feature_flag_enabled=true", Version.fromString("9.3.0"), null);
3132

3233
public final String systemProperty;
3334
public final Version from;

0 commit comments

Comments
 (0)