Skip to content

Commit

Permalink
switch from cluster id to report bill id
Browse files Browse the repository at this point in the history
  • Loading branch information
lcouzens committed Aug 17, 2024
1 parent 88a972f commit 145281c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions koku/masu/database/aws_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ def back_populate_ocp_infrastructure_costs(self, start_date, end_date, report_pe
}
self._prepare_and_execute_raw_sql_query(table_name, sql, sql_params)

def populate_ocp_on_aws_tag_information(self, bill_ids, start_date, end_date, cluster_id):
def populate_ocp_on_aws_tag_information(self, bill_ids, start_date, end_date, current_ocp_report_period_id):
"""Populate the line item aggregated totals data table."""
sql_params = {
"schema": self.schema,
"bill_ids": bill_ids,
"start_date": start_date,
"end_date": end_date,
"cluster_id": cluster_id,
"report_period_id": current_ocp_report_period_id,
}
# Tag Summary
sql = pkgutil.get_data("masu.database", "sql/reporting_ocpawstags_summary.sql")
Expand Down
4 changes: 2 additions & 2 deletions koku/masu/database/azure_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def get_bill_query_before_date(self, date):
"""Get the cost entry bill objects with billing period before provided date."""
return AzureCostEntryBill.objects.filter(billing_period_start__lte=date)

def populate_ocp_on_azure_tag_information(self, bill_ids, start_date, end_date, cluster_id):
def populate_ocp_on_azure_tag_information(self, bill_ids, start_date, end_date, report_period_id):
"""Populate the line item aggregated totals data table."""
sql_params = {
"schema": self.schema,
"bill_ids": bill_ids,
"start_date": start_date,
"end_date": end_date,
"cluster_id": cluster_id,
"report_period_id": report_period_id,
}
# Tag summary
sql = pkgutil.get_data("masu.database", "sql/reporting_ocpazuretags_summary.sql")
Expand Down
4 changes: 2 additions & 2 deletions koku/masu/database/gcp_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,14 @@ def get_openshift_on_cloud_matched_tags_trino(
)
return [json.loads(result[0]) for result in results]

