Skip to content

Commit

Permalink
changed condition to only update comp template on synthetic source ch…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
juliaElastic committed Nov 14, 2022
1 parent 41fe664 commit 5646bf5
Showing 1 changed file with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,39 @@ export async function handleExperimentalDatastreamFeatureOptIn({
(optIn) => optIn.data_stream === featureMapEntry.data_stream
);

const isOptInChanged =
existingOptIn?.features.synthetic_source !== featureMapEntry.features.synthetic_source ||
existingOptIn?.features.tsdb !== featureMapEntry.features.tsdb;
const isSyntheticSourceOptInChanged =
existingOptIn?.features.synthetic_source !== featureMapEntry.features.synthetic_source;

// If the feature opt-in status in unchanged, we don't need to update any component templates
if (!isOptInChanged) {
continue;
}

const componentTemplateName = `${featureMapEntry.data_stream}@package`;
const componentTemplateRes = await esClient.cluster.getComponentTemplate({
name: componentTemplateName,
});
if (isSyntheticSourceOptInChanged) {
const componentTemplateName = `${featureMapEntry.data_stream}@package`;
const componentTemplateRes = await esClient.cluster.getComponentTemplate({
name: componentTemplateName,
});

const componentTemplate = componentTemplateRes.component_templates[0].component_template;
const componentTemplate = componentTemplateRes.component_templates[0].component_template;

const body = {
template: {
...componentTemplate.template,
mappings: {
...componentTemplate.template.mappings,
_source: {
mode: featureMapEntry.features.synthetic_source ? 'synthetic' : 'stored',
const body = {
template: {
...componentTemplate.template,
mappings: {
...componentTemplate.template.mappings,
_source: {
mode: featureMapEntry.features.synthetic_source ? 'synthetic' : 'stored',
},
},
},
},
};
};

await esClient.cluster.putComponentTemplate({
name: componentTemplateName,
// @ts-expect-error - TODO: Remove when ES client typings include support for synthetic source
body,
});
await esClient.cluster.putComponentTemplate({
name: componentTemplateName,
// @ts-expect-error - TODO: Remove when ES client typings include support for synthetic source
body,
});
}

const isTSDBOptInChanged = existingOptIn?.features.tsdb !== featureMapEntry.features.tsdb;

if (featureMapEntry.features.tsdb) {
if (isTSDBOptInChanged && featureMapEntry.features.tsdb) {
const indexTemplateRes = await esClient.indices.getIndexTemplate({
name: featureMapEntry.data_stream,
});
Expand Down

0 comments on commit 5646bf5

Please sign in to comment.