-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat(derived_code_mappings): Add metric for creating a repository and dry_run mode #86387
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
from sentry.utils import metrics | ||
from sentry.utils.locking import UnableToAcquireLock | ||
|
||
from .constants import METRIC_PREFIX | ||
from .integration_utils import ( | ||
InstallationCannotGetTreesError, | ||
InstallationNotFoundError, | ||
|
@@ -79,8 +80,7 @@ def process_event(project_id: int, group_id: int, event_id: str) -> list[CodeMap | |
trees = get_trees_for_org(installation, org, extra) | ||
trees_helper = CodeMappingTreesHelper(trees) | ||
code_mappings = trees_helper.generate_code_mappings(frames_to_process, platform) | ||
if not is_dry_run_platform(platform): | ||
set_project_codemappings(code_mappings, installation, project, platform) | ||
create_repos_and_code_mappings(code_mappings, installation, project, platform) | ||
except (InstallationNotFoundError, InstallationCannotGetTreesError): | ||
pass | ||
|
||
|
@@ -157,7 +157,7 @@ def get_trees_for_org( | |
return trees | ||
|
||
|
||
def set_project_codemappings( | ||
def create_repos_and_code_mappings( | ||
code_mappings: list[CodeMapping], | ||
installation: IntegrationInstallation, | ||
project: Project, | ||
|
@@ -167,6 +167,7 @@ def set_project_codemappings( | |
Given a list of code mappings, create a new repository project path | ||
config for each mapping. | ||
""" | ||
dry_run = is_dry_run_platform(platform) | ||
organization_integration = installation.org_integration | ||
if not organization_integration: | ||
raise InstallationNotFoundError | ||
|
@@ -180,25 +181,38 @@ def set_project_codemappings( | |
) | ||
|
||
if not repository: | ||
repository = Repository.objects.create( | ||
name=code_mapping.repo.name, | ||
organization_id=organization_id, | ||
integration_id=organization_integration.integration_id, | ||
if not dry_run: | ||
repository = Repository.objects.create( | ||
name=code_mapping.repo.name, | ||
organization_id=organization_id, | ||
integration_id=organization_integration.integration_id, | ||
) | ||
metrics.incr( | ||
key=f"{METRIC_PREFIX}.repository.created", | ||
tags={"platform": platform, "dry_run": dry_run}, | ||
sample_rate=1.0, | ||
) | ||
|
||
_, created = RepositoryProjectPathConfig.objects.get_or_create( | ||
project=project, | ||
stack_root=code_mapping.stacktrace_root, | ||
defaults={ | ||
"repository": repository, | ||
"organization_integration_id": organization_integration.id, | ||
"integration_id": organization_integration.integration_id, | ||
"organization_id": organization_integration.organization_id, | ||
"source_root": code_mapping.source_path, | ||
"default_branch": code_mapping.repo.branch, | ||
"automatically_generated": True, | ||
}, | ||
) | ||
if created: | ||
# Since it is a low volume event, we can sample at 100% | ||
metrics.incr(key="code_mappings.created", tags={"platform": platform}, sample_rate=1.0) | ||
# The project and stack_root are unique together | ||
configs = RepositoryProjectPathConfig.objects.filter( | ||
project=project, stack_root=code_mapping.stacktrace_root | ||
).all() | ||
if not configs: | ||
armenzg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not dry_run and repository is not None: | ||
RepositoryProjectPathConfig.objects.create( | ||
repository=repository, | ||
project=project, | ||
organization_integration_id=organization_integration.id, | ||
organization_id=organization_integration.organization_id, | ||
integration_id=organization_integration.integration_id, | ||
stack_root=code_mapping.stacktrace_root, | ||
source_root=code_mapping.source_path, | ||
default_branch=code_mapping.repo.branch, | ||
automatically_generated=True, | ||
) | ||
|
||
metrics.incr( | ||
key=f"{METRIC_PREFIX}.code_mapping.created", | ||
tags={"platform": platform, "dry_run": dry_run}, | ||
sample_rate=1.0, | ||
) | ||
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. Shouldn't this be under the 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. UPDATE: Okay, I know you changed the logic around, but I'm still not sure I understand it. Shouldn't the
The first one works with the code above, but for the second one, don't we have to make sure the record doesn't yet exist before saying that |
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.
To match the code.