Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSDB: Add _tsid field to time_series indices #80276

Merged
merged 47 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2119b6d
Initial commit
csoulios Nov 3, 2021
9461331
Checkstyle
csoulios Nov 3, 2021
2ab1ff5
Merge branch 'master' into tsid-gen
csoulios Nov 3, 2021
fff4d7e
Removed TimeSeriesIdGeneratorService class
csoulios Nov 3, 2021
ca6c86e
Cleanup
csoulios Nov 3, 2021
12d89cf
Merge branch 'master' into tsid-gen
csoulios Nov 3, 2021
681831f
Revert
csoulios Nov 3, 2021
8267f74
Remove check for dynamic mapping update
csoulios Nov 3, 2021
7fbedc8
Return a shared instance of the tsid field mapper
csoulios Nov 3, 2021
1b5ef49
Remove tsid generator from Mapping class
csoulios Nov 4, 2021
95278e4
Remove TimeSeriesIdGenerator class
csoulios Nov 4, 2021
505d42b
Merge branch 'master' into tsid-gen
csoulios Nov 8, 2021
3ecaa8e
Merge branch 'master' into tsid-gen
csoulios Nov 9, 2021
e62254d
Delegate tsid generation to TsidFieldMapper
csoulios Nov 9, 2021
2975b48
Simplified dimension fields
csoulios Nov 9, 2021
7587518
More cleanup
csoulios Nov 9, 2021
b6f3f94
More cleanup
csoulios Nov 9, 2021
68e1526
Cleanup exception handling when parsing _tsid
csoulios Nov 9, 2021
a125aab
Fix broken tests
csoulios Nov 10, 2021
07ed667
Merge branch 'master' into tsid-gen
csoulios Nov 10, 2021
bc43ba0
Added more tests
csoulios Nov 10, 2021
5302edb
More tests
csoulios Nov 10, 2021
6860f38
More tests
csoulios Nov 10, 2021
05ed0d7
Cleanup
csoulios Nov 10, 2021
1a7e308
Merge branch 'master' into tsid-gen
csoulios Nov 11, 2021
8272182
Added rest tests for _tsid
csoulios Nov 11, 2021
05fc921
Merge branch 'master' into tsid-gen
csoulios Nov 11, 2021
15334e0
Sort by _tsid, @timestamp
csoulios Nov 11, 2021
5aaf469
Catch IOException at tsid field mapper level
csoulios Nov 11, 2021
9474774
spotless apply
csoulios Nov 11, 2021
359a22c
Fix test
csoulios Nov 13, 2021
02c2091
Fix test
csoulios Nov 13, 2021
14c23fe
Fix test
csoulios Nov 13, 2021
287a4c8
Merge branch 'master' into tsid-gen
csoulios Nov 13, 2021
7b87a71
Fix tests
csoulios Nov 15, 2021
271c66a
Merge branch 'master' into tsid-gen
csoulios Nov 15, 2021
1c1f0f8
Fix tests
csoulios Nov 15, 2021
713041d
Add _tsid field mapper only to time_series indices
csoulios Nov 16, 2021
c1cf213
Merge branch 'master' into tsid-gen
csoulios Nov 23, 2021
6a8dca6
Fix conflicts
csoulios Nov 23, 2021
5106a6e
Delegated building of tsid field mapper creation
csoulios Nov 23, 2021
0e10639
Fix brojen test
csoulios Nov 23, 2021
6d7d4ae
Merge branch 'master' into tsid-gen
csoulios Nov 23, 2021
91c91db
Fix broken tests
csoulios Nov 23, 2021
709700b
Addressed reviewer comments
csoulios Nov 25, 2021
1453e63
Merge branch 'master' into tsid-gen
csoulios Nov 25, 2021
12e5105
Merge branch 'master' into tsid-gen
csoulios Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,39 @@ can't shadow metrics:
runtime_mappings:
deep.deeper.deepest:
type: keyword

---
# Test that _tsid field is not added if an index is not a time-series index
no _tsid in standard indices:
- skip:
version: " - 8.00.99"
reason: _tsid support introduced in 8.1.0

- do:
indices.create:
index: test
body:
settings:
index:
number_of_replicas: 0
number_of_shards: 2
mappings:
properties:
"@timestamp":
type: date
metricset:
type: keyword
time_series_dimension: true

- do:
field_caps:
index: test
fields: [metricset, _tsid]

