Skip to content

Commit

Permalink
Merge pull request #150 from ImMin5/master
Browse files Browse the repository at this point in the history
Modify aggregated_cost_data for data_keys
  • Loading branch information
ImMin5 authored Jan 22, 2024
2 parents c18a482 + 665581d commit 3ea2417
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []

Expand All @@ -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)

Expand All @@ -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"}]

Expand All @@ -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(
{
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand All @@ -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": [
Expand Down

0 comments on commit 3ea2417

Please sign in to comment.