Skip to content

Commit 17022fd

Browse files
lktselasticmachine
andauthored
[8.x] Allow stored source in logsdb and tsdb (#114454) (#114648)
* Allow stored source in logsdb and tsdb (#114454) (cherry picked from commit a62228a) # Conflicts: # modules/aggregations/build.gradle # modules/data-streams/src/javaRestTest/java/org/elasticsearch/datastreams/logsdb/LogsIndexModeCustomSettingsIT.java # rest-api-spec/build.gradle * Fix tests * Fix tests --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 8c475a2 commit 17022fd

File tree

9 files changed

+161
-111
lines changed

9 files changed

+161
-111
lines changed

modules/aggregations/src/yamlRestTest/resources/rest-api-spec/test/aggregations/time_series.yml

-17
Original file line numberDiff line numberDiff line change
@@ -291,23 +291,6 @@ setup:
291291
sum:
292292
sum:
293293
field: val
294-
---
295-
"Configure with no synthetic source":
296-
- requires:
297-
cluster_features: ["gte_v8.15.0"]
298-
reason: "Error message changed in 8.15.0"
299-
300-
- do:
301-
catch: '/Indices with with index mode \[time_series\] only support synthetic source/'
302-
indices.create:
303-
index: tsdb_error
304-
body:
305-
settings:
306-
mode: time_series
307-
routing_path: [key]
308-
mappings:
309-
_source:
310-
enabled: false
311294

312295
---
313296
"Number for keyword routing field":

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

+87-6
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,62 @@ public void testConfigureStoredSourceBeforeIndexCreation() throws IOException {
114114
}
115115
}""";
116116

117+
assertOK(putComponentTemplate(client, "logs@custom", storedSourceMapping));
118+
assertOK(createDataStream(client, "logs-custom-dev"));
119+
120+
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
121+
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
122+
assertThat(sourceMode, equalTo("stored"));
123+
}
124+
125+
public void testConfigureDisabledSourceBeforeIndexCreation() {
126+
var storedSourceMapping = """
127+
{
128+
"template": {
129+
"settings": {
130+
"index": {
131+
"mode": "logsdb"
132+
}
133+
},
134+
"mappings": {
135+
"_source": {
136+
"enabled": false
137+
}
138+
}
139+
}
140+
}""";
141+
117142
Exception e = assertThrows(ResponseException.class, () -> putComponentTemplate(client, "logs@custom", storedSourceMapping));
118143
assertThat(
119144
e.getMessage(),
120-
containsString("Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source")
145+
containsString("Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode")
121146
);
122147
assertThat(e.getMessage(), containsString("mapper_parsing_exception"));
148+
}
123149

124-
assertOK(createDataStream(client, "logs-custom-dev"));
150+
public void testConfigureDisabledSourceModeBeforeIndexCreation() {
151+
var storedSourceMapping = """
152+
{
153+
"template": {
154+
"settings": {
155+
"index": {
156+
"mode": "logsdb"
157+
}
158+
},
159+
"mappings": {
160+
"_source": {
161+
"mode": "disabled"
162+
}
163+
}
164+
}
165+
}""";
125166

126-
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
127-
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
128-
assertThat(sourceMode, equalTo("synthetic"));
167+
Exception e = assertThrows(ResponseException.class, () -> putComponentTemplate(client, "logs@custom", storedSourceMapping));
168+
assertThat(
169+
e.getMessage(),
170+
containsString("Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode")
171+
);
172+
assertThat(e.getMessage(), containsString("mapper_parsing_exception"));
129173
}
130174

131175
public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException {
@@ -141,8 +185,45 @@ public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException {
141185
}""";
142186

143187
assertOK(putComponentTemplate(client, "logs@custom", storedSourceMapping));
188+
assertOK(createDataStream(client, "logs-custom-dev"));
189+
190+
var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0));
191+
String sourceMode = (String) subObject("_source").apply(mapping).get("mode");
192+
assertThat(sourceMode, equalTo("stored"));
193+
}
194+
195+
public void testConfigureDisabledSourceWhenIndexIsCreated() throws IOException {
196+
var disabledModeMapping = """
197+
{
198+
"template": {
199+
"mappings": {
200+
"_source": {
201+
"enabled": false
202+
}
203+
}
204+
}
205+
}""";
206+
207+
assertOK(putComponentTemplate(client, "logs@custom", disabledModeMapping));
208+
ResponseException e = expectThrows(ResponseException.class, () -> createDataStream(client, "logs-custom-dev"));
209+
assertThat(e.getMessage(), containsString("_source can not be disabled in index using [logsdb] index mode"));
210+
}
211+
212+
public void testConfigureDisabledSourceModeWhenIndexIsCreated() throws IOException {
213+
var disabledModeMapping = """
214+
{
215+
"template": {
216+
"mappings": {
217+
"_source": {
218+
"mode": "disabled"
219+
}
220+
}
221+
}
222+
}""";
223+
224+
assertOK(putComponentTemplate(client, "logs@custom", disabledModeMapping));
144225
ResponseException e = expectThrows(ResponseException.class, () -> createDataStream(client, "logs-custom-dev"));
145-
assertThat(e.getMessage(), containsString("Indices with with index mode [logsdb] only support synthetic source"));
226+
assertThat(e.getMessage(), containsString("_source can not be disabled in index using [logsdb] index mode"));
146227
}
147228

