Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,37 @@ describe('Alerts Service', () => {
}
});

test('should save the dynamic_templates', async () => {
const dynamicTemplates = [
{
strings_as_keywords: {
path_match: 'test-path',
match_mapping_type: 'string',
mapping: {
type: 'keyword',
ignore_above: 1024,
},
},
},
] satisfies IRuleTypeAlerts['mappings']['dynamicTemplates'];

alertsService.register({
...TestRegistrationContext,
mappings: {
...TestRegistrationContext.mappings,
dynamicTemplates,
},
});
await retryUntil(
'context initialized',
async () => (await getContextInitialized(alertsService)) === true
);

const componentTemplate = clusterClient.cluster.putComponentTemplate.mock.calls[3][0];
// @ts-ignore
expect(componentTemplate.template.mappings?.dynamic_templates).toEqual(dynamicTemplates);
});

test('should correctly install resources for custom namespace on demand when isSpaceAware is true', async () => {
alertsService.register({ ...TestRegistrationContext, isSpaceAware: true });
await retryUntil(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export class AlertsService implements IAlertsService {
const componentTemplate = getComponentTemplate({
fieldMap: mappings.fieldMap,
dynamic: mappings.dynamic,
dynamicTemplates: mappings.dynamicTemplates,
context,
});
initFns.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function createAlertsAsDataDynamicTemplatesTest({ getService }: F
// therefore we add 9 to get the real number.
const nestedObjectsAndMultiFields = 9;
// Number of free slots that we want to have, so we can add dynamic fields as many
const numberofFreeSlots = 3;
const numberofFreeSlots = 2;
const totalFields =
numberOfExistingFields + nestedObjectsAndMultiFields + numberofFreeSlots;

Expand Down Expand Up @@ -128,7 +128,7 @@ export default function createAlertsAsDataDynamicTemplatesTest({ getService }: F
);

// new dynamic field has been added
expect(dynamicField).to.eql('text');
expect(dynamicField).to.eql('keyword');
});
});

Expand Down