- match: {fields.metricset.keyword.searchable: true}
- match: {fields.metricset.keyword.aggregatable: true}
- match: {fields.metricset.keyword.time_series_dimension: true}
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices
- is_false: fields._tsid # _tsid metadata field must not exist in non-time-series indices
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ field capabilities:
- is_false: fields.metricset.keyword.indices
- is_false: fields.metricset.keyword.non_searchable_indices
- is_false: fields.metricset.keyword.non_aggregatable_indices
- match: { fields._tsid._tsid.metadata_field: true}
- match: {fields._tsid._tsid.metadata_field: true}
- match: {fields._tsid._tsid.searchable: false}
- match: {fields._tsid._tsid.aggregatable: true}
- is_false: fields._tsid._tsid.indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,14 @@ Map<Class<? extends MetadataFieldMapper>, MetadataFieldMapper> getMetadataMapper
if (existingMapper == null) {
for (MetadataFieldMapper.TypeParser parser : metadataMapperParsers.values()) {
MetadataFieldMapper metadataFieldMapper = parser.getDefault(parserContext());
metadataMappers.put(metadataFieldMapper.getClass(), metadataFieldMapper);
// A MetadataFieldMapper may choose to not be added to the metadata mappers
// of an index (eg TimeSeriesIdFieldMapper is only added to time series indices)
// In this case its TypeParser will return null instead of the MetadataFieldMapper
// instance.
if (metadataFieldMapper != null) {
metadataMappers.put(metadataFieldMapper.getClass(), metadataFieldMapper);
}
}

} else {
metadataMappers.putAll(existingMapper.mapping().getMetadataMappersMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,22 @@ public TimeSeriesIdFieldMapper build() {
}
}

public static final TypeParser PARSER = new ConfigurableTypeParser(c -> new TimeSeriesIdFieldMapper(), c -> new Builder());
/**
* A no-op builder does not return an instance of the field mapper. Instead, it returns null
* This is going to be used for non-time-series indices that should have this
*
*/
public static class NoopBuilder extends Builder {
@Override
public TimeSeriesIdFieldMapper build() {
return null;
}
}

public static final TypeParser PARSER = new ConfigurableTypeParser(
c -> c.getIndexSettings().getMode() == IndexMode.TIME_SERIES ? new TimeSeriesIdFieldMapper() : null,
c -> c.getIndexSettings().getMode() == IndexMode.TIME_SERIES ? new Builder() : new NoopBuilder()
);
csoulios marked this conversation as resolved.
Show resolved Hide resolved

public static final class TimeSeriesIdFieldType extends MappedFieldType {
private TimeSeriesIdFieldType() {
Expand Down Expand Up @@ -126,9 +141,6 @@ private TimeSeriesIdFieldMapper() {

@Override
public void postParse(DocumentParserContext context) throws IOException {
if (context.indexSettings().getMode() != IndexMode.TIME_SERIES) {
return;
}
assert fieldType().isSearchable() == false;

// SortedMap is expected to be sorted by key (field name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ public void testEnabledInTimeSeriesMode() throws Exception {

public void testDisabledInStandardMode() throws Exception {
DocumentMapper docMapper = createMapperService(
getIndexSettingsBuilder().put(IndexSettings.MODE.getKey(), "standard").build(),
getIndexSettingsBuilder().put(IndexSettings.MODE.getKey(), IndexMode.STANDARD.name()).build(),
mapping(b -> {})
).documentMapper();
ParsedDocument doc = docMapper.parse(source(b -> b.field("field", "value")));
assertThat(docMapper.metadataMapper(TimeSeriesIdFieldMapper.class), is(nullValue()));

ParsedDocument doc = docMapper.parse(source(b -> b.field("field", "value")));
assertThat(doc.rootDoc().getBinaryValue("_tsid"), is(nullValue()));
assertThat(doc.rootDoc().get("field"), equalTo("value"));
}

public void testIncludeInDocumentNotAllowed() throws Exception {
DocumentMapper docMapper = createDocumentMapper(mapping(b -> {}));
DocumentMapper docMapper = createDocumentMapper(
"a",
mapping(b -> { b.startObject("a").field("type", "keyword").field("time_series_dimension", true).endObject(); })
);
Exception e = expectThrows(MapperParsingException.class, () -> parseDocument(docMapper, b -> b.field("_tsid", "foo")));

assertThat(e.getCause().getMessage(), containsString("Field [_tsid] is a metadata field and cannot be added inside a document"));
Expand Down