Repository navigation
Bound the Liquid work of one email, and template request bodies - #644
Merged
Merged
Conversation
Each render of a compilation had its own limits and its own 5 seconds, and nothing bounded how many renders a template made: one block, attribute or condition each. A compilation now draws all its renders from one budget of 10 seconds and 20 million of render score; a template of the gallery spends well under 1% of it. templates.compile, templates.create and templates.update refuse a body over 1 MiB with 413, before it is parsed.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #644 +/- ##
=======================================
Coverage 90.46% 90.47%
=======================================
Files 390 391 +1
Lines 76569 76623 +54
=======================================
+ Hits 69271 69326 +55
+ Misses 4740 4739 -1
Partials 2558 2558
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The Liquid limits (render score, assign score, 5 seconds) applied to each render of a compilation, and a compilation makes one render per block, URL or alt attribute and display condition, plus the subject, the text and the whole document: nothing bounded how many of them a template made costly, and template request bodies had no size limit.
pkg/notifuse_mjml/render_budget.go):CompileTemplatecreates a budget of 10 s and 20 million of render score, and every render of the compilation takes the lower of its own limits and what is left, then has its score taken off. A spent budget fails the compilation with "liquid rendering exceeds the work budget of the email", like any Liquid error. The public functions (RenderWithTimeout,ProcessLiquidTemplate,Evaluate,ConvertJSONToMJMLWithData…) keep their signatures; the budget goes through internal parameters.templates.compile,templates.createandtemplates.updaterefuse a body over 1 MiB with 413 (decodeTemplateRequest). A gallery template weighs about 20 KB per language.Tests:
render_budget_test.go(budget arithmetic, a render stopped by score or time left, a 100-block costly tree stopped in under a second, every gallery template in every language under 1% of the budget, with its Liquid rendered),TestTemplateHandler_RequestBodyLimit(413 above, decoded at the limit, on the three endpoints), integrationTestTemplateCompileWorkLimits. Without the budget, the 100-block test takes 21.5 s and succeeds, so it fails.