-
Notifications
You must be signed in to change notification settings - Fork 25.6k
TSDB: Automatically map timestamp #78016
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/tsdb/15_timestamp_mapping.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
|
|
||
| --- | ||
| date: | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: introduced in 8.0.0 to be backported to 7.16.0 | ||
|
|
||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| index: | ||
| mode: time_series | ||
| number_of_replicas: 0 | ||
| number_of_shards: 2 | ||
| mappings: | ||
| properties: | ||
| "@timestamp": | ||
| type: date | ||
| metricset: | ||
| type: keyword | ||
| dimension: true | ||
|
|
||
| - do: | ||
| indices.get_mapping: | ||
| index: test | ||
| - match: { "[email protected]": date } | ||
|
|
||
| - do: | ||
| bulk: | ||
| refresh: true | ||
| index: test_index | ||
| body: | ||
| - '{"index": {}}' | ||
| - '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod"}' | ||
|
|
||
| - do: | ||
| search: | ||
| index: test_index | ||
| body: | ||
| docvalue_fields: [ '@timestamp' ] | ||
| - match: {hits.total.value: 1} | ||
| - match: { "hits.hits.0.fields.@timestamp": ["2021-04-28T18:50:04.467Z"] } | ||
|
|
||
| --- | ||
| date_nanos: | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: introduced in 8.0.0 to be backported to 7.16.0 | ||
|
|
||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| index: | ||
| mode: time_series | ||
| number_of_replicas: 0 | ||
| number_of_shards: 2 | ||
| mappings: | ||
| properties: | ||
| "@timestamp": | ||
| type: date_nanos | ||
| metricset: | ||
| type: keyword | ||
| dimension: true | ||
|
|
||
| - do: | ||
| indices.get_mapping: | ||
| index: test | ||
| - match: { "[email protected]": date_nanos } | ||
|
|
||
| - do: | ||
| bulk: | ||
| refresh: true | ||
| index: test_index | ||
| body: | ||
| - '{"index": {}}' | ||
| - '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod"}' | ||
|
|
||
| - do: | ||
| search: | ||
| index: test_index | ||
| body: | ||
| docvalue_fields: [ '@timestamp' ] | ||
| - match: {hits.total.value: 1} | ||
| - match: { "hits.hits.0.fields.@timestamp": ["2021-04-28T18:50:04.467Z"] } | ||
|
|
||
| --- | ||
| automatically add with date: | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: introduced in 8.0.0 to be backported to 7.16.0 | ||
|
|
||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| index: | ||
| mode: time_series | ||
| number_of_replicas: 0 | ||
| number_of_shards: 2 | ||
| mappings: | ||
| properties: | ||
| metricset: | ||
| type: keyword | ||
| dimension: true | ||
|
|
||
| - do: | ||
| indices.get_mapping: | ||
| index: test | ||
| - match: { 'test.mappings.properties.@timestamp': { "type": date } } | ||
|
|
||
| - do: | ||
| bulk: | ||
| refresh: true | ||
| index: test_index | ||
| body: | ||
| - '{"index": {}}' | ||
| - '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod"}' | ||
|
|
||
| - do: | ||
| search: | ||
| index: test_index | ||
| body: | ||
| docvalue_fields: [ '@timestamp' ] | ||
| - match: {hits.total.value: 1} | ||
| - match: { "hits.hits.0.fields.@timestamp": ["2021-04-28T18:50:04.467Z"] } | ||
|
|
||
| --- | ||
| reject @timestamp with wrong type: | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: introduced in 8.0.0 to be backported to 7.16.0 | ||
|
|
||
| - do: | ||
| catch: /@timestamp must be \[date\] or \[date_nanos\]/ | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| index: | ||
| mode: time_series | ||
| number_of_replicas: 0 | ||
| number_of_shards: 2 | ||
| mappings: | ||
| properties: | ||
| "@timestamp": | ||
| type: keyword |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data streams also automatically
@timestampas adatebut the way that do it seems really heavy to me. They have a special template calledDataStreamTemplateand they automatically apply it if the name starts with.ds-. We could do something similar but it'd take a bunch of extra layers of plumbing to get the setting into the template resolution layer. We'd still want the validation somewhere anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends, do you want the validation outside of data streams, or as a configuration option on the data stream itself? If you want it outside of data streams (for use with aliases for instance), then don't use the
DataStreamTemplate.Also, I notice that you add the mapper, but don't actually enforce that the
@timestampis filled in the way that a data stream does. I think you also need to validate that every document contains an@timestampfield, is that right? Or are you planning on filling it in automatically if it is missing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want it totally independent of data streams. If a time_series mode index is not in a data stream I still want there to be an
@timestampfield. I was more wondering if I should make a second special template or use a mechanism like this one here.I was planning on adding that test in a follow up change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach seems fine to me then, since you want it to be independent.
This should hopefully be easy as using
DataStreamTimestampFieldMapperinstead of theDateFieldMapper. I think we should probably unify them also so that they share the same infrastructure for validation, for example, it doesn't help if we add a@timestampfield but the user configures it forindexed: falseso we can't use it. TheDataStreamTimestampFieldMapperdoes more validation here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can have a look at unifying them in the follow up, yeah!