-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Skip backing indices with a disjoint range on @timestamp field. #85162
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
Merged
elasticsearchmachine
merged 31 commits into
elastic:master
from
martijnvg:skip_backing_indices
Jul 4, 2022
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
1a130aa
Skip backing indices with a disjoint range on @timestamp field.
martijnvg 9db31c1
fix mistake
martijnvg 2b0e37c
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg ac5cb16
added first test
martijnvg e0fc357
checkstyle
martijnvg 82c41e2
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg a90bd47
fix test compile error after merging in master
martijnvg 025e05e
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg 74277ba
iter
martijnvg 8314534
spotless
martijnvg 7e9a877
iter
martijnvg b5d0d7d
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg 641cecf
refactor
martijnvg a26c720
fix bug, in case of IndexLongFieldRange.EMPTY the hasTimestampData() …
martijnvg 4fcec95
added test and
martijnvg a83cf41
RemoveTimeSeriesRange with IndexLongFieldRange
martijnvg 34ec679
re-order
martijnvg 714f629
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg de2e3ed
fix test compile error after merging in master
martijnvg c78845e
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg a4845e3
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg 0034d7a
use start and end time from IndexMetadata instead of parsing it from …
martijnvg b475761
Add unit like test that verifies that for tsdb data stream
martijnvg 68539e1
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg c5ecf62
spotless
martijnvg ffb33ec
fix bug
martijnvg 710bb28
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg 25b3bb3
handle when index mode is provided in upper case
martijnvg ca5893b
Merge remote-tracking branch 'es/master' into skip_backing_indices
martijnvg 679e699
spotless
martijnvg f09ffe7
Merge branch 'master' into skip_backing_indices
elasticmachine 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
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
117 changes: 117 additions & 0 deletions
117
...streams/src/test/java/org/elasticsearch/datastreams/TimestampFieldMapperServiceTests.java
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,117 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.datastreams; | ||
|
|
||
| import org.elasticsearch.action.DocWriteRequest; | ||
| import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; | ||
| import org.elasticsearch.action.index.IndexRequest; | ||
| import org.elasticsearch.action.index.IndexResponse; | ||
| import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; | ||
| import org.elasticsearch.cluster.metadata.Template; | ||
| import org.elasticsearch.common.compress.CompressedXContent; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.time.DateFormatter; | ||
| import org.elasticsearch.common.time.FormatNames; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.test.ESSingleNodeTestCase; | ||
| import org.elasticsearch.xcontent.XContentType; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Instant; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.hamcrest.Matchers.nullValue; | ||
|
|
||
| public class TimestampFieldMapperServiceTests extends ESSingleNodeTestCase { | ||
|
|
||
| private static final String DOC = """ | ||
| { | ||
| "@timestamp": "$time", | ||
| "metricset": "pod", | ||
| "k8s": { | ||
| "pod": { | ||
| "name": "dog", | ||
| "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", | ||
| "ip": "10.10.55.3", | ||
| "network": { | ||
| "tx": 1434595272, | ||
| "rx": 530605511 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> getPlugins() { | ||
| return List.of(DataStreamsPlugin.class); | ||
| } | ||
|
|
||
| public void testGetTimestampFieldTypeForTsdbDataStream() throws IOException { | ||
| createTemplate(true); | ||
| IndexResponse indexResponse = indexDoc(); | ||
|
|
||
| var indicesService = getInstanceFromNode(IndicesService.class); | ||
| var result = indicesService.getTimestampFieldType(indexResponse.getShardId().getIndex()); | ||
| assertThat(result, notNullValue()); | ||
| } | ||
|
|
||
| public void testGetTimestampFieldTypeForDataStream() throws IOException { | ||
| createTemplate(false); | ||
| IndexResponse indexResponse = indexDoc(); | ||
|
|
||
| var indicesService = getInstanceFromNode(IndicesService.class); | ||
| var result = indicesService.getTimestampFieldType(indexResponse.getShardId().getIndex()); | ||
| assertThat(result, nullValue()); | ||
| } | ||
|
|
||
| private IndexResponse indexDoc() { | ||
| Instant time = Instant.now(); | ||
| var indexRequest = new IndexRequest("k8s").opType(DocWriteRequest.OpType.CREATE); | ||
| indexRequest.source(DOC.replace("$time", formatInstant(time)), XContentType.JSON); | ||
| return client().index(indexRequest).actionGet(); | ||
| } | ||
|
|
||
| private void createTemplate(boolean tsdb) throws IOException { | ||
| var mappingTemplate = """ | ||
| { | ||
| "_doc":{ | ||
| "properties": { | ||
| "metricset": { | ||
| "type": "keyword", | ||
| "time_series_dimension": true | ||
| } | ||
| } | ||
| } | ||
| }"""; | ||
| var templateSettings = Settings.builder().put("index.mode", tsdb ? "time_series" : "standard"); | ||
| var request = new PutComposableIndexTemplateAction.Request("id"); | ||
| request.indexTemplate( | ||
| new ComposableIndexTemplate( | ||
| List.of("k8s*"), | ||
| new Template(templateSettings.build(), new CompressedXContent(mappingTemplate), null), | ||
| null, | ||
| null, | ||
| null, | ||
| null, | ||
| new ComposableIndexTemplate.DataStreamTemplate(false, false), | ||
| null | ||
| ) | ||
| ); | ||
| client().execute(PutComposableIndexTemplateAction.INSTANCE, request).actionGet(); | ||
| } | ||
|
|
||
| private static String formatInstant(Instant instant) { | ||
| return DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(instant); | ||
| } | ||
|
|
||
| } |
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
Oops, something went wrong.
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.
Hey. So. Like. I think I made
getTimestampBoundand it does like nearly the same thing, right? I feel like that method should be involved in this PR somehow. Or maybeIndexSettings.timestampBoundsshould be.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.
Good point. I think I can reuse
getTimestampBound(...)and thenIndexMetadata#getTimeSeriesTimestampRange(...)use that to build aIndexLongFieldRangeinstance.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.
TimestampBoundsneedsIndexScopedSettingswhich I don't have in the context In want to use it.This technically only needed for dynamically updating endTime field, which is my case isn't needed.
But maybe with a minor change to
TimestampBounds, I can use it too.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.
Ah! Would you be ok to merge this as is and then do some kind of refactoring to make combine the two paths somehow?
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.
Yes, I can do that.