Fix enable API to schedule task after alert is updated (#55095)
This commit is contained in:
parent
5af378a2fb
commit
9c2d778d1c
|
@ -883,7 +883,6 @@ describe('enable()', () => {
|
||||||
schedule: { interval: '10s' },
|
schedule: { interval: '10s' },
|
||||||
alertTypeId: '2',
|
alertTypeId: '2',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
scheduledTaskId: 'task-123',
|
|
||||||
updatedBy: 'elastic',
|
updatedBy: 'elastic',
|
||||||
apiKey: null,
|
apiKey: null,
|
||||||
apiKeyOwner: null,
|
apiKeyOwner: null,
|
||||||
|
@ -892,6 +891,9 @@ describe('enable()', () => {
|
||||||
version: '123',
|
version: '123',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
expect(savedObjectsClient.update).toHaveBeenCalledWith('alert', '1', {
|
||||||
|
scheduledTaskId: 'task-123',
|
||||||
|
});
|
||||||
expect(taskManager.schedule).toHaveBeenCalledWith({
|
expect(taskManager.schedule).toHaveBeenCalledWith({
|
||||||
taskType: `alerting:2`,
|
taskType: `alerting:2`,
|
||||||
params: {
|
params: {
|
||||||
|
@ -964,7 +966,6 @@ describe('enable()', () => {
|
||||||
schedule: { interval: '10s' },
|
schedule: { interval: '10s' },
|
||||||
alertTypeId: '2',
|
alertTypeId: '2',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
scheduledTaskId: 'task-123',
|
|
||||||
apiKey: Buffer.from('123:abc').toString('base64'),
|
apiKey: Buffer.from('123:abc').toString('base64'),
|
||||||
apiKeyOwner: 'elastic',
|
apiKeyOwner: 'elastic',
|
||||||
updatedBy: 'elastic',
|
updatedBy: 'elastic',
|
||||||
|
@ -973,6 +974,9 @@ describe('enable()', () => {
|
||||||
version: '123',
|
version: '123',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
expect(savedObjectsClient.update).toHaveBeenCalledWith('alert', '1', {
|
||||||
|
scheduledTaskId: 'task-123',
|
||||||
|
});
|
||||||
expect(taskManager.schedule).toHaveBeenCalledWith({
|
expect(taskManager.schedule).toHaveBeenCalledWith({
|
||||||
taskType: `alerting:2`,
|
taskType: `alerting:2`,
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -362,7 +362,6 @@ export class AlertsClient {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (attributes.enabled === false) {
|
if (attributes.enabled === false) {
|
||||||
const scheduledTask = await this.scheduleAlert(id, attributes.alertTypeId);
|
|
||||||
const username = await this.getUserName();
|
const username = await this.getUserName();
|
||||||
await this.savedObjectsClient.update(
|
await this.savedObjectsClient.update(
|
||||||
'alert',
|
'alert',
|
||||||
|
@ -372,11 +371,11 @@ export class AlertsClient {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
...this.apiKeyAsAlertAttributes(await this.createAPIKey(), username),
|
...this.apiKeyAsAlertAttributes(await this.createAPIKey(), username),
|
||||||
updatedBy: username,
|
updatedBy: username,
|
||||||
|
|
||||||
scheduledTaskId: scheduledTask.id,
|
|
||||||
},
|
},
|
||||||
{ version }
|
{ version }
|
||||||
);
|
);
|
||||||
|
const scheduledTask = await this.scheduleAlert(id, attributes.alertTypeId);
|
||||||
|
await this.savedObjectsClient.update('alert', id, { scheduledTaskId: scheduledTask.id });
|
||||||
await this.invalidateApiKey({ apiKey: attributes.apiKey });
|
await this.invalidateApiKey({ apiKey: attributes.apiKey });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -761,8 +761,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Flaky: https://github.com/elastic/kibana/issues/54125
|
it(`should unmute all instances when unmuting an alert`, async () => {
|
||||||
it.skip(`should unmute all instances when unmuting an alert`, async () => {
|
|
||||||
const testStart = new Date();
|
const testStart = new Date();
|
||||||
const reference = alertUtils.generateReference();
|
const reference = alertUtils.generateReference();
|
||||||
const response = await alertUtils.createAlwaysFiringAction({
|
const response = await alertUtils.createAlwaysFiringAction({
|
||||||
|
|
Loading…
Reference in a new issue