[bug fix] handle rules exceeded error in listener rule synthesizer #4393
+493 −13
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.
Issue
#4373
Description
Fixes situation described in #4373. When the listener rule synthesizer moves rules into the last priorities (50,000 - 49900) and the listener is at all the rule limit, then the synthesizer gets stuck. This is because we always attempt to create rules prior to deleting, in order to prevent requests from not getting 404 errors due to missing listener rules. At first, I thought that the modify rule path should handle this, but closer inspection told me that we only call modify rule if the priority of the new rule matched the priority of a rule that we were deleting. This means that the only time you can successfully replace a rule is when you're at the maximum rules for a listener is to modify the rule at the exact priority (and perform no other modifications!).
The solution I came up with is to create a greedy algorithm that attempts to create all desired rules, up until we detect the listener is it's max rule limit. At this point of time, we start flip-flopping between delete and create in order to minimize time between rules missing on the listener. Finally, once all missing rules are created, we will delete all remaining undesired rules.
Some other solutions that I played around with..
1/ Always call modify rule. This meant determining which unmatched SDK and result LRs to map together to modify. The downside to this approach is that we can't guarantee that the customer provided priority ordering would match on the listener. This is because the Modify api doesn't allow priority modification. I was afraid of misrouting scenarios because of corrupted priority ordering.
2/ Something along the lines of again trying to map unmatched sdk and result LRs and perform the create / delete in that order. It was pretty hard to come up with a correct algorithm to do this matching..
Checklist
README.md, or thedocsdirectory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