def populate_ocp_on_gcp_tag_information(self, gcp_bill_ids, start_date, end_date, cluster_id):
def populate_ocp_on_gcp_tag_information(self, gcp_bill_ids, start_date, end_date, report_period_id):
"""Populate the line item aggregated totals data table."""
sql_params = {
"schema": self.schema,
"gcp_bill_ids": gcp_bill_ids,
"start_date": start_date,
"end_date": end_date,
"cluster_id": cluster_id,
"report_period_id": report_period_id,
}
# Tag Summary
sql = pkgutil.get_data("masu.database", "sql/gcp/openshift/reporting_ocpgcptags_summary.sql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WITH cte_tag_value AS (
jsonb_each_text(li.tags) labels
WHERE li.usage_start >= {{start_date}}
AND li.usage_start <= {{end_date}}
AND li.cluster_id = {{cluster_id}}
AND li.report_period_id = {{report_period_id}}
AND value IS NOT NULL
AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type = 'GCP')
{% if bill_ids %}
Expand Down
2 changes: 1 addition & 1 deletion koku/masu/database/sql/reporting_ocpawstags_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WITH cte_tag_value AS (
jsonb_each_text(li.tags) labels
WHERE li.usage_start >= {{start_date}}
AND li.usage_start <= {{end_date}}
AND li.cluster_id = {{cluster_id}}
AND li.report_period_id = {{report_period_id}}
AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type='AWS')
{% if bill_ids %}
AND li.cost_entry_bill_id IN {{ bill_ids | inclause }}
Expand Down
2 changes: 1 addition & 1 deletion koku/masu/database/sql/reporting_ocpazuretags_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WITH cte_tag_value AS (
jsonb_each_text(li.tags) labels
WHERE li.usage_start >= {{start_date}}
AND li.usage_start <= {{end_date}}
AND li.cluster_id = {{cluster_id}}
AND li.report_period_id = {{report_period_id}}
AND li.tags ?| (SELECT array_agg(DISTINCT key) FROM {{schema | sqlsafe}}.reporting_enabledtagkeys WHERE enabled=true AND provider_type='Azure')
{% if bill_ids %}
AND li.cost_entry_bill_id IN {{ bill_ids | inclause }}
Expand Down
8 changes: 5 additions & 3 deletions koku/masu/processor/ocp/ocp_cloud_parquet_summary_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def update_aws_summary_tables(self, openshift_provider_uuid, aws_provider_uuid,
sql_params["start_date"] = start
sql_params["end_date"] = end
accessor.back_populate_ocp_infrastructure_costs(start, end, current_ocp_report_period_id)
accessor.populate_ocp_on_aws_tag_information(aws_bill_ids, start, end, cluster_id)
accessor.populate_ocp_on_aws_tag_information(aws_bill_ids, start, end, current_ocp_report_period_id)
accessor.populate_ocp_on_aws_ui_summary_tables_trino(
start, end, openshift_provider_uuid, aws_provider_uuid
)
Expand Down Expand Up @@ -434,7 +434,9 @@ def update_azure_summary_tables(self, openshift_provider_uuid, azure_provider_uu
sql_params["start_date"] = start
sql_params["end_date"] = end
accessor.back_populate_ocp_infrastructure_costs(start, end, current_ocp_report_period_id)
accessor.populate_ocp_on_azure_tag_information(azure_bill_ids, start, end, cluster_id)
accessor.populate_ocp_on_azure_tag_information(
azure_bill_ids, start, end, current_ocp_report_period_id
)
accessor.populate_ocp_on_azure_ui_summary_tables_trino(
start, end, openshift_provider_uuid, azure_provider_uuid
)
Expand Down Expand Up @@ -555,7 +557,7 @@ def update_gcp_summary_tables(self, openshift_provider_uuid, gcp_provider_uuid,
accessor.populate_ocp_on_gcp_ui_summary_tables_trino(
start, end, openshift_provider_uuid, gcp_provider_uuid
)
accessor.populate_ocp_on_gcp_tag_information(gcp_bill_ids, start, end, cluster_id)
accessor.populate_ocp_on_gcp_tag_information(gcp_bill_ids, start, end, current_ocp_report_period_id)

with OCPReportDBAccessor(self._schema) as ocp_accessor:
sql_params["source_type"] = "GCP"
Expand Down
3 changes: 2 additions & 1 deletion koku/masu/test/database/test_aws_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def test_populate_ocp_on_aws_tag_information(self, mock_unleash):
"""
mock_unleash.return_value = True
populated_keys = []
report_period_id = 1
with schema_context(self.schema):
enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_AWS, enabled=True)
for enabled_tag in enabled_tags:
Expand All @@ -447,7 +448,7 @@ def test_populate_ocp_on_aws_tag_information(self, mock_unleash):
child_key, child_obj, child_count = populated_keys[1]
TagMapping.objects.create(parent=parent_obj, child=child_obj)
self.accessor.populate_ocp_on_aws_tag_information(
bill_ids, self.dh.this_month_start, self.dh.today, self.cluster_id
bill_ids, self.dh.this_month_start, self.dh.today, report_period_id
)
expected_parent_count = parent_count + child_count
actual_parent_count = OCPAWSCostLineItemProjectDailySummaryP.objects.filter(
Expand Down
3 changes: 2 additions & 1 deletion koku/masu/test/database/test_azure_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def test_populate_ocp_on_aZURE_tag_information(self, mock_unleash):
"""
mock_unleash.return_value = True
populated_keys = []
report_period_id = 1
with schema_context(self.schema):
enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_AZURE, enabled=True)
for enabled_tag in enabled_tags:
Expand All @@ -370,7 +371,7 @@ def test_populate_ocp_on_aZURE_tag_information(self, mock_unleash):
child_key, child_obj, child_count = populated_keys[1]
TagMapping.objects.create(parent=parent_obj, child=child_obj)
self.accessor.populate_ocp_on_azure_tag_information(
bill_ids, self.dh.this_month_start, self.dh.today, self.ocp_cluster_id
bill_ids, self.dh.this_month_start, self.dh.today, report_period_id
)
expected_parent_count = parent_count + child_count
actual_parent_count = OCPAzureCostLineItemProjectDailySummaryP.objects.filter(
Expand Down
6 changes: 4 additions & 2 deletions koku/masu/test/database/test_gcp_report_db_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,12 @@ def test_populate_ocp_gcp_ui_summary_tables(self, mock_sql):
@patch("masu.database.gcp_report_db_accessor.GCPReportDBAccessor._execute_raw_sql_query")
def test_populate_ocp_on_gcp_tag_information_assert_call(self, mock_trino):
"""Test that we construst our SQL and execute our query."""
report_period_id = 1
start_date = self.dh.this_month_start.date()
end_date = self.dh.this_month_end.date()

mock_gcp_bills = [Mock(), Mock()]
self.accessor.populate_ocp_on_gcp_tag_information(mock_gcp_bills, start_date, end_date, self.ocp_cluster_id)
self.accessor.populate_ocp_on_gcp_tag_information(mock_gcp_bills, start_date, end_date, report_period_id)
mock_trino.assert_called()

@patch("masu.database.gcp_report_db_accessor.GCPReportDBAccessor.schema_exists_trino")
Expand Down Expand Up @@ -493,6 +494,7 @@ def test_populate_ocp_on_gcp_tag_information(self, mock_unleash):
"""
mock_unleash.return_value = True
populated_keys = []
report_period_id = 1
with schema_context(self.schema):
enabled_tags = EnabledTagKeys.objects.filter(provider_type=Provider.PROVIDER_GCP, enabled=True)
for enabled_tag in enabled_tags:
Expand All @@ -515,7 +517,7 @@ def test_populate_ocp_on_gcp_tag_information(self, mock_unleash):
child_key, child_obj, child_count = populated_keys[1]
TagMapping.objects.create(parent=parent_obj, child=child_obj)
self.accessor.populate_ocp_on_gcp_tag_information(
bill_ids, self.dh.this_month_start, self.dh.today, self.ocp_cluster_id
bill_ids, self.dh.this_month_start, self.dh.today, report_period_id
)
expected_parent_count = parent_count + child_count
actual_parent_count = OCPGCPCostLineItemProjectDailySummaryP.objects.filter(
Expand Down

0 comments on commit 145281c

Please sign in to comment.