-
Couldn't load subscription status.
- Fork 25.6k
Updating TransportSimulateIndexTemplateAction.resolveTemplate() to account for data stream overrides #132131
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
masseyke
merged 15 commits into
elastic:main
from
masseyke:fix/TransportSimulateIndexTemplateAction-resolveTemplate
Aug 11, 2025
Merged
Updating TransportSimulateIndexTemplateAction.resolveTemplate() to account for data stream overrides #132131
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3720bf0
Updating TransportSimulateIndexTemplateAction.resolveTemplate() to ac…
masseyke 1edc47e
Update docs/changelog/132131.yaml
masseyke 55456f7
Merge branch 'main' into fix/TransportSimulateIndexTemplateAction-res…
masseyke 1a84742
fixing test method name
masseyke 9a4b79c
Merge branch 'fix/TransportSimulateIndexTemplateAction-resolveTemplat…
masseyke a3e5175
requiring logs stream feature for data stream mappings
masseyke 939298a
Merge branch 'main' into fix/TransportSimulateIndexTemplateAction-res…
masseyke 1971fa8
Update docs/changelog/132131.yaml
masseyke c4fc521
merging main
masseyke 9c90a1a
Merge branch 'main' into fix/TransportSimulateIndexTemplateAction-res…
masseyke 6116ce2
pulling mapping and setting logic into methods
masseyke fa9631a
Merge branch 'main' into fix/TransportSimulateIndexTemplateAction-res…
masseyke 042ebfc
templateNmae -> templateName
masseyke e3d710e
merging main
masseyke d6e03e4
adding javadocs
masseyke 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| pr: 132131 | ||
| summary: Updating `TransportSimulateIndexTemplateAction.resolveTemplate()` to account | ||
| for data stream overrides | ||
| area: Indices APIs | ||
| type: bug | ||
| issues: | ||
| - 131425 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ | |
| import org.elasticsearch.common.settings.ClusterSettings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.core.UpdateForV10; | ||
| import org.elasticsearch.index.IndexService; | ||
| import org.elasticsearch.index.IndexSettingProvider; | ||
|
|
@@ -48,7 +49,9 @@ | |
| import org.elasticsearch.transport.TransportService; | ||
| import org.elasticsearch.xcontent.NamedXContentRegistry; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
|
|
@@ -158,7 +161,6 @@ protected void localClusterStateOperation( | |
| listener.onResponse(new SimulateIndexTemplateResponse(null, null)); | ||
| return; | ||
| } | ||
|
|
||
| final ProjectMetadata tempProjectMetadata = resolveTemporaryState(matchingTemplate, request.getIndexName(), projectWithTemplate); | ||
| ComposableIndexTemplate templateV2 = tempProjectMetadata.templatesV2().get(matchingTemplate); | ||
| assert templateV2 != null : "the matched template must exist"; | ||
|
|
@@ -167,6 +169,7 @@ protected void localClusterStateOperation( | |
| matchingTemplate, | ||
| request.getIndexName(), | ||
| projectWithTemplate, | ||
| state.metadata().dataStreams().get(request.getIndexName()), | ||
| isDslOnlyMode, | ||
| xContentRegistry, | ||
| indicesService, | ||
|
|
@@ -233,44 +236,42 @@ public static ProjectMetadata resolveTemporaryState( | |
| /** | ||
| * Take a template and index name as well as state where the template exists, and return a final | ||
| * {@link Template} that represents all the resolved Settings, Mappings, Aliases and Lifecycle | ||
| * | ||
| * @param matchingTemplate | ||
| * @param indexName | ||
| * @param simulatedProject | ||
| * @param dataStream Used to get any data stream mapping or settings overrides to merge into the returned template | ||
| * @param isDslOnlyMode | ||
| * @param xContentRegistry | ||
| * @param indicesService | ||
| * @param systemIndices | ||
| * @param indexSettingProviders | ||
| * @return | ||
| * @throws Exception | ||
| */ | ||
| public static Template resolveTemplate( | ||
| final String matchingTemplate, | ||
| final String indexName, | ||
| final ProjectMetadata simulatedProject, | ||
| @Nullable final DataStream dataStream, | ||
| final boolean isDslOnlyMode, | ||
| final NamedXContentRegistry xContentRegistry, | ||
| final IndicesService indicesService, | ||
| final SystemIndices systemIndices, | ||
| Set<IndexSettingProvider> indexSettingProviders | ||
| ) throws Exception { | ||
| Settings templateSettings = resolveSettings(simulatedProject, matchingTemplate); | ||
|
|
||
| List<Map<String, AliasMetadata>> resolvedAliases = MetadataIndexTemplateService.resolveAliases(simulatedProject, matchingTemplate); | ||
|
|
||
| ComposableIndexTemplate template = simulatedProject.templatesV2().get(matchingTemplate); | ||
| Settings templateSettings = collectSettings(simulatedProject, dataStream, matchingTemplate, template); | ||
| // create the index with dummy settings in the cluster state so we can parse and validate the aliases | ||
| Settings.Builder dummySettings = Settings.builder() | ||
| .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()); | ||
|
|
||
| /* | ||
| * If the index name doesn't look like a data stream backing index, then MetadataCreateIndexService.collectV2Mappings() won't | ||
| * include data stream specific mappings in its response. | ||
| */ | ||
| String simulatedIndexName = template.getDataStreamTemplate() != null | ||
| && indexName.startsWith(DataStream.BACKING_INDEX_PREFIX) == false | ||
| ? DataStream.getDefaultBackingIndexName(indexName, 1) | ||
| : indexName; | ||
| List<CompressedXContent> mappings = MetadataCreateIndexService.collectV2Mappings( | ||
| null, // empty request mapping as the user can't specify any explicit mappings via the simulate api | ||
| simulatedProject, | ||
| template, | ||
| xContentRegistry, | ||
| simulatedIndexName | ||
| ); | ||
| List<CompressedXContent> mappings = collectMappings(simulatedProject, dataStream, template, indexName, xContentRegistry); | ||
|
|
||
| // First apply settings sourced from index settings providers | ||
| final var now = Instant.now(); | ||
|
|
@@ -360,6 +361,53 @@ public static Template resolveTemplate( | |
| ); | ||
| } | ||
|
|
||
| private static List<CompressedXContent> collectMappings( | ||
| ProjectMetadata simulatedProject, | ||
| DataStream dataStream, | ||
| ComposableIndexTemplate template, | ||
| String indexName, | ||
| NamedXContentRegistry xContentRegistry | ||
| ) throws IOException { | ||
| /* | ||
| * If the index name doesn't look like a data stream backing index, then MetadataCreateIndexService.collectV2Mappings() won't | ||
| * include data stream specific mappings in its response. | ||
| */ | ||
| String simulatedIndexName = template.getDataStreamTemplate() != null | ||
| && indexName.startsWith(DataStream.BACKING_INDEX_PREFIX) == false | ||
| ? DataStream.getDefaultBackingIndexName(indexName, 1) | ||
| : indexName; | ||
| List<CompressedXContent> mappings = MetadataCreateIndexService.collectV2Mappings( | ||
| null, // empty request mapping as the user can't specify any explicit mappings via the simulate api | ||
| simulatedProject, | ||
| template, | ||
| xContentRegistry, | ||
| simulatedIndexName | ||
| ); | ||
| if (template.getDataStreamTemplate() != null && dataStream != null) { | ||
| CompressedXContent dataStreamMappingOverrides = dataStream.getMappings(); | ||
| if (ComposableIndexTemplate.EMPTY_MAPPINGS.equals(dataStreamMappingOverrides) == false) { | ||
| // The data stream has had mapping overrides applied, so include these | ||
| mappings = new ArrayList<>(mappings); | ||
| mappings.add(dataStreamMappingOverrides); | ||
| } | ||
| } | ||
| return mappings; | ||
| } | ||
|
|
||
| private static Settings collectSettings( | ||
| final ProjectMetadata simulatedProject, | ||
| final DataStream dataStream, | ||
| String templateNmae, | ||
|
||
| ComposableIndexTemplate template | ||
| ) { | ||
| Settings templateSettings = resolveSettings(simulatedProject, templateNmae); | ||
| if (template.getDataStreamTemplate() != null && dataStream != null) { | ||
| // The data stream has had settings overrides applied, so include them | ||
| templateSettings = templateSettings.merge(dataStream.getSettings()); | ||
| } | ||
| return templateSettings; | ||
| } | ||
|
|
||
| private static IndexLongFieldRange getEventIngestedRange(String indexName, ProjectMetadata simulatedProject) { | ||
| final IndexMetadata indexMetadata = simulatedProject.index(indexName); | ||
| return indexMetadata == null ? IndexLongFieldRange.NO_SHARDS : indexMetadata.getEventIngestedRange(); | ||
|
|
||
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.
Can you add javadocs for this method?