Skip to content

[Task Manager] Adds runNow api to Task Manager#51601

Merged
gmmorris merged 46 commits intoelastic:masterfrom
gmmorris:task-manager/run-now
Dec 16, 2019
Merged

[Task Manager] Adds runNow api to Task Manager#51601
gmmorris merged 46 commits intoelastic:masterfrom
gmmorris:task-manager/run-now

Conversation

@gmmorris
Copy link
Copy Markdown
Contributor

@gmmorris gmmorris commented Nov 25, 2019

Summary

Adds a runNow api to Task Manager, allowing us to force the refresh of a recurring task.

This PR includes a couple of sustainability changes as well as the feature itself.

  1. Declarative query composition. At the moment the queries in the TaskStore are huge JSON objects that are hard to maintain and understand. This PR introduces a pattern where the different parts of the query are composed out of type-checked functions, making it easier to maintain and to construct dynamically as needs change. _This was included in this PR as the markAvailableTasksAsClaimed query needs different query clauses depending on whether there are specific Tasks we wish to claim first.

  2. Refactoring of the Task Poller As the runNow api is introduced we find Task Manager's lifecycle in a weird state where it has both a pull model, where timeouts & callbacks interact without having to responsd to any external requests, and a push model where requests are made to the new runNow api. Balancing these two proved error prone, hard to maintain and had the potential of lossy behaviour where requests are dropped accidentally. To address this TaskPoller has been refactored using Rxjs observables, remodelling the existing pull mechanism as a push mechanism so Task Manager can respond to both polling calls and runNow in a similar fashion.

And ofcourse the main feature of this PR:

  1. runNow api An api on TaskManager that takes a task ID and attempts to run the task. The call returns a promise which resolves with a result which notifies the caller when the task has either completed successfully, or result in an error.

Open Issues:

There are still a couple of things to address in this PR:

  1. There is now an unbounded buffer - we probably want to cap it at some configurable capacity.

  2. If the task being run by runNow fails, it is treated the same as any task that fails - it is rescheduled to try again, assuming there are more attempts available to it. This means a call to runNow might report a failure, and it might then succeed minutes later. Some thought needs to be put into how to address/communicate this. We've agreed this is a natural behaviour and we're fine with it,.

  3. while TaskPoller now uses a push model, it still relies on some pull models (fillPool mainly, with it's while(true), doesn't fit into the model well) that should also be refactored - this should result in Task Manager being clearner and easier to maintain in the future.

  4. several Perf metrics have been omitted by the changes to TaskPoller, we should figure out how to bring these back. And a fresh performance test needs to be run to ensure these changes haven't caused a regression.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@gmmorris
Copy link
Copy Markdown
Contributor Author

gmmorris commented Dec 3, 2019

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-stack-services (Team:Stack Services)

@gmmorris gmmorris changed the title [Task Manager] Adds runNow api to Task Manager [DRAFT] [Task Manager] Adds runNow api to Task Manager Dec 3, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown
Contributor

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the code, not the tests (yet, anyway). Left a bunch of comments. I'd need more time to read/review this code to approve it - it's some pretty dense code, and I'm still n00bish on functional and observable.

* you may not use this file except in compliance with the Elastic License.
*/

export interface TermBoolClause {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern seems nice to me, I guess no one else has done something similar in Kibana already? OTOH, I'm a n00b at query DSL, so what do I know.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked around but couldn't see anything like it, so went ahead and did it to clean it up here in this PR. :)

@gmmorris gmmorris changed the title [Draft] [Task Manager] Adds runNow api to Task Manager [Task Manager] Adds runNow api to Task Manager Dec 11, 2019
@gmmorris
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a look and code LGTM. Though I'm not expert enough to review the observable related code. I would defer to someone with more expertise to do a targeted review on those pieces.

@gmmorris
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only reviewed the task_poller.ts code.

As discussed on slack: There could be another approach that could remove the whole scan operator by tapping into the set from pollRequests$ before the merge, However both approaches relies on side-effects, so it's only subjectif on which is the best one.

LGTM to me

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gmmorris
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gmmorris gmmorris merged commit bb98e9a into elastic:master Dec 16, 2019
gmmorris added a commit to gmmorris/kibana that referenced this pull request Dec 16, 2019
Adds a `runNow` api to Task Manager, allowing us to force the refresh of a recurring task.

This PR includes a couple of sustainability changes as well as the feature itself.

1. **Declarative query composition.** At the moment the queries in the TaskStore are huge JSON objects that are hard to maintain and understand. This PR introduces a pattern where the different parts of the query are composed out of type-checked functions, making it easier to maintain and to construct dynamically as needs change. _This was included in this PR as the **markAvailableTasksAsClaimed** query needs different query clauses depending on whether there are specific Tasks we wish to claim first.

2. **Refactoring of the Task Poller** As the `runNow` api is introduced we find Task Manager's lifecycle in a weird state where it has both a _pull_ model, where timeouts & callbacks interact without having to responsd to any external requests, and a _push_ model where requests are made to the new `runNow` api. Balancing these two proved error prone, hard to maintain and had the potential of _lossy_ behaviour where requests are dropped accidentally. To address this TaskPoller has been refactored using Rxjs observables, remodelling the existing _pull_ mechanism as a _push_ mechanism so Task Manager can _respond_ to both _polling_ calls and _runNow_ in a similar fashion.

And ofcourse the main feature of this PR:

3. **runNow api** An api on TaskManager that takes a _task ID_ and attempts to run the task. The call returns a promise which resolves with a result which notifies the caller when the task has either completed successfully, or result in an error.
gmmorris added a commit that referenced this pull request Dec 16, 2019
Adds a `runNow` api to Task Manager, allowing us to force the refresh of a recurring task.

This PR includes a couple of sustainability changes as well as the feature itself.

1. **Declarative query composition.** At the moment the queries in the TaskStore are huge JSON objects that are hard to maintain and understand. This PR introduces a pattern where the different parts of the query are composed out of type-checked functions, making it easier to maintain and to construct dynamically as needs change. _This was included in this PR as the **markAvailableTasksAsClaimed** query needs different query clauses depending on whether there are specific Tasks we wish to claim first.

2. **Refactoring of the Task Poller** As the `runNow` api is introduced we find Task Manager's lifecycle in a weird state where it has both a _pull_ model, where timeouts & callbacks interact without having to responsd to any external requests, and a _push_ model where requests are made to the new `runNow` api. Balancing these two proved error prone, hard to maintain and had the potential of _lossy_ behaviour where requests are dropped accidentally. To address this TaskPoller has been refactored using Rxjs observables, remodelling the existing _pull_ mechanism as a _push_ mechanism so Task Manager can _respond_ to both _polling_ calls and _runNow_ in a similar fashion.

And ofcourse the main feature of this PR:

3. **runNow api** An api on TaskManager that takes a _task ID_ and attempts to run the task. The call returns a promise which resolves with a result which notifies the caller when the task has either completed successfully, or result in an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants