-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: propagate tags on trigger and resume #3105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
12129d0
561b3d4
bea364c
8f33660
04dcd2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,7 +189,7 @@ def terminate(cls, flow_name, name): | |
| return response | ||
|
|
||
| @classmethod | ||
| def trigger(cls, name, parameters): | ||
| def trigger(cls, name, parameters, tags=None): | ||
| try: | ||
| state_machine = StepFunctionsClient().get(name) | ||
| except Exception as e: | ||
|
|
@@ -202,7 +202,15 @@ def trigger(cls, name, parameters): | |
| ) | ||
|
|
||
| # Dump parameters into `Parameters` input field. | ||
| input = json.dumps({"Parameters": json.dumps(parameters)}) | ||
| # Always include TriggerTags (defaulting to empty list) in the | ||
| # execution input. The state machine propagates this field through | ||
| # every step so that trigger-time tags are applied to all tasks. | ||
| input = json.dumps( | ||
| { | ||
| "Parameters": json.dumps(parameters), | ||
| "TriggerTags": json.dumps(tags if tags else []), | ||
|
Comment on lines
204
to
+211
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| ) | ||
| # AWS Step Functions limits input to be 32KiB, but AWS Batch | ||
| # has its own limitation of 30KiB for job specification length. | ||
| # Reserving 10KiB for rest of the job specification leaves 20KiB | ||
|
|
@@ -617,6 +625,11 @@ def _batch(self, node): | |
| # start step to all subsequent tasks. | ||
| attrs["metaflow.run_id.$"] = "$$.Execution.Name" | ||
|
|
||
| # Propagate trigger-time tags from execution input to all steps. | ||
| # The trigger command always includes TriggerTags in the input. | ||
| attrs["metaflow.trigger_tags.$"] = "$.TriggerTags" | ||
| env["METAFLOW_TRIGGER_TAGS"] = "$.TriggerTags" | ||
|
Comment on lines
+628
to
+631
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After redeploying a state machine with these changes, any execution that doesn't include The Argo path avoids this by setting "Input": json.dumps({"Parameters": json.dumps({}), "TriggerTags": json.dumps([])}), |
||
|
|
||
| # Initialize parameters for the flow in the `start` step. | ||
| parameters = self._process_parameters() | ||
| if parameters: | ||
|
|
@@ -677,6 +690,11 @@ def _batch(self, node): | |
| ) | ||
| # Inherit the run id from the parent and pass it along to children. | ||
| attrs["metaflow.run_id.$"] = "$.Parameters.['metaflow.run_id']" | ||
| # Propagate trigger-time tags from the parent. | ||
| attrs["metaflow.trigger_tags.$"] = ( | ||
| "$.Parameters.['metaflow.trigger_tags']" | ||
| ) | ||
| env["METAFLOW_TRIGGER_TAGS"] = "$.Parameters.['metaflow.trigger_tags']" | ||
| else: | ||
| # Set appropriate environment variables for runtime replacement. | ||
| if len(node.in_funcs) == 1: | ||
|
|
@@ -687,6 +705,13 @@ def _batch(self, node): | |
| env["METAFLOW_PARENT_TASK_ID"] = "$.JobId" | ||
| # Inherit the run id from the parent and pass it along to children. | ||
| attrs["metaflow.run_id.$"] = "$.Parameters.['metaflow.run_id']" | ||
| # Propagate trigger-time tags from the parent. | ||
| attrs["metaflow.trigger_tags.$"] = ( | ||
| "$.Parameters.['metaflow.trigger_tags']" | ||
| ) | ||
| env["METAFLOW_TRIGGER_TAGS"] = ( | ||
| "$.Parameters.['metaflow.trigger_tags']" | ||
| ) | ||
| else: | ||
| # Generate the input paths in a quasi-compressed format. | ||
| # See util.decompress_list for why this is written the way | ||
|
|
@@ -698,6 +723,13 @@ def _batch(self, node): | |
| ) | ||
| # Inherit the run id from the parent and pass it along to children. | ||
| attrs["metaflow.run_id.$"] = "$.[0].Parameters.['metaflow.run_id']" | ||
| # Propagate trigger-time tags from the first branch. | ||
| attrs["metaflow.trigger_tags.$"] = ( | ||
| "$.[0].Parameters.['metaflow.trigger_tags']" | ||
| ) | ||
| env["METAFLOW_TRIGGER_TAGS"] = ( | ||
| "$.[0].Parameters.['metaflow.trigger_tags']" | ||
| ) | ||
| for idx, _ in enumerate(node.in_funcs): | ||
| env["METAFLOW_PARENT_%s_TASK_ID" % idx] = "$.[%s].JobId" % idx | ||
| env["METAFLOW_PARENT_%s_STEP" % idx] = ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bare
except Exceptionswallows everything — includingAttributeError,ImportError, or other programming errors that signal a real bug. Consider catching only the expected failure modes (e.g.MetaflowNotFound, network errors) and letting unexpected exceptions surface, or at minimum logging a warning so callers know tags were silently dropped.