Skip to content

Commit d7a6fdc

Browse files
[8.19] Fix ignored dynamic templates (elastic#219875) (elastic#219899)
# Backport This will backport the following commits from `main` to `8.19`: - [Fix ignored dynamic templates (elastic#219875)](elastic#219875) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-02T08:28:56Z","message":"Fix ignored dynamic templates (elastic#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com/elastic/pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","backport:version","v9.1.0","v8.19.0","v9.0.1","v9.0.2"],"title":"Fix ignored dynamic templates","number":219875,"url":"https://github.com/elastic/kibana/pull/219875","mergeCommit":{"message":"Fix ignored dynamic templates (elastic#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com/elastic/pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.19"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219875","number":219875,"mergeCommit":{"message":"Fix ignored dynamic templates (elastic#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com/elastic/pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Ersin Erdal <[email protected]> Co-authored-by: Ersin Erdal <[email protected]>
1 parent e73e035 commit d7a6fdc

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

x-pack/platform/plugins/shared/alerting/server/alerts_service/alerts_service.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,37 @@ describe('Alerts Service', () => {
708708
}
709709
});
710710

711+
test('should save the dynamic_templates', async () => {
712+
const dynamicTemplates = [
713+
{
714+
strings_as_keywords: {
715+
path_match: 'test-path',
716+
match_mapping_type: 'string',
717+
mapping: {
718+
type: 'keyword',
719+
ignore_above: 1024,
720+
},
721+
},
722+
},
723+
] satisfies IRuleTypeAlerts['mappings']['dynamicTemplates'];
724+
725+
alertsService.register({
726+
...TestRegistrationContext,
727+
mappings: {
728+
...TestRegistrationContext.mappings,
729+
dynamicTemplates,
730+
},
731+
});
732+
await retryUntil(
733+
'context initialized',
734+
async () => (await getContextInitialized(alertsService)) === true
735+
);
736+
737+
const componentTemplate = clusterClient.cluster.putComponentTemplate.mock.calls[3][0];
738+
// @ts-ignore
739+
expect(componentTemplate.template.mappings?.dynamic_templates).toEqual(dynamicTemplates);
740+
});
741+
711742
test('should correctly install resources for custom namespace on demand when isSpaceAware is true', async () => {
712743
alertsService.register({ ...TestRegistrationContext, isSpaceAware: true });
713744
await retryUntil(

x-pack/platform/plugins/shared/alerting/server/alerts_service/alerts_service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ export class AlertsService implements IAlertsService {
432432
const componentTemplate = getComponentTemplate({
433433
fieldMap: mappings.fieldMap,
434434
dynamic: mappings.dynamic,
435+
dynamicTemplates: mappings.dynamicTemplates,
435436
context,
436437
});
437438
initFns.push(

x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group4/alerts_as_data/alerts_as_data_dynamic_templates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function createAlertsAsDataDynamicTemplatesTest({ getService }: F
7373
// therefore we add 9 to get the real number.
7474
const nestedObjectsAndMultiFields = 9;
7575
// Number of free slots that we want to have, so we can add dynamic fields as many
76-
const numberofFreeSlots = 3;
76+
const numberofFreeSlots = 2;
7777
const totalFields =
7878
numberOfExistingFields + nestedObjectsAndMultiFields + numberofFreeSlots;
7979

@@ -128,7 +128,7 @@ export default function createAlertsAsDataDynamicTemplatesTest({ getService }: F
128128
);
129129

130130
// new dynamic field has been added
131-
expect(dynamicField).to.eql('text');
131+
expect(dynamicField).to.eql('keyword');
132132
});
133133
});
134134

0 commit comments

Comments
 (0)