From c5cd283a849f87d4740078134eb80deb164791f8 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Mon, 29 Apr 2024 10:19:11 +0900 Subject: [PATCH] fix: fix query bug --- src/setup.py | 11 +++++++++- .../cost_analysis/manager/cost_manager.py | 21 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/setup.py b/src/setup.py index 03fbd853..c8784f6a 100644 --- a/src/setup.py +++ b/src/setup.py @@ -26,7 +26,16 @@ author_email="admin@spaceone.dev", license="Apache License 2.0", packages=find_packages(), - install_requires=["spaceone-core", "spaceone-api", "pandas", "numpy"], + install_requires=[ + "spaceone-core", + "spaceone-api", + "pandas", + "numpy", + "jinja2", + "finance-datareader", + "plotly", + "bs4", + ], package_data={ "spaceone": [ "cost_analysis/template/*.html", diff --git a/src/spaceone/cost_analysis/manager/cost_manager.py b/src/spaceone/cost_analysis/manager/cost_manager.py index fc5339e3..51a450e9 100644 --- a/src/spaceone/cost_analysis/manager/cost_manager.py +++ b/src/spaceone/cost_analysis/manager/cost_manager.py @@ -14,6 +14,7 @@ DataSourceAccountManager, ) from spaceone.cost_analysis.manager.identity_manager import IdentityManager +from spaceone.cost_analysis.manager.data_source_manager import DataSourceManager _LOGGER = logging.getLogger(__name__) @@ -32,6 +33,9 @@ def __init__(self, *args, **kwargs): self.data_source_account_mgr: DataSourceAccountManager = ( self.locator.get_manager("DataSourceAccountManager") ) + self.data_source_mgr: DataSourceManager = self.locator.get_manager( + "DataSourceManager" + ) def create_cost(self, params: dict, execute_rollback=True): def _rollback(vo: Cost): @@ -108,12 +112,12 @@ def filter_costs(self, **conditions): def list_costs(self, query: dict, domain_id: str): query = self._change_filter_project_group_id(query, domain_id) - query = self._change_filter_v_workspace_id(query, domain_id) + # query = self._change_filter_v_workspace_id(query, domain_id) return self.cost_model.query(**query) def stat_costs(self, query: dict, domain_id: str): query = self._change_filter_project_group_id(query, domain_id) - query = self._change_filter_v_workspace_id(query, domain_id) + # query = self._change_filter_v_workspace_id(query, domain_id) return self.cost_model.stat(**query) @@ -122,12 +126,12 @@ def filter_monthly_costs(self, **conditions): def list_monthly_costs(self, query: dict, domain_id: str): query = self._change_filter_project_group_id(query, domain_id) - query = self._change_filter_v_workspace_id(query, domain_id) + # query = self._change_filter_v_workspace_id(query, domain_id) return self.monthly_cost_model.query(**query) def stat_monthly_costs(self, query: dict, domain_id: str): query = self._change_filter_project_group_id(query, domain_id) - query = self._change_filter_v_workspace_id(query, domain_id) + # query = self._change_filter_v_workspace_id(query, domain_id) return self.monthly_cost_model.stat(**query) def analyze_costs(self, query, domain_id, target="SECONDARY_PREFERRED"): @@ -201,7 +205,14 @@ def analyze_costs_by_granularity( granularity = query["granularity"] # Change filter v_workspace_id to workspace_id - query = self._change_filter_v_workspace_id(query, domain_id) + data_source_vo = self.data_source_mgr.get_data_source(data_source_id, domain_id) + plugin_metadata = data_source_vo.plugin_info.metadata + use_account_routing = plugin_metadata.get("use_account_routing", False) + if use_account_routing: + _LOGGER.debug( + f"[analyze_costs_by_granularity] add v_workspace_id filter: {data_source_id}" + ) + query = self._change_filter_v_workspace_id(query, domain_id) # Save query history to speed up data loading query_hash: str = utils.dict_to_hash(query)