mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [[RAM] fix logger bug (#146139)](https://github.com/elastic/kibana/pull/146139) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia","email":"iuliia.guskova@elastic.co"},"sourceCommit":{"committedDate":"2022-11-24T08:24:19Z","message":"[RAM] fix logger bug (#146139)\n\nResolves: https://github.com/elastic/kibana/issues/146097\r\n\r\n## Summary\r\n\r\nIn this PR I'm fixing a bug for bulkDelete endpoint.\r\nIt loggers this error message:\r\n`[2022-11-22T15:19:31.182+01:00][ERROR][plugins.alerting] Failure to\r\ndelete schedules for underlying tasks:` even if we do not have any\r\nfailed to delete tasks.\r\n\r\n### Checklist\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"ad8373c46ff92537f655c095fe58bb634d946a7b","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Alerting/RulesManagement","backport:prev-minor","v8.6.0"],"number":146139,"url":"https://github.com/elastic/kibana/pull/146139","mergeCommit":{"message":"[RAM] fix logger bug (#146139)\n\nResolves: https://github.com/elastic/kibana/issues/146097\r\n\r\n## Summary\r\n\r\nIn this PR I'm fixing a bug for bulkDelete endpoint.\r\nIt loggers this error message:\r\n`[2022-11-22T15:19:31.182+01:00][ERROR][plugins.alerting] Failure to\r\ndelete schedules for underlying tasks:` even if we do not have any\r\nfailed to delete tasks.\r\n\r\n### Checklist\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"ad8373c46ff92537f655c095fe58bb634d946a7b"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Julia <iuliia.guskova@elastic.co>
This commit is contained in:
parent
fbf1981c00
commit
66f900f93b
2 changed files with 49 additions and 19 deletions
|
@ -2112,14 +2112,20 @@ export class RulesClient {
|
|||
taskIdsFailedToBeDeleted.push(status.id);
|
||||
}
|
||||
});
|
||||
this.logger.debug(
|
||||
`Successfully deleted schedules for underlying tasks: ${taskIdsSuccessfullyDeleted.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
this.logger.error(
|
||||
`Failure to delete schedules for underlying tasks: ${taskIdsFailedToBeDeleted.join(', ')}`
|
||||
);
|
||||
if (taskIdsSuccessfullyDeleted.length) {
|
||||
this.logger.debug(
|
||||
`Successfully deleted schedules for underlying tasks: ${taskIdsSuccessfullyDeleted.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
if (taskIdsFailedToBeDeleted.length) {
|
||||
this.logger.error(
|
||||
`Failure to delete schedules for underlying tasks: ${taskIdsFailedToBeDeleted.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Failure to delete schedules for underlying tasks: ${taskIdsToDelete.join(
|
||||
|
|
|
@ -390,19 +390,16 @@ describe('bulkDelete', () => {
|
|||
],
|
||||
}));
|
||||
|
||||
const result = await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });
|
||||
await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });
|
||||
|
||||
expect(logger.debug).toBeCalledTimes(1);
|
||||
expect(logger.debug).toBeCalledWith(
|
||||
'Successfully deleted schedules for underlying tasks: taskId1'
|
||||
);
|
||||
expect(logger.error).toBeCalledTimes(1);
|
||||
expect(logger.error).toBeCalledWith(
|
||||
'Failure to delete schedules for underlying tasks: taskId2'
|
||||
);
|
||||
expect(result).toStrictEqual({
|
||||
errors: [],
|
||||
total: 2,
|
||||
taskIdsFailedToBeDeleted: ['taskId2'],
|
||||
});
|
||||
});
|
||||
|
||||
test('should not throw an error if taskManager throw an error', async () => {
|
||||
|
@ -417,17 +414,44 @@ describe('bulkDelete', () => {
|
|||
throw new Error('UPS');
|
||||
});
|
||||
|
||||
const result = await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });
|
||||
await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });
|
||||
|
||||
expect(logger.error).toBeCalledTimes(1);
|
||||
expect(logger.error).toBeCalledWith(
|
||||
'Failure to delete schedules for underlying tasks: taskId1, taskId2. TaskManager bulkRemoveIfExist failed with Error: UPS'
|
||||
);
|
||||
expect(result).toStrictEqual({
|
||||
errors: [],
|
||||
taskIdsFailedToBeDeleted: [],
|
||||
total: 2,
|
||||
});
|
||||
|
||||
test('should not call logger.error if all tasks successfully deleted', async () => {
|
||||
mockCreatePointInTimeFinderAsInternalUser();
|
||||
unsecuredSavedObjectsClient.bulkDelete.mockResolvedValue({
|
||||
statuses: [
|
||||
{ id: 'id1', type: 'alert', success: true },
|
||||
{ id: 'id2', type: 'alert', success: true },
|
||||
],
|
||||
});
|
||||
taskManager.bulkRemoveIfExist.mockImplementation(async () => ({
|
||||
statuses: [
|
||||
{
|
||||
id: 'taskId1',
|
||||
type: 'alert',
|
||||
success: true,
|
||||
},
|
||||
{
|
||||
id: 'taskId2',
|
||||
type: 'alert',
|
||||
success: true,
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
await rulesClient.bulkDeleteRules({ filter: 'fake_filter' });
|
||||
|
||||
expect(logger.debug).toBeCalledTimes(1);
|
||||
expect(logger.debug).toBeCalledWith(
|
||||
'Successfully deleted schedules for underlying tasks: taskId1, taskId2'
|
||||
);
|
||||
expect(logger.error).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue