chore(AlertRuleGroup): Remove unnecessary requests during reconcile #2051
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.
Background
Noticed that the AlertRuleGroup reconciler would send 1 request per rule in the spec and thought it was a bit excessive.
It turns out that you can update all rules in a group at once by just updating the group, and if a rule is omitted from the update, it is then deleted.
But to create a rule, it is necessary to send POST for each new rule.
Knowing that, it was simple to just find the missing rules on a given instance and do the minimum GET and PUT requests to reconcile the difference.
Implementation
I would have liked to make smaller commits, but making individual commits that compiled and worked could not really be done easily.
editable
is still immutable and requires a recreate.rules
now has aMinItems=1
requiring at least one rule to be defined.In the old implementation this would apply successfully but do nothing?
Number of requests sent to each Grafana instance during a reconcile*.
N = number of rules in a group
*multiply by the number of instances for the total number of requests
I would appreciate individual testing as this is almost a rewrite of the reconcile function with a lot of changes.