Skip to content

Commit

Permalink
Fix enable API to schedule task after alert is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Jan 16, 2020
1 parent a922e1f commit a9915b8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ describe('enable()', () => {
schedule: { interval: '10s' },
alertTypeId: '2',
enabled: true,
scheduledTaskId: 'task-123',
updatedBy: 'elastic',
apiKey: null,
apiKeyOwner: null,
Expand All @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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: {
Expand Down
5 changes: 2 additions & 3 deletions x-pack/legacy/plugins/alerting/server/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit a9915b8

Please sign in to comment.