-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Fix] Empty Alert Table when upgrading from 8.8.x -> 8.9 #162063
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,18 @@ export const migrateLegacyTimelinesToSecurityDataTable = (legacyTimelineTables: | |
}, {} as { [K in TableIdLiteral]: DataTableModel }); | ||
}; | ||
|
||
/* | ||
* | ||
* This migraiton only works for upgrading from | ||
* 8.7 -> 8.8. Please do not edit this migration for any | ||
* future release. | ||
* | ||
* If there is a migration that is required to be done for | ||
* any future release. It should written as a saperate piece of code | ||
* and should be called after this migration | ||
* | ||
* **/ | ||
|
||
export const migrateAlertTableStateToTriggerActionsState = ( | ||
storage: Storage, | ||
legacyDataTableState: DataTableState['dataTable']['tableById'] | ||
|
@@ -100,7 +112,7 @@ export const migrateAlertTableStateToTriggerActionsState = ( | |
sort: legacyDataTableState[tableKey].sort.map((sortCandidate) => ({ | ||
[sortCandidate.columnId]: { order: sortCandidate.sortDirection }, | ||
})), | ||
visibleColumns: legacyDataTableState[tableKey].columns.map((c) => c.id), | ||
visibleColumns: legacyDataTableState[tableKey].columns, | ||
}, | ||
}; | ||
}); | ||
|
@@ -110,7 +122,47 @@ export const migrateAlertTableStateToTriggerActionsState = ( | |
storage.set(key, stateObj[key]); | ||
}) | ||
); | ||
return Object.assign(legacyDataTableState, triggersActionsState); | ||
}; | ||
|
||
/* | ||
* | ||
* Used for migrating Alert Table from 8.8 => 8.9 | ||
* */ | ||
export const migrateTriggerActionsVisibleColumnsAlertTable88xTo89 = (storage: Storage) => { | ||
const localStorageKeys = [ | ||
`detection-engine-alert-table-${ALERTS_TABLE_REGISTRY_CONFIG_IDS.ALERTS_PAGE}-gridView`, | ||
`detection-engine-alert-table-${ALERTS_TABLE_REGISTRY_CONFIG_IDS.RULE_DETAILS}-gridView`, | ||
]; | ||
|
||
localStorageKeys.forEach((key) => { | ||
const alertTableData = storage.get(key); | ||
if (!alertTableData) { | ||
return; | ||
} | ||
if ('visibleColumns' in alertTableData) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have one more early exit here?
Right now the map will most likely run every time someone loads the table for every version after this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right.. made these changes with a little tweak. |
||
const visibleColumns = | ||
alertTableData.visibleColumns as DataTableState['dataTable']['tableById'][string]['columns']; | ||
const v89CompliantFormat = visibleColumns.every((val: unknown) => typeof val === 'string'); | ||
if (v89CompliantFormat) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweet, this works! 👍🏾 |
||
return; | ||
} | ||
const newVisibleColumns = visibleColumns | ||
.map((visibleCol) => { | ||
if (typeof visibleCol === 'string') { | ||
// if column format is 8.9 compliant already | ||
return visibleCol; | ||
} | ||
// if column format is 8.8 | ||
return visibleCol.id; | ||
}) | ||
.filter(Boolean); | ||
|
||
storage.set(key, { | ||
...alertTableData, | ||
visibleColumns: newVisibleColumns, | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
/** | ||
|
@@ -155,7 +207,8 @@ export const getDataTablesInStorageByIds = (storage: Storage, tableIds: TableIdL | |
} | ||
} | ||
|
||
allDataTables = migrateAlertTableStateToTriggerActionsState(storage, allDataTables); | ||
migrateAlertTableStateToTriggerActionsState(storage, allDataTables); | ||
migrateTriggerActionsVisibleColumnsAlertTable88xTo89(storage); | ||
|
||
return tableIds.reduce((acc, tableId) => { | ||
const tableModel = allDataTables[tableId]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted these changes: https://github.com/elastic/kibana/pull/161054/files#diff-462cfa4cb4b92df83bbcbc37c52901467f33c279a628266d35590df6fad2f9c2L103