Skip to content

Commit 3f25ca5

Browse files
authored
Group migration: additional logging (#2239)
## Changes This PR contains logging improvements in the group manager to help understand (potential) causes of problems during group migration. ### Linked issues Relates #2227. ### Functionality - modified existing workflow: `group-migration`
1 parent 643bac6 commit 3f25ca5

File tree

1 file changed

+32
-9
lines changed
  • src/databricks/labs/ucx/workspace_access

1 file changed

+32
-9
lines changed

src/databricks/labs/ucx/workspace_access/groups.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def rename_groups(self):
432432
workspace_groups_in_workspace = self._workspace_groups_in_workspace()
433433
groups_to_migrate = self.get_migration_state().groups
434434

435+
logger.info(f"Starting to rename {len(groups_to_migrate)} groups for migration...")
435436
for migrated_group in groups_to_migrate:
436437
if migrated_group.name_in_account in account_groups_in_workspace:
437438
logger.info(f"Skipping {migrated_group.name_in_account}: already in workspace")
@@ -472,13 +473,15 @@ def _rename_group(self, group_id: str, new_group_name: str) -> None:
472473
def _wait_for_rename(self, group_id: str, old_group_name: str, new_group_name: str) -> None:
473474
group = self._ws.groups.get(group_id)
474475
if group.display_name == old_group_name:
475-
# Rename still pending.
476+
logger.debug(
477+
f"Group {group_id} still has old name; still waiting for rename to take effect: {old_group_name} -> {new_group_name}"
478+
)
476479
raise GroupRenameIncompleteError(group_id, old_group_name, new_group_name)
477480
if group.display_name != new_group_name:
478481
# Group has an entirely unexpected name; something else is interfering.
479-
msg = f"While waiting for group {group_id} rename ({old_group_name} -> {new_group_name} an unexpected name was observed: {group.display_name}"
482+
msg = f"While waiting for group {group_id} rename ({old_group_name} -> {new_group_name}) an unexpected name was observed: {group.display_name}"
480483
raise RuntimeError(msg)
481-
# Normal exit; group has been renamed.
484+
logger.debug(f"Group {group_id} rename has taken effect: {old_group_name} -> {new_group_name}")
482485

483486
@retried(on=[ManyError], timeout=timedelta(minutes=2))
484487
def _wait_for_renamed_groups(self, expected_groups: Collection[tuple[str, str]]) -> None:
@@ -492,9 +495,15 @@ def _wait_for_renamed_groups(self, expected_groups: Collection[tuple[str, str]])
492495
for group_id, expected_name in expected_groups:
493496
found_name = found_groups.get(group_id, None)
494497
if found_name is None:
495-
pending_renames.append(RuntimeError(f"Missing group with id: {group_id} (renamed to {expected_name}"))
498+
logger.warning(f"Group enumeration omits renamed group: {group_id} (renamed to {expected_name})")
499+
pending_renames.append(RuntimeError(f"Missing group with id: {group_id} (renamed to {expected_name})"))
496500
elif found_name != expected_name:
501+
logger.debug(
502+
f"Group enumeration does not yet reflect rename: {group_id} (renamed to {expected_name} but currently {found_name})"
503+
)
497504
pending_renames.append(GroupRenameIncompleteError(group_id, found_name, expected_name))
505+
else:
506+
logger.debug(f"Group enumeration reflects renamed group: {group_id} (renamed to {expected_name})")
498507
if pending_renames:
499508
raise ManyError(pending_renames)
500509

@@ -503,6 +512,7 @@ def reflect_account_groups_on_workspace(self):
503512
account_groups_in_account = self._account_groups_in_account()
504513
account_groups_in_workspace = self._account_groups_in_workspace()
505514
groups_to_migrate = self.get_migration_state().groups
515+
logger.info(f"Starting to reflect {len(groups_to_migrate)} account groups into workspace for migration...")
506516
for migrated_group in groups_to_migrate:
507517
if migrated_group.name_in_account in account_groups_in_workspace:
508518
logger.info(f"Skipping {migrated_group.name_in_account}: already in workspace")
@@ -523,7 +533,9 @@ def delete_original_workspace_groups(self):
523533
tasks = []
524534
workspace_groups_in_workspace = self._workspace_groups_in_workspace()
525535
account_groups_in_workspace = self._account_groups_in_workspace()
526-
for migrated_group in self.snapshot():
536+
migrated_groups = self.snapshot()
537+
logger.info(f"Starting to remove {len(migrated_groups)} migrated workspace groups...")
538+
for migrated_group in migrated_groups:
527539
if migrated_group.temporary_name not in workspace_groups_in_workspace:
528540
logger.info(f"Skipping {migrated_group.name_in_workspace}: no longer in workspace")
529541
continue
@@ -570,19 +582,25 @@ def validate_group_membership(self) -> list[dict]:
570582
workspace_groups_in_workspace = self._workspace_groups_in_workspace()
571583
account_groups_in_account = self._account_groups_in_account()
572584
strategy = self._get_strategy(workspace_groups_in_workspace, account_groups_in_account)
573-
migrated_groups = strategy.generate_migrated_groups()
585+
migrated_groups = list(strategy.generate_migrated_groups())
574586
mismatch_group = []
575587
retry_on_internal_error = retried(on=[InternalError], timeout=self._verify_timeout)
576588
get_account_group = retry_on_internal_error(self._get_account_group)
589+
logger.info(f"Starting to validate {len(migrated_groups)} migrated workspace groups...")
577590
for ws_group in migrated_groups:
578591
# Users with the same display name but different email will be deduplicated!
579592
ws_members_set = {m.get("display") for m in json.loads(ws_group.members)} if ws_group.members else set()
580-
acc_group = get_account_group(account_groups_in_account[ws_group.name_in_account].id)
593+
acc_group_id = account_groups_in_account[ws_group.name_in_account].id
594+
acc_group = get_account_group(acc_group_id)
581595
if not acc_group:
596+
logger.debug(
597+
f"Skipping validation; account group no longer present: {ws_group.name_in_account} (id={acc_group_id})"
598+
)
582599
continue # group not present anymore
583600
acc_members_set = {a.as_dict().get("display") for a in acc_group.members} if acc_group.members else set()
584601
set_diff = (ws_members_set - acc_members_set).union(acc_members_set - ws_members_set)
585602
if not set_diff:
603+
logger.debug(f"Validated group, no differences found: {ws_group.name_in_account} (id={acc_group_id})")
586604
continue
587605
mismatch_group.append(
588606
{
@@ -594,9 +612,11 @@ def validate_group_membership(self) -> list[dict]:
594612
}
595613
)
596614
if not mismatch_group:
597-
logger.info("There are no groups with different membership between account and workspace")
615+
logger.info("There are no groups with different membership between account and workspace.")
598616
else:
599-
logger.info("There are groups with different membership between account and workspace")
617+
logger.info(
618+
f"There are {len(mismatch_group)} (of {len(migrated_groups)}) groups with different membership between account and workspace."
619+
)
600620
return mismatch_group
601621

602622
def has_workspace_group(self, name):
@@ -612,6 +632,7 @@ def _workspace_groups_in_workspace(self) -> dict[str, Group]:
612632
groups = {}
613633
for group in self._list_workspace_groups("WorkspaceGroup", attributes):
614634
if not group.display_name:
635+
logger.debug(f"Ignoring workspace group without name: {group.id}")
615636
continue
616637
groups[group.display_name] = group
617638
return groups
@@ -620,6 +641,7 @@ def _account_groups_in_workspace(self) -> dict[str, Group]:
620641
groups = {}
621642
for group in self._list_workspace_groups("Group", "id,displayName,externalId,meta"):
622643
if not group.display_name:
644+
logger.debug(f"Ignoring account group in workspace without name: {group.id}")
623645
continue
624646
groups[group.display_name] = group
625647
return groups
@@ -628,6 +650,7 @@ def _account_groups_in_account(self) -> dict[str, Group]:
628650
groups = {}
629651
for group in self._list_account_groups("id,displayName,externalId"):
630652
if not group.display_name:
653+
logger.debug(f"Ignoring account group in without name: {group.id}")
631654
continue
632655
groups[group.display_name] = group
633656
return groups

0 commit comments

Comments
 (0)