Skip to content
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

[7.16] [SecuritySolution][Detections] Fixes rule status migration when alertId is not a string (#117962) #118040

Merged
merged 2 commits into from
Nov 9, 2021
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 @@ -136,7 +136,6 @@ describe.each([

describe('mergeStatuses', () => {
it('merges statuses and converts from camelCase saved object to snake_case HTTP response', () => {
//
const statusOne = exampleRuleStatus();
statusOne.attributes.status = RuleExecutionStatus.failed;
const statusTwo = exampleRuleStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export const ruleStatusSavedObjectsClientFactory = (
type: 'alert',
}));
const order: 'desc' = 'desc';
// NOTE: Once https://github.com/elastic/kibana/issues/115153 is resolved
// ${legacyRuleStatusSavedObjectType}.statusDate will need to be updated to
// ${legacyRuleStatusSavedObjectType}.attributes.statusDate
const aggs = {
references: {
nested: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ export const legacyMigrateRuleAlertIdSOReferences = (
const { alertId, ...otherAttributes } = doc.attributes;
const existingReferences = doc.references ?? [];

// early return if alertId is not a string as expected
// early return if alertId is not a string as expected, still removing alertId as the mapping no longer exists
if (!isString(alertId)) {
return { ...doc, references: existingReferences };
return {
...doc,
attributes: otherAttributes,
references: existingReferences,
};
}

const alertReferences = legacyMigrateAlertId({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ export default ({ getService }: FtrProviderContext): void => {
lastLookBackDate: null,
});
});

// If alertId is not a string/null ensure it is removed as the mapping was removed and so the migration would fail.
// Specific test for this as e2e tests will not catch the mismatch and we can't use the migration test harness
// since this SO is not importable/exportable via the SOM.
// For details see: https://github.com/elastic/kibana/issues/116423
it('migrates legacy siem-detection-engine-rule-status and removes alertId when not a string', async () => {
const response = await es.get<{
'siem-detection-engine-rule-status': IRuleStatusSOAttributes;
}>({
index: '.kibana',
id: 'siem-detection-engine-rule-status:d62d2980-27c4-11ec-92b0-f7b47106bb36',
});
expect(response.statusCode).to.eql(200);

expect(response.body._source?.['siem-detection-engine-rule-status']).to.eql({
statusDate: '2021-10-11T20:51:26.622Z',
status: 'succeeded',
lastFailureAt: '2021-10-11T18:10:08.982Z',
lastSuccessAt: '2021-10-11T20:51:26.622Z',
lastFailureMessage:
'4 days (323690920ms) were not queried between this rule execution and the last execution, so signals may have been missed. Consider increasing your look behind time or adding more Kibana instances. name: "Threshy" id: "fb1046a0-0452-11ec-9b15-d13d79d162f3" rule id: "b789c80f-f6d8-41f1-8b4f-b4a23342cde2" signals index: ".siem-signals-spong-default"',
lastSuccessMessage: 'succeeded',
gap: '4 days',
bulkCreateTimeDurations: ['34.49'],
searchAfterTimeDurations: ['62.58'],
lastLookBackDate: null,
});
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,34 @@
}
}

{
"type": "doc",
"value": {
"id": "siem-detection-engine-rule-status:d62d2980-27c4-11ec-92b0-f7b47106bb36",
"index": ".kibana_1",
"source": {
"siem-detection-engine-rule-status": {
"alertId": 1337,
"statusDate": "2021-10-11T20:51:26.622Z",
"status": "succeeded",
"lastFailureAt": "2021-10-11T18:10:08.982Z",
"lastSuccessAt": "2021-10-11T20:51:26.622Z",
"lastFailureMessage": "4 days (323690920ms) were not queried between this rule execution and the last execution, so signals may have been missed. Consider increasing your look behind time or adding more Kibana instances. name: \"Threshy\" id: \"fb1046a0-0452-11ec-9b15-d13d79d162f3\" rule id: \"b789c80f-f6d8-41f1-8b4f-b4a23342cde2\" signals index: \".siem-signals-spong-default\"",
"lastSuccessMessage": "succeeded",
"gap": "4 days",
"bulkCreateTimeDurations": [
"34.49"
],
"searchAfterTimeDurations": [
"62.58"
],
"lastLookBackDate": null
},
"type": "siem-detection-engine-rule-status",
"references": [],
"coreMigrationVersion": "7.14.0",
"updated_at": "2021-10-11T20:51:26.657Z"
}
}
}