-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting][8.0] Prepare alerting SOs to sharecapable (#110386)
* [Alerting] [8.0] Prepare for making alerting saved objects sharecapable (#109990) * [Alerting] [8.0] Prepare for making alerting saved objects sharecapable * removed v8 check * removed link * added no op migration * fixed name Co-authored-by: Kibana Machine <[email protected]> * [Actions] [8.0] Prepare for making action saved objects sharecapable. (#109756) * [Actions] [8.0] Prepare for making action saved objects sharecapable. * added more tests * made it compatible to merge to 7.x * fixed due to comments * fixed tests * added tests * fixed tests * fixed due to comments * added no-opactions migration * fixed test * [Task Manager][8.0] Added migrations to savedObject Ids for "actions:* and "alerting:*" task types (#109180) * [Task Manager][8.0] Added migrations to savedObject Ids for "actions:* and "alerting:*" task types * fixed due to comments * fixed typo * added more tests * added unit test * added func test * added func tests * fixed test Co-authored-by: Kibana Machine <[email protected]> * fixed merge * fixed legacy tests * fixed tests * fixed eslint * Update migrations.ts fixed action task * fixed due to comments Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
40b91c9
commit 3e15695
Showing
17 changed files
with
736 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
x-pack/plugins/task_manager/server/saved_objects/migrations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import uuid from 'uuid'; | ||
import { getMigrations } from './migrations'; | ||
import { SavedObjectUnsanitizedDoc } from 'kibana/server'; | ||
import { migrationMocks } from 'src/core/server/mocks'; | ||
import { TaskInstanceWithDeprecatedFields } from '../task'; | ||
|
||
const migrationContext = migrationMocks.createContext(); | ||
|
||
describe('successful migrations', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
describe('7.4.0', () => { | ||
test('extend task instance with updated_at', () => { | ||
const migration740 = getMigrations()['7.4.0']; | ||
const taskInstance = getMockData({}); | ||
expect(migration740(taskInstance, migrationContext).attributes.updated_at).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('7.6.0', () => { | ||
test('rename property Internal to Schedule', () => { | ||
const migration760 = getMigrations()['7.6.0']; | ||
const taskInstance = getMockData({}); | ||
expect(migration760(taskInstance, migrationContext)).toEqual({ | ||
...taskInstance, | ||
attributes: { | ||
...taskInstance.attributes, | ||
schedule: taskInstance.attributes.schedule, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('8.0.0', () => { | ||
test('transforms actionsTasksLegacyIdToSavedObjectIds', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'actions:123456', | ||
params: JSON.stringify({ spaceId: 'user1', actionTaskParamsId: '123456' }), | ||
}); | ||
|
||
expect(migration800(taskInstance, migrationContext)).toEqual({ | ||
...taskInstance, | ||
attributes: { | ||
...taskInstance.attributes, | ||
params: '{"spaceId":"user1","actionTaskParamsId":"800f81f8-980e-58ca-b710-d1b0644adea2"}', | ||
}, | ||
}); | ||
}); | ||
|
||
test('it is only applicable for saved objects that live in a custom space', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'actions:123456', | ||
params: JSON.stringify({ spaceId: 'default', actionTaskParamsId: '123456' }), | ||
}); | ||
|
||
expect(migration800(taskInstance, migrationContext)).toEqual(taskInstance); | ||
}); | ||
|
||
test('it is only applicable for saved objects that live in a custom space even if spaces are disabled', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'actions:123456', | ||
params: JSON.stringify({ actionTaskParamsId: '123456' }), | ||
}); | ||
|
||
expect(migration800(taskInstance, migrationContext)).toEqual(taskInstance); | ||
}); | ||
|
||
test('transforms alertingTaskLegacyIdToSavedObjectIds', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'alerting:123456', | ||
params: JSON.stringify({ spaceId: 'user1', alertId: '123456' }), | ||
}); | ||
|
||
expect(migration800(taskInstance, migrationContext)).toEqual({ | ||
...taskInstance, | ||
attributes: { | ||
...taskInstance.attributes, | ||
params: '{"spaceId":"user1","alertId":"1a4f9206-e25f-58e6-bad5-3ff21e90648e"}', | ||
}, | ||
}); | ||
}); | ||
|
||
test('skip transformation for defult space scenario', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'alerting:123456', | ||
params: JSON.stringify({ spaceId: 'default', alertId: '123456' }), | ||
}); | ||
|
||
expect(migration800(taskInstance, migrationContext)).toEqual({ | ||
...taskInstance, | ||
attributes: { | ||
...taskInstance.attributes, | ||
params: '{"spaceId":"default","alertId":"123456"}', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('handles errors during migrations', () => { | ||
describe('8.0.0 throws if migration fails', () => { | ||
test('should throw the exception if task instance params format is wrong', () => { | ||
const migration800 = getMigrations()['8.0.0']; | ||
const taskInstance = getMockData({ | ||
taskType: 'alerting:123456', | ||
params: `{ spaceId: 'user1', customId: '123456' }`, | ||
}); | ||
expect(() => { | ||
migration800(taskInstance, migrationContext); | ||
}).toThrowError(); | ||
expect(migrationContext.log.error).toHaveBeenCalledWith( | ||
`savedObject 8.0.0 migration failed for task instance ${taskInstance.id} with error: Unexpected token s in JSON at position 2`, | ||
{ | ||
migrations: { | ||
taskInstanceDocument: { | ||
...taskInstance, | ||
attributes: { | ||
...taskInstance.attributes, | ||
}, | ||
}, | ||
}, | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
function getUpdatedAt(): string { | ||
const updatedAt = new Date(); | ||
updatedAt.setHours(updatedAt.getHours() + 2); | ||
return updatedAt.toISOString(); | ||
} | ||
|
||
function getMockData( | ||
overwrites: Record<string, unknown> = {} | ||
): SavedObjectUnsanitizedDoc<Partial<TaskInstanceWithDeprecatedFields>> { | ||
return { | ||
attributes: { | ||
scheduledAt: new Date(), | ||
state: { runs: 0, total_cleaned_up: 0 }, | ||
runAt: new Date(), | ||
startedAt: new Date(), | ||
retryAt: new Date(), | ||
ownerId: '234', | ||
taskType: 'foo', | ||
schedule: { interval: '10s' }, | ||
params: { | ||
bar: true, | ||
}, | ||
...overwrites, | ||
}, | ||
updated_at: getUpdatedAt(), | ||
id: uuid.v4(), | ||
type: 'task', | ||
}; | ||
} |
Oops, something went wrong.