Skip to content

Commit

Permalink
Fix the timestamp field of a data stream to @timestamp
Browse files Browse the repository at this point in the history
The commit makes the following changes:
* The timestamp field of a data stream definition in a composable
  index template can only be set to '@timestamp'.
* Removed custom data stream timestamp field validation and reuse the validation from `TimestampFieldMapper` and
  instead only check that the _timestamp field mapping has been defined on a backing index of a data stream.
* Moved code that injects _timestamp meta field mapping from `MetadataCreateIndexService#applyCreateIndexRequestWithV2Template58956(...)` method
  to `MetadataIndexTemplateService#collectMappings(...)` method.
* Fixed a bug (elastic#58956) that cases timestamp field validation to be performed
  for each template and instead of the final mappings that is created.

Relates to elastic#58642
Relates to elastic#53100
Closes elastic#58956
Closes elastic#58583
  • Loading branch information
martijnvg committed Jul 6, 2020
1 parent afb6f9c commit 5269034
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setup:
body:
index_patterns: logs-*
data_stream:
timestamp_field: timestamp
timestamp_field: '@timestamp'
template:
mappings:
properties:
Expand All @@ -36,7 +36,7 @@ teardown:
refresh: true
body:
foo: bar
timestamp: '2020-12-12'
'@timestamp': '2020-12-12'

- do:
reindex:
Expand Down Expand Up @@ -69,7 +69,7 @@ teardown:
refresh: true
body:
foo: bar
timestamp: '2020-12-12'
'@timestamp': '2020-12-12'

- do:
reindex:
Expand Down Expand Up @@ -102,7 +102,7 @@ teardown:
refresh: true
body:
foo: bar
timestamp: '2020-12-12'
'@timestamp': '2020-12-12'

- do:
reindex:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
- match: {data_streams.1.name: my_remote_cluster:simple-data-stream2}
- match: {data_streams.1.backing_indices.0: .ds-simple-data-stream2-000001}
- match: {data_streams.1.backing_indices.1: .ds-simple-data-stream2-000002}
- match: {data_streams.1.timestamp_field: "@timestamp2"}
- match: {data_streams.1.timestamp_field: "@timestamp"}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'@timestamp2':
type: date
data_stream:
timestamp_field: '@timestamp2'
timestamp_field: '@timestamp'

- do:
indices.create_data_stream:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ setup:
template:
mappings:
properties:
'@timestamp2':
'@timestamp':
type: date
data_stream:
timestamp_field: '@timestamp2'
timestamp_field: '@timestamp'

---
"Create data stream":
Expand All @@ -55,7 +55,7 @@ setup:
- length: { 0.indices: 1 }
- match: { 0.indices.0.index_name: '.ds-simple-data-stream1-000001' }
- match: { 1.name: simple-data-stream2 }
- match: { 1.timestamp_field.name: '@timestamp2' }
- match: { 1.timestamp_field.name: '@timestamp' }
- match: { 0.generation: 1 }
- length: { 1.indices: 1 }
- match: { 1.indices.0.index_name: '.ds-simple-data-stream2-000001' }
Expand Down Expand Up @@ -124,31 +124,26 @@ setup:
indices.get_data_stream: {}
- match: { 0.name: simple-data-stream1 }
- match: { 0.timestamp_field.name: '@timestamp' }
- match: { 0.timestamp_field.mapping: {type: date} }
- match: { 0.generation: 1 }
- match: { 1.name: simple-data-stream2 }
- match: { 1.timestamp_field.name: '@timestamp2' }
- match: { 1.timestamp_field.mapping: {type: date} }
- match: { 1.timestamp_field.name: '@timestamp' }
- match: { 1.generation: 1 }

- do:
indices.get_data_stream:
name: simple-data-stream1
- match: { 0.name: simple-data-stream1 }
- match: { 0.timestamp_field.name: '@timestamp' }
- match: { 0.timestamp_field.mapping: {type: date} }
- match: { 0.generation: 1 }

- do:
indices.get_data_stream:
name: simple-data-stream*
- match: { 0.name: simple-data-stream1 }
- match: { 0.timestamp_field.name: '@timestamp' }
- match: { 0.timestamp_field.mapping: {type: date} }
- match: { 0.generation: 1 }
- match: { 1.name: simple-data-stream2 }
- match: { 1.timestamp_field.name: '@timestamp2' }
- match: { 1.timestamp_field.mapping: {type: date} }
- match: { 1.timestamp_field.name: '@timestamp' }
- match: { 1.generation: 1 }

- do:
Expand Down Expand Up @@ -235,35 +230,35 @@ setup:
template:
mappings:
properties:
'timestamp':
'@timestamp':
type: date
data_stream:
timestamp_field: timestamp
timestamp_field: '@timestamp'

- do:
index:
index: logs-foobar
body: { timestamp: '2020-12-12' }
body: { '@timestamp': '2020-12-12' }
- match: { _index: .ds-logs-foobar-000001 }

- do:
catch: bad_request
index:
index: .ds-logs-foobar-000001
body: { timestamp: '2020-12-12' }
body: { '@timestamp': '2020-12-12' }

- do:
bulk:
body:
- create:
_index: .ds-logs-foobar-000001
- timestamp: '2020-12-12'
- '@timestamp': '2020-12-12'
- index:
_index: .ds-logs-foobar-000001
- timestamp: '2020-12-12'
- '@timestamp': '2020-12-12'
- create:
_index: logs-foobar
- timestamp: '2020-12-12'
- '@timestamp': '2020-12-12'
- match: { errors: true }
- match: { items.0.create.status: 400 }
- match: { items.0.create.error.type: illegal_argument_exception }
Expand Down Expand Up @@ -296,10 +291,10 @@ setup:
template:
mappings:
properties:
'timestamp':
'@timestamp':
type: date
data_stream:
timestamp_field: timestamp
timestamp_field: '@timestamp'

- do:
catch: bad_request
Expand All @@ -315,19 +310,19 @@ setup:
- foo: bar
- create:
_index: logs-foobar
- timestamp: '2020-12-12'
- '@timestamp': '2020-12-12'
- create:
_index: logs-foobar
- timestamp: ['2020-12-12', '2022-12-12']
- '@timestamp': ['2020-12-12', '2022-12-12']
- match: { errors: true }
- match: { items.0.create.status: 400 }
- match: { items.0.create.error.caused_by.type: illegal_argument_exception }
- match: { items.0.create.error.caused_by.reason: "data stream timestamp field [timestamp] is missing" }
- match: { items.0.create.error.caused_by.reason: "data stream timestamp field [@timestamp] is missing" }
- match: { items.1.create.result: created }
- match: { items.1.create._index: .ds-logs-foobar-000001 }
- match: { items.2.create.status: 400 }
- match: { items.2.create.error.caused_by.type: illegal_argument_exception }
- match: { items.2.create.error.caused_by.reason: "data stream timestamp field [timestamp] encountered multiple values" }
- match: { items.2.create.error.caused_by.reason: "data stream timestamp field [@timestamp] encountered multiple values" }

- do:
indices.delete_data_stream:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
body:
index_patterns: logs-*
data_stream:
timestamp_field: timestamp
timestamp_field: '@timestamp'
template:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
timestamp:
'@timestamp':
type: date

- do:
index:
index: logs-foobar
refresh: true
body:
'timestamp': '2020-12-12'
'@timestamp': '2020-12-12'
foo: bar

- do:
Expand All @@ -43,7 +43,7 @@
indices.get_data_stream:
name: logs-foobar
- match: { 0.name: logs-foobar }
- match: { 0.timestamp_field.name: 'timestamp' }
- match: { 0.timestamp_field.name: '@timestamp' }
- length: { 0.indices: 1 }
- match: { 0.indices.0.index_name: '.ds-logs-foobar-000001' }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ setup:
- match: {data_streams.1.name: simple-data-stream2}
- match: {data_streams.1.backing_indices.0: .ds-simple-data-stream2-000001}
- match: {data_streams.1.backing_indices.1: .ds-simple-data-stream2-000002}
- match: {data_streams.1.timestamp_field: "@timestamp2"}
- match: {data_streams.1.timestamp_field: "@timestamp"}

- do:
indices.delete_data_stream:
Expand Down Expand Up @@ -165,7 +165,7 @@ setup:
- match: {data_streams.1.name: simple-data-stream2}
- match: {data_streams.1.backing_indices.0: .ds-simple-data-stream2-000001}
- match: {data_streams.1.backing_indices.1: .ds-simple-data-stream2-000002}
- match: {data_streams.1.timestamp_field: "@timestamp2"}
- match: {data_streams.1.timestamp_field: "@timestamp"}

- do:
indices.delete_data_stream:
Expand Down
Loading

0 comments on commit 5269034

Please sign in to comment.