-
-
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
ref(auto_source_config): Multiple calls does not create new repository #87437
Changes from 5 commits
2ea2a2d
bc6976e
17241af
4e86339
2cded45
c9208ca
a5410e3
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from collections.abc import MutableMapping | ||
from enum import StrEnum | ||
from typing import Any | ||
|
||
|
@@ -176,9 +177,8 @@ def create_repos_and_code_mappings( | |
raise InstallationNotFoundError | ||
|
||
organization_id = organization_integration.organization_id | ||
with metrics.timer( | ||
f"{METRIC_PREFIX}.create_configurations.duration", tags={"platform": platform} | ||
): | ||
tags: MutableMapping[str, str | bool] = {"platform": platform, "dry_run": dry_run} | ||
with metrics.timer(f"{METRIC_PREFIX}.create_configurations.duration", tags=tags): | ||
for code_mapping in code_mappings: | ||
repository = ( | ||
Repository.objects.filter( | ||
|
@@ -187,39 +187,22 @@ def create_repos_and_code_mappings( | |
.order_by("-date_added") | ||
.first() | ||
) | ||
|
||
if not repository: | ||
created = False | ||
if not dry_run: | ||
repository = Repository.objects.create( | ||
repository, created = Repository.objects.get_or_create( | ||
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. Notice I'm changing from |
||
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, | ||
) | ||
|
||
extra = { | ||
"project_id": project.id, | ||
"stack_root": code_mapping.stacktrace_root, | ||
"repository_name": code_mapping.repo.name, | ||
} | ||
# The project and stack_root are unique together | ||
existing_code_mappings = RepositoryProjectPathConfig.objects.filter( | ||
project=project, stack_root=code_mapping.stacktrace_root | ||
) | ||
if existing_code_mappings.exists(): | ||
logger.warning("Investigate.", extra=extra) | ||
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. Pass by change. This has not been happening in production, thus, removing it. |
||
continue | ||
if created or dry_run: | ||
metrics.incr( | ||
key=f"{METRIC_PREFIX}.repository.created", tags=tags, sample_rate=1.0 | ||
) | ||
|
||
created = False | ||
if not dry_run: | ||
if repository is None: # This is mostly to appease the type checker | ||
logger.warning("Investigate.", extra=extra) | ||
continue | ||
|
||
RepositoryProjectPathConfig.objects.create( | ||
_, created = RepositoryProjectPathConfig.objects.get_or_create( | ||
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. Changing from |
||
project=project, | ||
stack_root=code_mapping.stacktrace_root, | ||
repository=repository, | ||
|
@@ -230,9 +213,7 @@ def create_repos_and_code_mappings( | |
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, | ||
) | ||
if created or dry_run: | ||
metrics.incr( | ||
key=f"{METRIC_PREFIX}.code_mapping.created", tags=tags, sample_rate=1.0 | ||
) |
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'm refactoring some of the logic here to make sure the metrics are called correctly.