Skip to content
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

Fix cleanup #613

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions cid/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,20 +723,27 @@ def delete_view(self, view_name):

@command
def cleanup(self, **kwargs):
"""Delete unused resources (QuickSight datasets, Athena views)"""
"""Delete unused resources (QuickSight datasets not used in Dashboards)"""

self.qs.discover_dashboards()
self.qs.discover_datasets()
used_datasets = [x for v in self.qs.dashboards.values() for x in v.datasets.values() ]
for v in list(self.qs._datasets.values()):
if v.arn not in used_datasets and click.confirm(f'Delete unused dataset {v.name}?'):
logger.info(f'Deleting dataset {v.name} ({v.arn})')
self.qs.delete_dataset(v.id)
logger.info(f'Deleted dataset {v.name} ({v.arn})')
print(f'Deleted dataset {v.name} ({v.arn})')
else:
print(f'Dataset {v.name} ({v.arn}) is in use')

references = {}
for dashboard in self.qs.dashboards.values():
for dataset_id in dashboard.datasets.values():
if dataset_id not in references:
references[dataset_id] = []
references[dataset_id].append(dashboard.id)
for dataset in self.qs._datasets.values():
if dataset.id in references:
cid_print(f'Dataset {dataset.name} ({dataset.id}) is in use ({", ".join(references[dataset.id])})')
continue
if get_yesno_parameter(f'confirm-delete-dataset-{dataset.id}',
message=f'Delete dataset "{dataset.name}" (not used in dashboards, but can be used in analysis)?',
default='no',
):
logger.info(f'Deleting dataset {dataset.name} ({dataset.id})')
self.qs.delete_dataset(dataset.id)
cid_print(f'Deleted dataset {dataset.name} ({dataset.id})')

@command
def share(self, dashboard_id, **kwargs):
Expand Down
Loading