Skip to content

Commit

Permalink
Fixes migration bug where I was deleting attributes (elastic#115098)
Browse files Browse the repository at this point in the history
## Summary

During the work here: elastic#113577

I accidentally have introduced a bug where on migration I was deleting the attributes of `ruleThrottle` and `alertThrottle` because I was not using splat correctly.

Added unit and e2e tests to fix this.

### Checklist
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
  • Loading branch information
FrankHassanabad authored and kibanamachine committed Oct 16, 2021
1 parent 5aa8e9b commit 7c44a1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('legacy_migrations', () => {
test('it migrates both a "ruleAlertId" and a actions array with 1 element into the references array', () => {
const doc = {
attributes: {
ruleThrottle: '1d',
alertThrottle: '1d',
ruleAlertId: '123',
actions: [
{
Expand All @@ -37,6 +39,8 @@ describe('legacy_migrations', () => {
)
).toEqual({
attributes: {
ruleThrottle: '1d',
alertThrottle: '1d',
actions: [
{
actionRef: 'action_0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const legacyMigrateRuleAlertId = (
return {
...doc,
attributes: {
...attributesWithoutRuleAlertId.attributes,
...attributesWithoutRuleAlertId,
actions: actionsWithRef,
},
references: [...existingReferences, ...alertReferences, ...actionsReferences],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ export default ({ getService }: FtrProviderContext): void => {
undefined
);
});

it('migrates legacy siem-detection-engine-rule-actions and retains "ruleThrottle" and "alertThrottle" as the same attributes as before', async () => {
const response = await es.get<{
'siem-detection-engine-rule-actions': {
ruleThrottle: string;
alertThrottle: string;
};
}>({
index: '.kibana',
id: 'siem-detection-engine-rule-actions:fce024a0-0452-11ec-9b15-d13d79d162f3',
});
expect(response.statusCode).to.eql(200);

// "alertThrottle" and "ruleThrottle" should still exist
expect(response.body._source?.['siem-detection-engine-rule-actions'].alertThrottle).to.eql(
'7d'
);
expect(response.body._source?.['siem-detection-engine-rule-actions'].ruleThrottle).to.eql(
'7d'
);
});
});
});
};

0 comments on commit 7c44a1a

Please sign in to comment.