Skip to content

Commit

Permalink
Deprecate source mode in mappings (elastic#117177)
Browse files Browse the repository at this point in the history
Backport of elastic#116689 to 8.18
  • Loading branch information
dnhatn committed Nov 25, 2024
1 parent 0bc9af1 commit ee09bc2
Show file tree
Hide file tree
Showing 32 changed files with 290 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public void skipTest(String fullTestName, String reason) {
// For example: indices.get_mapping/20_missing_type/Non-existent type returns 404
// However, the folder can be arbitrarily nest so, a == a1/a2/a3, and the test name can include forward slashes, so c == c1/c2/c3
// So we also need to support a1/a2/a3/b/c1/c2/c3

String[] testParts = fullTestName.split("/");
boolean limitTo3Separators = fullTestName.equals("logsdb/20_source_mapping/include/exclude is supported with stored _source");
String[] testParts = limitTo3Separators ? fullTestName.split("/", 3) : fullTestName.split("/");
if (testParts.length < 3) {
throw new IllegalArgumentException(
"To skip tests, all 3 parts [folder/file/test name] must be defined. found [" + fullTestName + "]"
Expand Down
10 changes: 10 additions & 0 deletions docs/changelog/116689.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pr: 116689
summary: Deprecate `_source.mode` in mappings
area: Mapping
type: deprecation
issues: []
deprecation:
title: Deprecate `_source.mode` in mappings
area: Mapping
details: Configuring `_source.mode` in mappings is deprecated and will be removed in future versions. Use `index.mapping.source.mode` index setting instead.
impact: Use `index.mapping.source.mode` index setting instead
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ protected void registerParameters(ParameterChecker checker) throws IOException {
checker.registerConflictCheck(
"enabled",
timestampMapping(true, b -> b.startObject("@timestamp").field("type", "date").endObject()),
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject())
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject()),
dm -> {}
);
checker.registerUpdateCheck(
timestampMapping(false, b -> b.startObject("@timestamp").field("type", "date").endObject()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.FormatNames;
import org.elasticsearch.test.MapMatcher;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.RestTestLegacyFeatures;
Expand All @@ -31,9 +30,6 @@
import java.util.Map;
import java.util.function.Supplier;

import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;

public class LogsIndexModeFullClusterRestartIT extends ParameterizedFullClusterRestartTestCase {

@ClassRule
Expand Down Expand Up @@ -172,22 +168,16 @@ public void testLogsIndexing() throws IOException {
assertOK(bulkIndexResponse);
assertThat(entityAsMap(bulkIndexResponse).get("errors"), Matchers.is(false));

assertIndexMappingsAndSettings(0, Matchers.nullValue(), matchesMap().extraOk());
assertIndexMappingsAndSettings(
1,
Matchers.equalTo("logsdb"),
matchesMap().extraOk().entry("_source", Map.of("mode", "synthetic"))
);
assertIndexSettings(0, Matchers.nullValue());
assertIndexSettings(1, Matchers.equalTo("logsdb"));
}
}

private void assertIndexMappingsAndSettings(int backingIndex, final Matcher<Object> indexModeMatcher, final MapMatcher mappingsMatcher)
throws IOException {
private void assertIndexSettings(int backingIndex, final Matcher<Object> indexModeMatcher) throws IOException {
assertThat(
getSettings(client(), getWriteBackingIndex(client(), "logs-apache-production", backingIndex)).get("index.mode"),
indexModeMatcher
);
assertMap(getIndexMappingAsMap(getWriteBackingIndex(client(), "logs-apache-production", backingIndex)), mappingsMatcher);
}

private static Request createDataStream(final String dataStreamName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.TimeSeriesIdFieldMapper;
import org.elasticsearch.test.ListMatcher;
Expand Down Expand Up @@ -419,9 +420,15 @@ public void testSyntheticSource() throws IOException {
if (isOldCluster()) {
Request createIndex = new Request("PUT", "/synthetic");
XContentBuilder indexSpec = XContentBuilder.builder(XContentType.JSON.xContent()).startObject();
boolean useIndexSetting = getOldClusterIndexVersion().onOrAfter(IndexVersions.DEPRECATE_SOURCE_MODE_MAPPER);
if (useIndexSetting) {
indexSpec.startObject("settings").field("index.mapping.source.mode", "synthetic").endObject();
}
indexSpec.startObject("mappings");
{
indexSpec.startObject("_source").field("mode", "synthetic").endObject();
if (useIndexSetting == false) {
indexSpec.startObject("_source").field("mode", "synthetic").endObject();
}
indexSpec.startObject("properties").startObject("kwd").field("type", "keyword").endObject().endObject();
}
indexSpec.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.FormatNames;
import org.elasticsearch.test.MapMatcher;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.hamcrest.Matcher;
Expand All @@ -30,9 +29,6 @@
import java.util.Map;
import java.util.function.Supplier;

import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;

public class LogsIndexModeRollingUpgradeIT extends AbstractRollingUpgradeTestCase {

@ClassRule()
Expand Down Expand Up @@ -160,14 +156,10 @@ public void testLogsIndexing() throws IOException {
assertOK(bulkIndexResponse);
assertThat(entityAsMap(bulkIndexResponse).get("errors"), Matchers.is(false));

assertIndexMappingsAndSettings(0, Matchers.nullValue(), matchesMap().extraOk());
assertIndexMappingsAndSettings(1, Matchers.nullValue(), matchesMap().extraOk());
assertIndexMappingsAndSettings(2, Matchers.nullValue(), matchesMap().extraOk());
assertIndexMappingsAndSettings(
3,
Matchers.equalTo("logsdb"),
matchesMap().extraOk().entry("_source", Map.of("mode", "synthetic"))
);
assertIndexSettings(0, Matchers.nullValue());
assertIndexSettings(1, Matchers.nullValue());
assertIndexSettings(2, Matchers.nullValue());
assertIndexSettings(3, Matchers.equalTo("logsdb"));
}
}

Expand All @@ -183,13 +175,11 @@ static void enableLogsdbByDefault() throws IOException {
assertOK(client().performRequest(request));
}

private void assertIndexMappingsAndSettings(int backingIndex, final Matcher<Object> indexModeMatcher, final MapMatcher mappingsMatcher)
throws IOException {
private void assertIndexSettings(int backingIndex, final Matcher<Object> indexModeMatcher) throws IOException {
assertThat(
getSettings(client(), getWriteBackingIndex(client(), "logs-apache-production", backingIndex)).get("index.mode"),
indexModeMatcher
);
assertMap(getIndexMappingAsMap(getWriteBackingIndex(client(), "logs-apache-production", backingIndex)), mappingsMatcher);
}

private static Request createDataStream(final String dataStreamName) {
Expand Down
6 changes: 6 additions & 0 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,10 @@ tasks.named("precommit").configure {
tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
task.skipTest("indices.sort/10_basic/Index Sort", "warning does not exist for compatibility")
task.skipTest("search/330_fetch_fields/Test search rewrite", "warning does not exist for compatibility")
task.skipTest("tsdb/20_mapping/stored source is supported", "no longer serialize source_mode")
task.skipTest("tsdb/20_mapping/Synthetic source", "no longer serialize source_mode")
task.skipTest("logsdb/10_settings/create logs index", "no longer serialize source_mode")
task.skipTest("logsdb/20_source_mapping/stored _source mode is supported", "no longer serialize source_mode")
task.skipTest("logsdb/20_source_mapping/include/exclude is supported with stored _source", "no longer serialize source_mode")
task.skipTest("logsdb/20_source_mapping/synthetic _source is default", "no longer serialize source_mode")
})
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ create logs index:
- is_true: test
- match: { test.settings.index.mode: "logsdb" }

- do:
indices.get_mapping:
index: test
- match: { test.mappings._source.mode: synthetic }

---
using default timestamp field mapping:
- requires:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ synthetic _source is default:
index:
mode: logsdb
- do:
indices.get:
indices.get_settings:
index: test-default-source

- match: { test-default-source.mappings._source.mode: "synthetic" }
- match: { test-default-source.settings.index.mode: logsdb }
- match: { test-default-source.settings.index.mapping.source.mode: null }

---
stored _source mode is supported:
Expand All @@ -28,11 +28,12 @@ stored _source mode is supported:
index:
mode: logsdb
mapping.source.mode: stored

- do:
indices.get:
indices.get_settings:
index: test-stored-source

- match: { test-stored-source.mappings._source.mode: "stored" }
- match: { test-stored-source.settings.index.mode: logsdb }
- match: { test-stored-source.settings.index.mapping.source.mode: stored }

---
disabled _source is not supported:
Expand Down Expand Up @@ -110,7 +111,6 @@ include/exclude is supported with stored _source:
indices.get:
index: test-includes

- match: { test-includes.mappings._source.mode: "stored" }
- match: { test-includes.mappings._source.includes: ["a"] }

- do:
Expand All @@ -129,5 +129,4 @@ include/exclude is supported with stored _source:
indices.get:
index: test-excludes

- match: { test-excludes.mappings._source.mode: "stored" }
- match: { test-excludes.mappings._source.excludes: ["b"] }
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,6 @@ nested fields:
type: long
time_series_metric: gauge

- do:
indices.get_mapping: {}

- match: {tsdb-synthetic.mappings._source.mode: synthetic}

---
stored source is supported:
- requires:
Expand Down Expand Up @@ -486,12 +481,6 @@ stored source is supported:
type: keyword
time_series_dimension: true

- do:
indices.get:
index: tsdb_index

- match: { tsdb_index.mappings._source.mode: "stored" }

---
disabled source is not supported:
- requires:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.CheckedFunction;
Expand Down Expand Up @@ -54,7 +55,7 @@ Settings getAdditionalIndexSettings(
/**
* Infrastructure class that holds services that can be used by {@link IndexSettingProvider} instances.
*/
record Parameters(CheckedFunction<IndexMetadata, MapperService, IOException> mapperServiceFactory) {
record Parameters(ClusterService clusterService, CheckedFunction<IndexMetadata, MapperService, IOException> mapperServiceFactory) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private static IndexVersion def(int id, Version luceneVersion) {
public static final IndexVersion ADD_ROLE_MAPPING_CLEANUP_MIGRATION = def(8_518_00_0, Version.LUCENE_9_12_0);
public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT_BACKPORT = def(8_519_00_0, Version.LUCENE_9_12_0);
public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID_BACKPORT = def(8_520_00_0, Version.LUCENE_9_12_0);
public static final IndexVersion DEPRECATE_SOURCE_MODE_MAPPER = def(8_521_00_0, Version.LUCENE_9_12_0);
/*
* STOP! READ THIS FIRST! No, really,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Loading

0 comments on commit ee09bc2

Please sign in to comment.