-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: apply user-defined aws_batch_tags regardless of BATCH_EMIT_TAGS #3210
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
Open
odncode
wants to merge
4
commits into
Netflix:master
Choose a base branch
from
odncode:fix-batch-tags-always-emit-user-tags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+81
−5
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9e298f
fix: apply user-defined aws_batch_tags regardless of BATCH_EMIT_TAGS
odncode 56a7330
test: add positive assertion for aws_batch_tags presence
odncode e50e340
Merge branch 'master' into fix-batch-tags-always-emit-user-tags
odncode 9ac9eca
style: add missing EOF newline (pre-commit)
odncode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """ | ||
| Regression test for user-defined AWS Batch tags. | ||
|
|
||
| User-defined tags (aws_batch_tags) and METAFLOW_BATCH_DEFAULT_TAGS should | ||
| always be applied to Batch jobs, regardless of the BATCH_EMIT_TAGS setting. | ||
| BATCH_EMIT_TAGS controls only Metaflow's internal observability tags | ||
| (app=metaflow, metaflow.flow_name, etc.), not user-specified tags. | ||
|
|
||
| See: https://github.com/Netflix/metaflow/issues/3209 | ||
| """ | ||
|
|
||
| import ast | ||
| import inspect | ||
| import textwrap | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_user_tags_not_inside_emit_tags_guard(): | ||
| """ | ||
| Verify that the aws_batch_tags block in batch.py is NOT inside | ||
| the BATCH_EMIT_TAGS conditional. This is a structural test that | ||
| checks the source code's AST to ensure user tags are always applied. | ||
| """ | ||
| from metaflow.plugins.aws.batch.batch import Batch | ||
|
|
||
| source = inspect.getsource(Batch.create_job) | ||
| # dedent because inspect.getsource preserves class indentation | ||
| source = textwrap.dedent(source) | ||
| tree = ast.parse(source) | ||
|
|
||
| # Find all If nodes that test BATCH_EMIT_TAGS | ||
| def find_emit_tags_guards(node): | ||
| """Find all 'if BATCH_EMIT_TAGS:' blocks and return their AST nodes.""" | ||
| guards = [] | ||
| for child in ast.walk(node): | ||
| if isinstance(child, ast.If): | ||
| # Check if the test is just 'BATCH_EMIT_TAGS' | ||
| test = child.test | ||
| if isinstance(test, ast.Name) and test.id == "BATCH_EMIT_TAGS": | ||
| guards.append(child) | ||
| return guards | ||
|
|
||
| def contains_aws_batch_tags_usage(node): | ||
| """Check if an AST node contains reference to 'aws_batch_tags'.""" | ||
| for child in ast.walk(node): | ||
| if isinstance(child, ast.Name) and child.id == "aws_batch_tags": | ||
| return True | ||
| return False | ||
|
|
||
| guards = find_emit_tags_guards(tree) | ||
| assert guards, "Could not find 'if BATCH_EMIT_TAGS:' block in create_job" | ||
|
|
||
| for guard in guards: | ||
| # Check the body of each BATCH_EMIT_TAGS guard | ||
| for stmt in guard.body: | ||
| assert not contains_aws_batch_tags_usage(stmt), ( | ||
| "aws_batch_tags is used inside 'if BATCH_EMIT_TAGS:' block. " | ||
| "User-defined tags should be applied unconditionally, outside " | ||
| "the BATCH_EMIT_TAGS guard." | ||
| ) | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.