Fix enable API to schedule task after alert is updated (#55095)

This commit is contained in:
Mike Côté 2020-01-17 10:48:48 -05:00 committed by GitHub
parent 5af378a2fb
commit 9c2d778d1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 7 deletions

View file

@ -883,7 +883,6 @@ describe('enable()', () => {
schedule: { interval: '10s' },
alertTypeId: '2',
enabled: true,
scheduledTaskId: 'task-123',
updatedBy: 'elastic',
apiKey: null,
apiKeyOwner: null,
@ -892,6 +891,9 @@ describe('enable()', () => {
version: '123',
}
);
expect(savedObjectsClient.update).toHaveBeenCalledWith('alert', '1', {
scheduledTaskId: 'task-123',
});
expect(taskManager.schedule).toHaveBeenCalledWith({
taskType: `alerting:2`,
params: {
@ -964,7 +966,6 @@ describe('enable()', () => {
schedule: { interval: '10s' },
alertTypeId: '2',
enabled: true,
scheduledTaskId: 'task-123',
apiKey: Buffer.from('123:abc').toString('base64'),
apiKeyOwner: 'elastic',
updatedBy: 'elastic',
@ -973,6 +974,9 @@ describe('enable()', () => {
version: '123',
}
);
expect(savedObjectsClient.update).toHaveBeenCalledWith('alert', '1', {
scheduledTaskId: 'task-123',
});
expect(taskManager.schedule).toHaveBeenCalledWith({
taskType: `alerting:2`,
params: {

View file

@ -362,7 +362,6 @@ export class AlertsClient {
});
if (attributes.enabled === false) {
const scheduledTask = await this.scheduleAlert(id, attributes.alertTypeId);
const username = await this.getUserName();
await this.savedObjectsClient.update(
'alert',
@ -372,11 +371,11 @@ export class AlertsClient {
enabled: true,
...this.apiKeyAsAlertAttributes(await this.createAPIKey(), username),
updatedBy: username,
scheduledTaskId: scheduledTask.id,
},
{ version }
);
const scheduledTask = await this.scheduleAlert(id, attributes.alertTypeId);
await this.savedObjectsClient.update('alert', id, { scheduledTaskId: scheduledTask.id });
await this.invalidateApiKey({ apiKey: attributes.apiKey });
}
}

View file

@ -761,8 +761,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
}
});
// Flaky: https://github.com/elastic/kibana/issues/54125
it.skip(`should unmute all instances when unmuting an alert`, async () => {
it(`should unmute all instances when unmuting an alert`, async () => {
const testStart = new Date();
const reference = alertUtils.generateReference();
const response = await alertUtils.createAlwaysFiringAction({