-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RAM] refactors RulesClient.update, by using new Task Manager API bulkUpdateSchedules #134027
[RAM] refactors RulesClient.update, by using new Task Manager API bulkUpdateSchedules #134027
Conversation
…liidm/kibana into task-manager-bulk-schedules
…-ref HEAD~1..HEAD --fix'
Addresses: #124850 ## Summary - Adds new method Task Manager API `bulkUpdateSchedules` - Adds calling `taskManager.bulkUpdateSchedules` in rulesClient.bulkEdit to update tasks if updated rules have `scheduleTaskId` property - Enables the rest of operations for rulesClient.bulkEdit (set schedule, notifyWhen, throttle) - #### bulkUpdateSchedules Using `bulkUpdatesSchedules` you can instruct TaskManager to update interval of tasks that are in `idle` status. When interval updated, new `runAt` will be computed and task will be updated with that value ```js export class Plugin { constructor() { } public setup(core: CoreSetup, plugins: { taskManager }) { } public start(core: CoreStart, plugins: { taskManager }) { try { const bulkUpdateResults = await taskManager.bulkUpdateSchedule( ['97c2c4e7-d850-11ec-bf95-895ffd19f959', 'a5ee24d1-dce2-11ec-ab8d-cf74da82133d'], { interval: '10m' }, ); // If no error is thrown, the bulkUpdateSchedule has completed successfully. // But some updates of some tasks can be failed, due to OCC 409 conflict for example } catch(err: Error) { // if error is caught, means the whole method requested has failed and tasks weren't updated } } } ``` ### in follow-up PRs - use `taskManager.bulkUpdateSchedules` in rulesClient.update (#134027) - functional test for bulkEdit (#133635) ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Release note Adds new method to Task Manager - bulkUpdatesSchedules, that allow bulk updates of scheduled tasks. Adds 3 new operations to rulesClient.bulkUpdate: update of schedule, notifyWhen, throttle.
…w-taks-manager-api
}); | ||
|
||
test('updating the alert should not wait for the rerun the task to complete', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't need this test anymore: we not running task anymore right after rule's SO updated, only doing REST API calls.
So, once user updates rule's schedule, there will be no time expensive run of rule, only underlying task update.
In that case, we can wait to this update finished and we won't need to leave unfinished HTTP requests once return response of RulesClient.update
Pinging @elastic/response-ops (Team:ResponseOps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Verified that updating a single task from the UI does not run the task immediately but sets a new runAt
time for the scheduled task document.
This might be worth a release note since this is a change in behavior for how rule schedule updates work.
); | ||
|
||
this.logger.debug( | ||
`Alert update has rescheduled the underlying task: ${updateResult.scheduledTaskId}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include the new runAt
in the log message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included, thanks for the suggestion
…w-taks-manager-api
Co-authored-by: Ying Mao <ying.mao@elastic.co>
Co-authored-by: Ying Mao <ying.mao@elastic.co>
…w-taks-manager-api
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: cc @vitaliidm |
Summary
RulesClient.update
method TaskManager APIrunNow
tobulkUpdateSchedules
When using runNow in scale, there can be situations, when TaskManager capacity is full, thus leading failure of
runNow
.Instead, new API
bulkUpdateSchedules
will be used, which in case if rule schedule is getting updated: will update underlying task schedule and will calculate newrunAt
time.More details on new TaskManager API: #132637, #124850
Checklist