Formalize evaluation state in controllers #119
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the controllers attempted to ensure exclusive access to an evaluation with some ad-hoc solutions. This PR improves this by introducing formalized constructs that deal with the evaluation state.
Additionally, using this EvalState the controller logic has been restructured to a more consistent, simplified model. A controller in its essence (currently still contain a lot of plumbing that at some point can be extracted to a shared controller helper) consists solely out of
evaluation(id string)
to trigger the evaluation of an object with the relevant id. A controller will do the required fetching of object states, e.g. get the current and desired object status from cache or a backing store, evaluate the difference, and execute actions if necessary. The evaluation can be modeled as a set of rules, where each rule evaluates the state and returns the required action:rule : state -> action
. In this PR this model has been implemented using theRule
andAction
interfaces. The advantages of this approach include improved testability of the individual and combinations of rules and actions, reuse of rules across different controllers, and a clear separation of mechanism (controller, actions) and policy (rules).Furthermore, as executing the actions typically does not introduce heavy load, the action workqueue has been removed. The exclusive access on the evaluation of an invocation or workflow is only removed after the action has been executed, preventing new evaluations before the previous action has been executed. Instead an evaluation queue has been added, with the controller ticker and notifications submitting evaluations to the queue. The controller evaluation loop uses this queue to determine the next id to evaluate, centralizing the entrypoint/usage of this control loop.
These changes together intend to make the controller approach more reliable, eliminate the existing (potential) concurrency issues, make the controllers better testable (as the added tests show) and provide a more simplified model of the controllers.
Additionally this PR: