Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug Code #268

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/spaceone/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def delete_cost_with_datasource(self, domain_id: str, data_source_id: str) -> No
history_vos.delete()

def get_cost(
self,
cost_id: str,
domain_id: str,
workspace_id=None,
user_projects: list = None,
self,
cost_id: str,
domain_id: str,
workspace_id=None,
user_projects: list = None,
):
conditions = {"cost_id": cost_id, "domain_id": domain_id}

Expand Down Expand Up @@ -171,7 +171,7 @@ def analyze_yearly_costs(self, query, domain_id, target="SECONDARY_PREFERRED"):
expire=3600 * 24,
)
def stat_monthly_costs_with_cache(
self, query, query_hash, domain_id, data_source_id
self, query, query_hash, domain_id, data_source_id
):
return self.stat_monthly_costs(query, domain_id)

Expand All @@ -180,7 +180,7 @@ def stat_monthly_costs_with_cache(
expire=3600 * 24,
)
def analyze_costs_with_cache(
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
):
return self.analyze_costs(query, domain_id, target)

Expand All @@ -189,7 +189,7 @@ def analyze_costs_with_cache(
expire=3600 * 24,
)
def analyze_monthly_costs_with_cache(
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
):
return self.analyze_monthly_costs(query, domain_id, target)

Expand All @@ -198,12 +198,12 @@ def analyze_monthly_costs_with_cache(
expire=3600 * 24,
)
def analyze_yearly_costs_with_cache(
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
self, query, query_hash, domain_id, data_source_id, target="SECONDARY_PREFERRED"
):
return self.analyze_yearly_costs(query, domain_id, target)

def analyze_costs_by_granularity(
self, query: dict, domain_id: str, data_source_id: str
self, query: dict, domain_id: str, data_source_id: str
):
self._check_group_by(query)
self._check_date_range(query)
Expand Down Expand Up @@ -240,7 +240,7 @@ def analyze_costs_by_granularity(
expire=600,
)
def create_cost_query_history(
self, query: dict, query_hash: str, domain_id: str, data_source_id: str
self, query: dict, query_hash: str, domain_id: str, data_source_id: str
):
def _rollback(history_vo):
_LOGGER.info(
Expand Down Expand Up @@ -444,7 +444,7 @@ def _change_filter_project_group_id(self, query: dict, domain_id: str) -> dict:
return query

def change_filter_v_workspace_id(
self, query: dict, domain_id: str, data_source_id: str
self, query: dict, domain_id: str, data_source_id: str
) -> dict:
change_filter = []
workspace_ids = []
Expand Down Expand Up @@ -500,10 +500,9 @@ def change_filter_v_workspace_id(
return query

def _change_response_workspace_group_by(
self, response: dict, query: dict, domain_id: str, data_source_id: str
self, response: dict, query: dict, domain_id: str, data_source_id: str
) -> dict:
if query_group_by := query.get("group_by"):

if self._check_group_by_key(query_group_by):
results = response.get("results")
v_workspace_ids = [result.get("workspace_id") for result in results]
Expand Down Expand Up @@ -534,7 +533,7 @@ def _change_response_workspace_group_by(
return response

def _get_workspace_id_from_v_workspace_id(
self, domain_id: str, v_workspace_id: str
self, domain_id: str, v_workspace_id: str
) -> str:
workspace_id = v_workspace_id
ds_account_vos = self.data_source_account_mgr.filter_data_source_accounts(
Expand All @@ -548,7 +547,6 @@ def _get_workspace_id_from_v_workspace_id(
@staticmethod
def _check_group_by_key(query_group_by: list):
for group_by_info in query_group_by:

if isinstance(group_by_info, dict):
key = group_by_info.get("key")
else:
Expand Down
10 changes: 10 additions & 0 deletions src/spaceone/cost_analysis/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ def _aggregate_monthly_cost_data(

row_count = 0
for aggregated_cost_data in cursor:
_LOGGER.debug(
f"[_aggregate_monthly_cost_data] data: {aggregated_cost_data}"
)
_LOGGER.debug(
f"[_aggregate_monthly_cost_data] data type: {type(aggregated_cost_data)}"
)
aggregated_cost_data["data_source_id"] = data_source_id
aggregated_cost_data["billed_month"] = billed_month
aggregated_cost_data["job_id"] = job_id
Expand All @@ -894,6 +900,10 @@ def _aggregate_monthly_cost_data(
aggregated_cost_data["data"][data_key] = aggregated_cost_data.pop(
f"data_{data_key}", None
)

_LOGGER.debug(
f"[_aggregate_monthly_cost_data] input data: {aggregated_cost_data}"
)
self.cost_mgr.create_monthly_cost(aggregated_cost_data)
row_count += 1

Expand Down
Loading