-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Simplifying the way the simulate ingest API uses component template substitutions for pipeline lookup and mapping validation #113908
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
Changes from 3 commits
f726e4e
08a80d7
4d78e91
dd46229
a0bb388
4e15bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
import org.elasticsearch.cluster.ClusterStateApplier; | ||
import org.elasticsearch.cluster.ClusterStateTaskExecutor; | ||
import org.elasticsearch.cluster.ClusterStateTaskListener; | ||
import org.elasticsearch.cluster.metadata.ComponentTemplate; | ||
import org.elasticsearch.cluster.metadata.DataStream; | ||
import org.elasticsearch.cluster.metadata.IndexAbstraction; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
|
@@ -271,30 +270,14 @@ public static void resolvePipelinesAndUpdateIndexRequest( | |
final IndexRequest indexRequest, | ||
final Metadata metadata | ||
) { | ||
resolvePipelinesAndUpdateIndexRequest(originalRequest, indexRequest, metadata, Map.of()); | ||
} | ||
|
||
public static void resolvePipelinesAndUpdateIndexRequest( | ||
final DocWriteRequest<?> originalRequest, | ||
final IndexRequest indexRequest, | ||
final Metadata metadata, | ||
Map<String, ComponentTemplate> componentTemplateSubstitutions | ||
) { | ||
resolvePipelinesAndUpdateIndexRequest( | ||
originalRequest, | ||
indexRequest, | ||
metadata, | ||
System.currentTimeMillis(), | ||
componentTemplateSubstitutions | ||
); | ||
resolvePipelinesAndUpdateIndexRequest(originalRequest, indexRequest, metadata, System.currentTimeMillis()); | ||
} | ||
|
||
static void resolvePipelinesAndUpdateIndexRequest( | ||
final DocWriteRequest<?> originalRequest, | ||
final IndexRequest indexRequest, | ||
final Metadata metadata, | ||
final long epochMillis, | ||
final Map<String, ComponentTemplate> componentTemplateSubstitutions | ||
final long epochMillis | ||
) { | ||
if (indexRequest.isPipelineResolved()) { | ||
return; | ||
|
@@ -307,16 +290,9 @@ static void resolvePipelinesAndUpdateIndexRequest( | |
* we don't fall back to the existing index if we don't find any because it is possible the user has intentionally removed the | ||
* pipeline. | ||
*/ | ||
final Pipelines pipelines; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update this comment and mention that in order of the simulation to work we would need to remove any existing index/data stream. I am thinking that now this can easily be missed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good point! I had forgotten about this comment. |
||
if (componentTemplateSubstitutions.isEmpty()) { | ||
pipelines = resolvePipelinesFromMetadata(originalRequest, indexRequest, metadata, epochMillis) // | ||
.or(() -> resolvePipelinesFromIndexTemplates(indexRequest, metadata, Map.of())) | ||
.orElse(Pipelines.NO_PIPELINES_DEFINED); | ||
} else { | ||
pipelines = resolvePipelinesFromIndexTemplates(indexRequest, metadata, componentTemplateSubstitutions).orElse( | ||
Pipelines.NO_PIPELINES_DEFINED | ||
); | ||
} | ||
final Pipelines pipelines = resolvePipelinesFromMetadata(originalRequest, indexRequest, metadata, epochMillis).or( | ||
() -> resolvePipelinesFromIndexTemplates(indexRequest, metadata) | ||
).orElse(Pipelines.NO_PIPELINES_DEFINED); | ||
|
||
// The pipeline coming as part of the request always has priority over the resolved one from metadata or templates | ||
String requestPipeline = indexRequest.getPipeline(); | ||
|
@@ -1466,11 +1442,7 @@ private static Optional<Pipelines> resolvePipelinesFromMetadata( | |
return Optional.of(new Pipelines(IndexSettings.DEFAULT_PIPELINE.get(settings), IndexSettings.FINAL_PIPELINE.get(settings))); | ||
} | ||
|
||
private static Optional<Pipelines> resolvePipelinesFromIndexTemplates( | ||
IndexRequest indexRequest, | ||
Metadata metadata, | ||
Map<String, ComponentTemplate> componentTemplateSubstitutions | ||
) { | ||
private static Optional<Pipelines> resolvePipelinesFromIndexTemplates(IndexRequest indexRequest, Metadata metadata) { | ||
if (indexRequest.index() == null) { | ||
return Optional.empty(); | ||
} | ||
|
@@ -1480,7 +1452,7 @@ private static Optional<Pipelines> resolvePipelinesFromIndexTemplates( | |
// precedence), or if a V2 template does not match, any V1 templates | ||
String v2Template = MetadataIndexTemplateService.findV2Template(metadata, indexRequest.index(), false); | ||
if (v2Template != null) { | ||
final Settings settings = MetadataIndexTemplateService.resolveSettings(metadata, v2Template, componentTemplateSubstitutions); | ||
final Settings settings = MetadataIndexTemplateService.resolveSettings(metadata, v2Template); | ||
return Optional.of(new Pipelines(IndexSettings.DEFAULT_PIPELINE.get(settings), IndexSettings.FINAL_PIPELINE.get(settings))); | ||
} | ||
|
||
|
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 think it will be really helpful to refer here to the methods that require this to work properly.
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 added a bit here. Let me know if there's something else that would be helpful.