-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(ecosystem): refactor link_all_repos to bulk update repositories #95494
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
Changes from all commits
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,4 +1,5 @@ | ||
import logging | ||
from typing import Any | ||
|
||
from sentry.constants import ObjectStatus | ||
from sentry.integrations.services.integration import integration_service | ||
|
@@ -18,7 +19,6 @@ | |
from sentry.taskworker.config import TaskworkerConfig | ||
from sentry.taskworker.namespaces import integrations_control_tasks | ||
from sentry.taskworker.retry import Retry | ||
from sentry.utils import metrics | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -58,27 +58,11 @@ def link_all_repos( | |
integration_id=integration_id, status=ObjectStatus.ACTIVE | ||
) | ||
if not integration: | ||
# TODO: Remove this logger in favor of context manager | ||
logger.error( | ||
"%s.link_all_repos.integration_missing", | ||
integration_key, | ||
extra={"organization_id": organization_id}, | ||
) | ||
metrics.incr("github.link_all_repos.error", tags={"type": "missing_integration"}) | ||
lifecycle.record_failure(str(LinkAllReposHaltReason.MISSING_INTEGRATION)) | ||
return | ||
|
||
rpc_org = organization_service.get(id=organization_id) | ||
if rpc_org is None: | ||
logger.error( | ||
"%s.link_all_repos.organization_missing", | ||
integration_key, | ||
extra={"organization_id": organization_id}, | ||
) | ||
metrics.incr( | ||
f"{integration_key}.link_all_repos.error", | ||
tags={"type": "missing_organization"}, | ||
) | ||
lifecycle.record_failure(str(LinkAllReposHaltReason.MISSING_ORGANIZATION)) | ||
return | ||
|
||
|
@@ -93,26 +77,31 @@ def link_all_repos( | |
lifecycle.record_halt(str(LinkAllReposHaltReason.RATE_LIMITED)) | ||
return | ||
|
||
metrics.incr(f"{integration_key}.link_all_repos.api_error") | ||
raise | ||
|
||
integration_repo_provider = get_integration_repository_provider(integration) | ||
|
||
# If we successfully create any repositories, we'll set this to True | ||
success = False | ||
|
||
repo_configs: list[dict[str, Any]] = [] | ||
missing_repos = [] | ||
for repo in repositories: | ||
try: | ||
config = get_repo_config(repo, integration_id) | ||
integration_repo_provider.create_repository( | ||
repo_config=config, organization=rpc_org | ||
) | ||
success = True | ||
repo_configs.append(get_repo_config(repo, integration_id)) | ||
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. 👏🏼 Much cleaner |
||
except KeyError: | ||
continue | ||
except RepoExistsError: | ||
metrics.incr("sentry.integration_repo_provider.repo_exists") | ||
missing_repos.append(repo) | ||
continue | ||
|
||
if not success: | ||
lifecycle.record_halt(str(LinkAllReposHaltReason.REPOSITORY_NOT_CREATED)) | ||
try: | ||
integration_repo_provider.create_repositories( | ||
configs=repo_configs, organization=rpc_org | ||
) | ||
except RepoExistsError as e: | ||
lifecycle.record_halt( | ||
str(LinkAllReposHaltReason.REPOSITORY_NOT_CREATED), | ||
{"missing_repos": e.repos, "integration_id": integration_id}, | ||
) | ||
|
||
if missing_repos: | ||
lifecycle.record_halt( | ||
str(LinkAllReposHaltReason.REPOSITORY_NOT_CREATED), | ||
{"missing_repos": missing_repos, "integration_id": integration_id}, | ||
) | ||
Comment on lines
+104
to
+107
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. Are there any other partial failures cases we need to worry about? What does 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. The only case is where some fail and some succeed. Previously we would actually mark it as success if any repo was created, but here we only mark it as success if ALL repos are created/updated successfully. If repo creation fails, we now raise an exception with the failed repos and mark it as a halt |
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.
Are there any dashboards we need to update that use this?
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 not aware of any monitoring we have on this, plus we should be using the lifecycle metrics anyway