feat(transform): Add MetaRetry Transform#222
Merged
Conversation
shellcromancer
approved these changes
Jul 29, 2024
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.
Description
MetaRetrytransform for retrying transform functions.Motivation and Context
This is a better implementation of what was previously in the
retry_with_backoffexample and can be used to add strict guarantees when enriching data with an external source (such as a REST API or KV store). For example, this can be used to:This transform will eventually return a limit exceeded error, which can be caught with the
MetaErrtransform if needed with the caveat that this can result in data loss for some transforms (only ones that I noticed areAggregateTo*; it does work forSend*transforms). The default behavior of the packaged applications is to crash on error, so I'm not too concerned about lossy transformation since:MetaErr)In future releases this may supersede retry strategies built into other transforms.
How Has This Been Tested?
Here are more configs that can be tested with a simple JSON event (like
{"a":"b"}):Retry All Errors
This is retried three times and fails:
sub.tf.meta.retry({ transforms: [ sub.tf.util.err({ message: 'test err'}), ], retry: { delay: '1s', count: 3, error_messages: [".*"] }, }),Retry Specific Errors
This is not retried and fails:
sub.tf.meta.retry({ transforms: [ sub.tf.util.err({ message: 'test err'}), ], retry: { delay: '1s', count: 3, error_messages: ["^err"] }, }),Retry Aggregate Transform
This fails if the data is put into the Y aggregate array transform. The failure isn't known until a ctrl message is received, and the data put into the array is lost on retry.
sub.tf.meta.retry({ transforms: [ sub.tf.meta.switch({ cases: [ { transforms: [ sub.tf.agg.to.arr({object: { target_key: 'x'}}), ], condition: sub.cnd.all([sub.cnd.utility.random()]), }, { transforms: [ sub.tf.agg.to.arr({object: { target_key: 'y'}}), ], } ]}), ], condition: sub.cnd.all([ sub.cnd.num.len.gt({ object: { source_key: 'x'}, value: 0 }), ]), retry: { delay: '1s', count: 3 }, }),Retry Send Aux Transform
This retries forever until it succeeds. The failure isn't known until a ctrl message is received, and the data put into the send is not lost on retry.
sub.tf.meta.retry({ transforms: [ sub.tf.send.stdout({ aux_tforms: [ sub.tf.meta.switch({ cases: [{ transforms: [ sub.tf.util.err({ message: 'test err'}), ], condition: sub.cnd.all([sub.cnd.utility.random()]), }]}) ]}), ], retry: { delay: '1s', error_messages: ['test err'] }, }),Types of changes
Checklist: