diff --git a/koku/masu/processor/ocp/ocp_report_db_cleaner.py b/koku/masu/processor/ocp/ocp_report_db_cleaner.py index d1f04c90b3..14f92b63b7 100644 --- a/koku/masu/processor/ocp/ocp_report_db_cleaner.py +++ b/koku/masu/processor/ocp/ocp_report_db_cleaner.py @@ -14,6 +14,7 @@ from masu.database.ocp_report_db_accessor import OCPReportDBAccessor from reporting.models import EXPIRE_MANAGED_TABLES from reporting.models import PartitionedTable +from reporting.provider.ocp.models import OCPUsageReportPeriod from reporting.provider.ocp.models import UI_SUMMARY_TABLES LOG = logging.getLogger(__name__) @@ -95,8 +96,6 @@ def purge_expired_report_data_by_date(self, expired_date, simulate=False): partition_from = str(date(expired_date.year, expired_date.month, 1)) removed_items = [] all_report_periods = [] - all_cluster_ids = set() - all_period_starts = set() with OCPReportDBAccessor(self._schema) as accessor: all_usage_periods = accessor.get_report_periods_before_date(expired_date) @@ -115,18 +114,6 @@ def purge_expired_report_data_by_date(self, expired_date, simulate=False): {"usage_period_id": usage_period.id, "interval_start": str(usage_period.report_period_start)} ) all_report_periods.append(usage_period.id) - all_cluster_ids.add(usage_period.cluster_id) - all_period_starts.add(str(usage_period.report_period_start)) - - LOG.info( - log_json( - msg="removing all data related to cluster_ids", - report_periods=all_report_periods, - cluster_ids=all_cluster_ids, - period_starts=all_period_starts, - schema=self._schema, - ) - ) if not simulate: # Will call trigger to detach, truncate, and drop partitions @@ -147,6 +134,17 @@ def purge_expired_report_data_by_date(self, expired_date, simulate=False): ) LOG.info(log_json(msg="deleted table partitions", count=del_count, schema=self._schema)) + # Remove all data related to the report period + del_count, _ = OCPUsageReportPeriod.objects.filter(id__in=all_report_periods).delete() + LOG.info( + log_json( + msg="deleted ocp-usage-report-periods", + count=del_count, + report_periods=all_report_periods, + schema=self._schema, + ) + ) + return removed_items def purge_expired_trino_partitions(self, expired_date, simulate=False):