Add feature flag for subobjects auto (#114616)

This commit is contained in:
Martijn van Groningen 2024-10-12 18:55:27 +02:00 committed by GitHub
parent edcabb80b7
commit e833e7b6c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48 additions and 22 deletions

View file

@ -89,7 +89,8 @@ public class CcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
.setting("xpack.security.enabled", "false")
// geohex_grid requires gold license
.setting("xpack.license.self_generated.type", "trial")
.feature(FeatureFlag.TIME_SERIES_MODE);
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED);
private static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local()
.name(REMOTE_CLUSTER_NAME)

View file

@ -91,6 +91,7 @@ public class RcsCcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
.setting("xpack.security.remote_cluster_server.ssl.enabled", "false")
.setting("xpack.security.remote_cluster_client.ssl.enabled", "false")
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.user("test_admin", "x-pack-test-password");
private static ElasticsearchCluster fulfillingCluster = ElasticsearchCluster.local()

View file

@ -35,6 +35,7 @@ public class SmokeTestMultiNodeClientYamlTestSuiteIT extends ESClientYamlSuiteTe
// The first node does not have the ingest role so we're sure ingest requests are forwarded:
.node(0, n -> n.setting("node.roles", "[master,data,ml,remote_cluster_client,transform]"))
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.build();
public SmokeTestMultiNodeClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

View file

@ -36,6 +36,7 @@ public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
.module("health-shards-availability")
.module("data-streams")
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.build();
public ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

View file

@ -15,6 +15,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.util.FeatureFlag;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.features.NodeFeature;
@ -41,6 +42,7 @@ import java.util.stream.Stream;
public class ObjectMapper extends Mapper {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ObjectMapper.class);
public static final FeatureFlag SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto");
public static final String CONTENT_TYPE = "object";
static final String STORE_ARRAY_SOURCE_PARAM = "store_array_source";
@ -74,7 +76,7 @@ public class ObjectMapper extends Mapper {
if (value.equalsIgnoreCase("false")) {
return DISABLED;
}
if (value.equalsIgnoreCase("auto")) {
if (SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled() && value.equalsIgnoreCase("auto")) {
return AUTO;
}
}

View file

@ -1377,6 +1377,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoFlatPaths() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.field("foo.metric.count", 10);
@ -1389,6 +1390,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoStructuredPaths() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.startObject("foo");
@ -1411,6 +1413,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoArrayOfObjects() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.startObject("foo");
@ -1444,6 +1447,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectAutoDynamicNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
@ -1482,6 +1486,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testRootSubobjectAutoDynamicNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
@ -1515,6 +1520,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
// verify that we read the dynamic value properly from the parent mapper. DocumentParser#dynamicOrDefault splits the field
// name where dots are found, but it does that only for the parent prefix e.g. metrics.service and not for the leaf suffix time.max
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
@ -1578,6 +1584,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoWithInnerNestedFromDynamicTemplate() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
@ -2045,6 +2052,7 @@ public class DynamicTemplatesTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoFlattened() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
String mapping = """
{
"_doc": {

View file

@ -169,27 +169,29 @@ public class ObjectMapperTests extends MapperServiceTestCase {
assertEquals(ObjectMapper.Subobjects.ENABLED, objectMapper.subobjects());
assertTrue(objectMapper.sourceKeepMode().isEmpty());
// Setting 'enabled' to true is allowed, and updates the mapping.
update = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("object")
.field("type", "object")
.field("enabled", true)
.field("subobjects", "auto")
.field(ObjectMapper.STORE_ARRAY_SOURCE_PARAM, true)
.endObject()
.endObject()
.endObject()
);
mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.INDEX_TEMPLATE);
if (ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled()) {
// Setting 'enabled' to true is allowed, and updates the mapping.
update = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject("object")
.field("type", "object")
.field("enabled", true)
.field("subobjects", "auto")
.field(ObjectMapper.STORE_ARRAY_SOURCE_PARAM, true)
.endObject()
.endObject()
.endObject()
);
mapper = mapperService.merge("type", new CompressedXContent(update), MergeReason.INDEX_TEMPLATE);
objectMapper = mapper.mappers().objectMappers().get("object");
assertNotNull(objectMapper);
assertTrue(objectMapper.isEnabled());
assertEquals(ObjectMapper.Subobjects.AUTO, objectMapper.subobjects());
assertEquals(Mapper.SourceKeepMode.ARRAYS, objectMapper.sourceKeepMode().orElse(Mapper.SourceKeepMode.NONE));
objectMapper = mapper.mappers().objectMappers().get("object");
assertNotNull(objectMapper);
assertTrue(objectMapper.isEnabled());
assertEquals(ObjectMapper.Subobjects.AUTO, objectMapper.subobjects());
assertEquals(Mapper.SourceKeepMode.ARRAYS, objectMapper.sourceKeepMode().orElse(Mapper.SourceKeepMode.NONE));
}
}
public void testFieldReplacementForIndexTemplates() throws IOException {
@ -503,6 +505,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAuto() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
@ -532,6 +535,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoWithInnerObject() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
@ -565,6 +569,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoWithInnerNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
@ -586,6 +591,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoRoot() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service.time");
b.field("type", "long");
@ -606,6 +612,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoRootWithInnerObject() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service.time");
{
@ -626,6 +633,7 @@ public class ObjectMapperTests extends MapperServiceTestCase {
}
public void testSubobjectsAutoRootWithInnerNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service");
b.field("type", "nested");

View file

@ -18,6 +18,7 @@ import org.elasticsearch.test.cluster.util.Version;
public enum FeatureFlag {
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
FAILURE_STORE_ENABLED("es.failure_store_feature_flag_enabled=true", Version.fromString("8.12.0"), null),
SUB_OBJECTS_AUTO_ENABLED("es.sub_objects_auto_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
CHUNKING_SETTINGS_ENABLED("es.inference_chunking_settings_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
INFERENCE_DEFAULT_ELSER("es.inference_default_elser_feature_flag_enabled=true", Version.fromString("8.16.0"), null);

View file

@ -43,6 +43,7 @@ public class XPackRestIT extends AbstractXPackRestTest {
.setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB")
.user("x_pack_rest_user", "x-pack-test-password")
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.configFile("testnode.pem", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem"))
.configFile("testnode.crt", Resource.fromClasspath("org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt"))
.configFile("service_tokens", Resource.fromClasspath("service_tokens"))

View file

@ -48,6 +48,7 @@ public class CoreWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTest
.setting("xpack.security.autoconfiguration.enabled", "false")
.user(USER, PASS)
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.build();
public CoreWithSecurityClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

View file

@ -44,6 +44,7 @@ subprojects {
setting 'xpack.security.enabled', 'false'
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
requiresFeature 'es.sub_objects_auto_feature_flag_enabled', Version.fromString("8.16.0")
}
tasks.named("yamlRestTest").configure {