From 665581d710992688d029d0b7f1db788e59b72cf2 Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Mon, 22 Jan 2024 11:39:46 +0900 Subject: [PATCH] feat: modify aggregated_cost_data for data_keys --- .../cost_analysis/service/job_service.py | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/spaceone/cost_analysis/service/job_service.py b/src/spaceone/cost_analysis/service/job_service.py index cf21bd41..dd66ee5d 100644 --- a/src/spaceone/cost_analysis/service/job_service.py +++ b/src/spaceone/cost_analysis/service/job_service.py @@ -253,7 +253,7 @@ def get_cost_data(self, params): is_canceled = False for costs_data in self.ds_plugin_mgr.get_cost_data( - options, secret_data, schema, task_options, domain_id + options, secret_data, schema, task_options, domain_id ): results = costs_data.get("results", []) for cost_data in results: @@ -414,11 +414,11 @@ def create_cost_job(self, data_source_vo: DataSource, job_options): return job_vo def _list_secret_ids_from_secret_type( - self, - data_source_vo: DataSource, - secret_type: str, - workspace_id: str, - domain_id: str, + self, + data_source_vo: DataSource, + secret_type: str, + workspace_id: str, + domain_id: str, ): secret_ids = [] @@ -439,7 +439,7 @@ def _list_secret_ids_from_secret_type( return secret_ids def _list_secret_ids_from_secret_filter( - self, secret_filter, provider: str, workspace_id: str, domain_id: str + self, secret_filter, provider: str, workspace_id: str, domain_id: str ): secret_manager: SecretManager = self.locator.get_manager(SecretManager) @@ -454,7 +454,7 @@ def _list_secret_ids_from_secret_filter( @staticmethod def _set_secret_filter( - secret_filter, provider: str, workspace_id: str, domain_id: str + secret_filter, provider: str, workspace_id: str, domain_id: str ): _filter = [{"k": "domain_id", "v": domain_id, "o": "eq"}] @@ -469,8 +469,8 @@ def _set_secret_filter( {"k": "secret_id", "v": secret_filter["secrets"], "o": "in"} ) if ( - "service_accounts" in secret_filter - and secret_filter["service_accounts"] + "service_accounts" in secret_filter + and secret_filter["service_accounts"] ): _filter.append( { @@ -566,10 +566,10 @@ def _create_cost_data(self, cost_data, job_task_vo, cost_options): self.cost_mgr.create_cost(cost_data, execute_rollback=False) def _is_job_failed( - self, - job_id: str, - domain_id: str, - workspace_id: str, + self, + job_id: str, + domain_id: str, + workspace_id: str, ): job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id) @@ -579,12 +579,12 @@ def _is_job_failed( return False def _close_job( - self, - job_id: str, - data_source_id: str, - domain_id: str, - data_keys: list, - workspace_id: str = None, + self, + job_id: str, + data_source_id: str, + domain_id: str, + data_keys: list, + workspace_id: str = None, ) -> None: job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id) no_preload_cache = job_vo.options.get("no_preload_cache", False) @@ -734,7 +734,7 @@ def _delete_old_cost_data(self, data_source_id, domain_id): monthly_cost_vos.delete() def _delete_changed_cost_data( - self, job_vo: Job, start, end, change_filter, domain_id + self, job_vo: Job, start, end, change_filter, domain_id ): query = { "filter": [ @@ -780,7 +780,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 + data_source_id, domain_id, job_id, job_task_id ): self._aggregate_monthly_cost_data( data_source_id, @@ -812,14 +812,14 @@ def _distinct_billed_month(self, data_source_id, domain_id, job_id, job_task_id) return values def _aggregate_monthly_cost_data( - self, - data_source_id, - domain_id, - job_id, - job_task_id, - billed_month, - data_keys: list, - workspace_id: str = None, + self, + data_source_id: str, + domain_id: str, + job_id: str, + job_task_id: str, + billed_month: str, + data_keys: list, + workspace_id: str = None, ): query = { "group_by": [ @@ -854,7 +854,7 @@ def _aggregate_monthly_cost_data( for data_key in data_keys: query["fields"].update( - {f"{data_key}": {"key": f"data.{data_key}", "operator": "sum"}} + {f"data_{data_key}": {"key": f"data.{data_key}", "operator": "sum"}} ) if workspace_id: @@ -872,7 +872,7 @@ def _aggregate_monthly_cost_data( for data_key in data_keys: aggregated_cost_data["data"][data_key] = aggregated_cost_data.pop( - data_key, None + f"data_{data_key}", None ) self.cost_mgr.create_monthly_cost(aggregated_cost_data) @@ -886,7 +886,7 @@ def _get_all_data_sources(self): ) def _check_duplicate_job( - self, data_source_id: str, domain_id: str, this_job_vo: Job + self, data_source_id: str, domain_id: str, this_job_vo: Job ): query = { "filter": [