Skip to content

Commit

Permalink
[fix] Descendant Summary Account Usage (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Oct 14, 2024
1 parent e5f33ac commit 846a1ca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fixbackend/inventory/inventory_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,12 +946,12 @@ def get_account_usage(account_id: str, cloud_id: str) -> AccountRegionSummary:
if kinds:
summary = {k: v.for_kinds(kinds) for k, v in summary.items()}

account_usage: Dict[str, int] = defaultdict(int)
account_usage: Dict[str, Dict[str, int]] = defaultdict(lambda: defaultdict(int))
region_usage: Dict[str, Dict[str, int]] = defaultdict(lambda: defaultdict(int))
account_region_usage: Dict[str, Set[str]] = defaultdict(set)
for account in summary.values():
for kind, count in account.count.items():
account_usage[kind] += count
account_usage[kind][account.account_id] += count
for region, region_kinds in account.regions.items():
for kind, count in region_kinds.items():
account_region_usage[kind].add(account.account_id)
Expand All @@ -964,11 +964,11 @@ def get_account_usage(account_id: str, cloud_id: str) -> AccountRegionSummary:
kd.regions = len(regions)
kd.resources = sum(regions.values())
else:
for kind, count in account_usage.items():
for kind, accounts in account_usage.items():
kd = kind_usage[kind]
kd.accounts += 1
kd.accounts = len(account_usage[kind])
kd.regions = len(region_usage[kind])
kd.resources += count
kd.resources = sum(accounts.values())

for kind, regions in region_usage.items():
kind_usage[kind].regions = len(regions)
Expand Down

0 comments on commit 846a1ca

Please sign in to comment.