Skip to content

Commit

Permalink
[COST-5658] Fix regression for removing report period (#5415)
Browse files Browse the repository at this point in the history
* Dropping old data from OCP Models based on report_period_id.

---------

Co-authored-by: Michael Skarbek <mskarbek@redhat.com>
  • Loading branch information
bacciotti and maskarb authored Dec 11, 2024
1 parent 993ae41 commit db0dd53
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions koku/masu/processor/ocp/ocp_report_db_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit db0dd53

Please sign in to comment.