148229
public void testOverrideIndexCodec() throws IOException {
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
---
2-
stored _source mode is not supported:
2+
stored _source mode is supported:
33
- requires:
4-
test_runner_features: [capabilities]
5-
capabilities:
6-
- method: PUT
7-
path: /{index}
8-
capabilities: [logsdb_index_mode]
9-
reason: "Support for 'logsdb' index mode capability required"
10-
11-
- skip:
12-
known_issues:
13-
- cluster_feature: "gte_v8.15.0"
14-
fixed_by: "gte_v8.16.0"
15-
reason: "Development of logs index mode spans 8.15 and 8.16"
4+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
5+
reason: requires new validation logic
166

177
- do:
18-
catch: bad_request
198
indices.create:
209
index: test-stored-source
2110
body:
@@ -25,31 +14,17 @@ stored _source mode is not supported:
2514
mappings:
2615
_source:
2716
mode: stored
28-
properties:
29-
"@timestamp":
30-
type: date
31-
host.name:
32-
type: keyword
17+
- do:
18+
indices.get:
19+
index: test-stored-source
3320

34-
- match: { error.type: "mapper_parsing_exception" }
35-
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
36-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
21+
- match: { test-stored-source.mappings._source.mode: "stored" }
3722

3823
---
3924
disabled _source is not supported:
4025
- requires:
41-
test_runner_features: [capabilities]
42-
capabilities:
43-
- method: PUT
44-
path: /{index}
45-
capabilities: [logsdb_index_mode]
46-
reason: "Support for 'logsdb' index mode capability required"
47-
48-
- skip:
49-
known_issues:
50-
- cluster_feature: "gte_v8.15.0"
51-
fixed_by: "gte_v8.16.0"
52-
reason: "Development of logs index mode spans 8.15 and 8.16"
26+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
27+
reason: requires new error message
5328

5429
- do:
5530
catch: bad_request
@@ -62,33 +37,23 @@ disabled _source is not supported:
6237
mappings:
6338
_source:
6439
enabled: false
65-
properties:
66-
"@timestamp":
67-
type: date
68-
host.name:
69-
type: keyword
7040

7141
- match: { error.type: "mapper_parsing_exception" }
7242
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
73-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
43+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode" }
7444

7545
- do:
7646
catch: bad_request
7747
indices.create:
78-
index: test-disabled-source
48+
index: test-disabled-mode-source
7949
body:
8050
settings:
8151
index:
8252
mode: logsdb
8353
mappings:
8454
_source:
8555
mode: disabled
86-
properties:
87-
"@timestamp":
88-
type: date
89-
host.name:
90-
type: keyword
9156

9257
- match: { error.type: "mapper_parsing_exception" }
9358
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
94-
- match: { error.reason: "Failed to parse mapping: Indices with with index mode [logsdb] only support synthetic source" }
59+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [logsdb] index mode" }

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/20_mapping.yml

+18-8
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,12 @@ nested fields:
456456
- match: {tsdb-synthetic.mappings._source.mode: synthetic}
457457

458458
---
459-
regular source:
459+
stored source is supported:
460460
- requires:
461-
cluster_features: ["gte_v8.7.0"]
462-
reason: synthetic source
461+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
462+
reason: requires new validation logic
463463

464464
- do:
465-
catch: '/time series indices only support synthetic source/'
466465
indices.create:
467466
index: tsdb_index
468467
body:
@@ -486,14 +485,21 @@ regular source:
486485
uid:
487486
type: keyword
488487
time_series_dimension: true
488+
489+
- do:
490+
indices.get:
491+
index: tsdb_index
492+
493+
- match: { tsdb_index.mappings._source.mode: "stored" }
494+
489495
---
490-
disabled source:
496+
disabled source is not supported:
491497
- requires:
492-
cluster_features: ["gte_v8.7.0"]
493-
reason: synthetic source
498+
cluster_features: ["mapper.source.remove_synthetic_source_only_validation"]
499+
reason: requires new error message
494500

495501
- do:
496-
catch: '/time series indices only support synthetic source/'
502+
catch: bad_request
497503
indices.create:
498504
index: tsdb_index
499505
body:
@@ -518,6 +524,10 @@ disabled source:
518524
type: keyword
519525
time_series_dimension: true
520526

527+
- match: { error.type: "mapper_parsing_exception" }
528+
- match: { error.root_cause.0.type: "mapper_parsing_exception" }
529+
- match: { error.reason: "Failed to parse mapping: _source can not be disabled in index using [time_series] index mode" }
530+
521531
---
522532
source include/exclude:
523533
- requires:

server/src/main/java/org/elasticsearch/index/IndexMode.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ public boolean shouldValidateTimestamp() {
217217

218218
@Override
219219
public void validateSourceFieldMapper(SourceFieldMapper sourceFieldMapper) {
220-
if (sourceFieldMapper.isSynthetic() == false) {
221-
throw new IllegalArgumentException("time series indices only support synthetic source");
220+
if (sourceFieldMapper.enabled() == false) {
221+
throw new IllegalArgumentException("_source can not be disabled in index using [" + IndexMode.TIME_SERIES + "] index mode");
222222
}
223223
}
224224

@@ -292,8 +292,8 @@ public boolean shouldValidateTimestamp() {
292292

293293
@Override
294294
public void validateSourceFieldMapper(SourceFieldMapper sourceFieldMapper) {
295-
if (sourceFieldMapper.isSynthetic() == false) {
296-
throw new IllegalArgumentException("Indices with with index mode [" + IndexMode.LOGSDB + "] only support synthetic source");
295+
if (sourceFieldMapper.enabled() == false) {
296+
throw new IllegalArgumentException("_source can not be disabled in index using [" + IndexMode.LOGSDB + "] index mode");
297297
}
298298
}
299299

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public Set<NodeFeature> getFeatures() {
5858

5959
@Override
6060
public Set<NodeFeature> getTestFeatures() {
61-
return Set.of(RangeFieldMapper.DATE_RANGE_INDEXING_FIX, IgnoredSourceFieldMapper.DONT_EXPAND_DOTS_IN_IGNORED_SOURCE);
61+
return Set.of(
62+
RangeFieldMapper.DATE_RANGE_INDEXING_FIX,
63+
IgnoredSourceFieldMapper.DONT_EXPAND_DOTS_IN_IGNORED_SOURCE,
64+
SourceFieldMapper.REMOVE_SYNTHETIC_SOURCE_ONLY_VALIDATION
65+
);
6266
}
6367
}

server/src/main/java/org/elasticsearch/index/mapper/MappingParser.java

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.compress.CompressedXContent;
1313
import org.elasticsearch.common.xcontent.XContentHelper;
1414
import org.elasticsearch.core.Nullable;
15-
import org.elasticsearch.index.IndexMode;
1615
import org.elasticsearch.index.mapper.MapperService.MergeReason;
1716
import org.elasticsearch.xcontent.XContentType;
1817

@@ -147,10 +146,6 @@ Mapping parse(@Nullable String type, MergeReason reason, Map<String, Object> map
147146
assert fieldNodeMap.isEmpty();
148147

149148
if (metadataFieldMapper instanceof SourceFieldMapper sfm) {
150-
// Validation in other places should have failed first
151-
assert sfm.isSynthetic()
152-
|| (sfm.isSynthetic() == false && mappingParserContext.getIndexSettings().getMode() != IndexMode.TIME_SERIES)
153-
: "synthetic source can't be disabled in a time series index";
154149
isSourceSynthetic = sfm.isSynthetic();
155150
}
156151

server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class SourceFieldMapper extends MetadataFieldMapper {
5353
public static final NodeFeature SYNTHETIC_SOURCE_COPY_TO_INSIDE_OBJECTS_FIX = new NodeFeature(
5454
"mapper.source.synthetic_source_copy_to_inside_objects_fix"
5555
);
56+
public static final NodeFeature REMOVE_SYNTHETIC_SOURCE_ONLY_VALIDATION = new NodeFeature(
57+
"mapper.source.remove_synthetic_source_only_validation"
58+
);
5659

5760
public static final String NAME = "_source";
5861
public static final String RECOVERY_SOURCE_NAME = "_recovery_source";
@@ -288,9 +291,6 @@ private boolean isDefault(final Mode sourceMode) {
288291
@Override
289292
public SourceFieldMapper build() {
290293
if (enabled.getValue().explicit()) {
291-
if (indexMode != null && indexMode.isSyntheticSourceEnabled()) {
292-
throw new MapperParsingException("Indices with with index mode [" + indexMode + "] only support synthetic source");
293-
}
294294
if (mode.get() != null) {
295295
throw new MapperParsingException("Cannot set both [mode] and [enabled] parameters");
296296
}

0 commit comments

Comments
 (0)