Skip to content

Commit

Permalink
feat: add data_source_id parameter for cost stat
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMin5 committed Apr 30, 2024
1 parent 11d5130 commit 52754e9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ def _delete_old_cost_data(self, data_source_id, domain_id):
]
}

cost_vos, total_count = self.cost_mgr.list_costs(cost_delete_query, domain_id)
cost_vos, total_count = self.cost_mgr.list_costs(
cost_delete_query, domain_id, data_source_id
)
_LOGGER.debug(f"[_delete_old_cost_data] delete costs (count = {total_count})")
cost_vos.delete()

Expand Down Expand Up @@ -774,7 +776,7 @@ def _delete_changed_cost_data(
_LOGGER.debug(f"[_delete_changed_cost_data] query: {query}")

cost_vos, total_count = self.cost_mgr.list_costs(
copy.deepcopy(query), domain_id
copy.deepcopy(query), domain_id, job_vo.data_source_id
)
cost_vos.delete()
_LOGGER.debug(
Expand All @@ -800,7 +802,7 @@ def _aggregate_cost_data(self, job_vo: Job, data_keys: list):

for job_task_id in job_task_ids:
for billed_month in self._distinct_billed_month(
data_source_id, domain_id, job_id, job_task_id
domain_id, data_source_id, job_id, job_task_id
):
self._aggregate_monthly_cost_data(
data_source_id,
Expand All @@ -812,7 +814,9 @@ def _aggregate_cost_data(self, job_vo: Job, data_keys: list):
workspace_id,
)

def _distinct_billed_month(self, data_source_id, domain_id, job_id, job_task_id):
def _distinct_billed_month(
self, domain_id: str, data_source_id: str, job_id: str, job_task_id: str
):
query = {
"distinct": "billed_month",
"filter": [
Expand All @@ -824,7 +828,7 @@ def _distinct_billed_month(self, data_source_id, domain_id, job_id, job_task_id)
"target": "PRIMARY", # Execute a query to primary DB
}
_LOGGER.debug(f"[_distinct_cost_data] query: {query}")
response = self.cost_mgr.stat_costs(query, domain_id)
response = self.cost_mgr.stat_costs(query, domain_id, data_source_id)
values = response.get("results", [])

_LOGGER.debug(f"[_distinct_cost_data] billed_month: {values}")
Expand Down

0 comments on commit 52754e9

Please sign in to comment.