-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(auto_source): Derive a code mapping per module #101288
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
Conversation
The work to derive code mappings for Java fell short of supporting multi module directory structure. This adds support for multi module directory structure behind a feature flag.
| # com.example.multi.foo.bar.Baz$InnerClass, Baz.kt -> | ||
| # stack_root: com/example/multi/foo/ | ||
| # file_path: com/example/multi/foo/bar/Baz.kt | ||
| granularity = STACK_ROOT_MAX_LEVEL |
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.
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.
hm, just wondering, if there are second level TLDs would this still work? E.g. au/com/company/app/feature/ ? Found this repo as an exemplar: https://github.com/Automattic/pocket-casts-android/tree/main/modules/features/account/src/main/java/au/com/shiftyjelly/pocketcasts/account
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.
I have filed it as a ticket to follow-up on.
| source_root=expected_cm["source_root"], | ||
| ).first() | ||
| code_mapping = current_code_mappings.get( | ||
| project_id=self.project.id, stack_root=expected_cm["stack_root"] |
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 index together is the project and the stack root.
| project_id=self.project.id, stack_root=expected_cm["stack_root"] | ||
| ) | ||
| assert code_mapping is not None | ||
| assert code_mapping.source_root == expected_cm["source_root"] |
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.
When a test fails, this assertion is better than when source_root did not match (the call to first() would give us None).
| expected_new_in_app_stack_trace_rules=["stack.module:android.app.** +app"], | ||
| ) | ||
|
|
||
| def test_multi_module_with_old_granularity(self) -> None: |
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.
This is the current behaviour without the option.
We will delete this test once we're fully rolled out.
| # It's missing the extra granularity | ||
| # It's going to pick modY since it is the first frame processed, thus, | ||
| # the other frame will not have a working code mapping | ||
| self.code_mapping("com/example/multi/", "modules/modY/com/example/multi/") |
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.
This code mapping will not work for com.example.multi.foo.Bar since the file is found under modules/modX/com.example.multi/foo/Bar.kt.
| # the other frame will not have a working code mapping | ||
| self.code_mapping("com/example/multi/", "modules/modY/com/example/multi/") | ||
| ], | ||
| expected_new_in_app_stack_trace_rules=["stack.module:com.example.** +app"], |
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.
This has one degree of granularity than with the new feature.
- stack.module:com.example.** +app
+ stack.module:com.example.multi.** +app| platform=self.platform, | ||
| expected_new_code_mappings=[ | ||
| self.code_mapping(f"{module_prefix}foo/", f"modules/modX/{module_prefix}foo/"), | ||
| self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"), |
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.
A code mapping per module rather than a single code mapping.
| self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"), | ||
| ], | ||
| expected_new_in_app_stack_trace_rules=[ | ||
| f"stack.module:{java_module_prefix}.** +app" |
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.
This has one granularity degree greater than the default behaviour. See previous test.
| return stack_root, file_path | ||
|
|
||
|
|
||
| def get_granularity(parts: Sequence[str]) -> int: |
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.
I believe this logic is correct, but I'm wondering if we can simplify it, e.g.:
num_segments = len(parts)
if num_segments == 1:
return 1
# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/foo/
# file_path: com/example/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL - 1
# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/foo/
# file_path: com/example/foo/bar/Baz.kt
if parts[1] in SECOND_LEVEL_TLDS:
granularity = STACK_ROOT_MAX_LEVEL
# com.example.multi.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/multi/foo/
# file_path: com/example/multi/foo/bar/Baz.kt
elif options.get("auto_source_code_config.multi_module_projects_allowlist"):
granularity = STACK_ROOT_MAX_LEVEL
return granularity
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.
That probably makes sense. I will handle it on my next PR.
7194ad3 to
4d7c7c1
Compare
|
bugbot run |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #101288 +/- ##
===========================================
+ Coverage 81.04% 81.08% +0.03%
===========================================
Files 8681 8683 +2
Lines 385115 385368 +253
Branches 24320 24320
===========================================
+ Hits 312132 312461 +329
+ Misses 72624 72548 -76
Partials 359 359 |
Remove option and old code path from #101288.
This makes the granularity of the stack root consistent rather than trying to optimize number of created code mappings. This also removes the option and old code path from #101288.
The work to derive code mappings for Java fell short of supporting multi module directory structure. This adds support for multi module directory structure behind a feature flag.
This makes the granularity of the stack root consistent rather than trying to optimize number of created code mappings. This also removes the option and old code path from #101288.

The work to derive code mappings for Java fell short of supporting multi module directory structure.
This adds support for multi module directory structure behind a feature flag.