-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(derived_code_mappings): Make code clearer #86597
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
This also prepares the code for further changes.
| trees = get_trees_for_org(installation, org, extra) | ||
| trees_helper = CodeMappingTreesHelper(trees) | ||
| code_mappings = trees_helper.generate_code_mappings(frames_to_process, platform) | ||
| create_repos_and_code_mappings(code_mappings, installation, project, platform) |
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.
We're also going to be creating in_app stack trace rules, thus, renaming in advance.
|
|
||
| organization_id = organization_integration.organization_id | ||
| for code_mapping in code_mappings: | ||
| repository = ( |
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.
Moving all of the logic from this loop to process_code_mapping. It will make create_configurations shorter and easier to read.
|
|
||
| if not repository: | ||
| if not dry_run: | ||
| if repository is None: # This is mostly to appease the type checker |
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.
| .first() | ||
| ) | ||
|
|
||
| if not repository: |
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.
Should we add some negative metrics here if, say, the code mapping creation fails or one already exists? It might be helpful to understand how often each failure mode is occurring.
Some of those metrics might also belong inside the tree_helpers.generate_code_mappings function
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.
Hi @MichaelSun48, good point.
I have reworked the code to handle this correctly. There's no need for a metric.
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.
Sorry if I'm misunderstanding or missing something, but why do we not need a metric? There are definitely cases where we do not create a code mapping because one already exists, right?
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 only time we get to not repository is when we use dry_run=True. It's not possible otherwise.
| def create_code_mapping( | ||
| code_mapping: CodeMapping, | ||
| project: Project, | ||
| repository: Repository | 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.
@MichaelSun48 I'm changing this is to Repository | None.
| organization_integration: RpcOrganizationIntegration, | ||
| dry_run: bool, | ||
| ) -> None: | ||
| if not dry_run and repository: |
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 also changed this.
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #86597 +/- ##
=========================================
Coverage ? 87.79%
=========================================
Files ? 9772
Lines ? 553439
Branches ? 21639
=========================================
Hits ? 485877
Misses ? 67191
Partials ? 371 |
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
|
PR reverted: f2d672c |
This reverts commit cc85c73. Co-authored-by: armenzg <[email protected]>
…ories In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/explore/discover/results/?dataset=errors&end=2025-03-12T03%3A59%3A59.000&field=issue&field=count%28%29&interval=2h&name=IntegrityError%3A%20UniqueViolation%28%27duplicate%20key%20value%20violates%20unique%20constraint%20%22sentry_repositoryproject_project_id_stack_root_e376b891_uniq%22%5CnDETAIL%3A%20%20Key%20%28project_id%2C%20stack_root%29%3D%284507969920565328%2C%20kamino_platform%2F%29%20already%20exists.%5Cn%27%29&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&queryDataset=error-events&sort=-count&start=2025-03-09T05%3A00%3A00.000&yAxis=count%28%29&yAxis=count_unique%28user%29) because we called `create` when the repository already existed. This change is to have a test to prevent trying to create the repository more than once.
…ories In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/issues/?environment=prod&groupStatsPeriod=auto&page=0&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&referrer=issue-list&statsPeriod=90d) because we called `create` when the code mapping already existed. This change is to have a test to prevent trying to create the repository or code mappings more than once.
In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/issues/?environment=prod&groupStatsPeriod=auto&page=0&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&referrer=issue-list&statsPeriod=90d) because we called `create` when the code mapping already existed. This change is to have a test to prevent trying to create the repository or code mappings more than once.
… repositories (#87498) This change adds testing the creation of code mappings based on data from different repositories to prevent future regressions (In #86597 I refactored the code and introduced a regression). This change will not prevent the regression but it will make the follow-up PR to fix it.
#87437) This depends on #87498 merging first. In #86597 I introduced a bug causing many [IntegrityErrors](https://sentry.sentry.io/explore/discover/results/?dataset=errors&end=2025-03-12T03%3A59%3A59.000&field=issue&field=count%28%29&interval=2h&name=IntegrityError%3A%20UniqueViolation%28%27duplicate%20key%20value%20violates%20unique%20constraint%20%22sentry_repositoryproject_project_id_stack_root_e376b891_uniq%22%5CnDETAIL%3A%20%20Key%20%28project_id%2C%20stack_root%29%3D%284507969920565328%2C%20kamino_platform%2F%29%20already%20exists.%5Cn%27%29&project=1&query=error.type%3AIntegrityError%20transaction%3Asentry.tasks.auto_source_code_config&queryDataset=error-events&sort=-count&start=2025-03-09T05%3A00%3A00.000&yAxis=count%28%29&yAxis=count_unique%28user%29) because we called `create` when the repository already existed. This change is to have a test to prevent trying to create the repository more than once.

This also prepares the code for further changes.