Skip to content

Commit

Permalink
Merge pull request #213 from whdalsrnt/master
Browse files Browse the repository at this point in the history
fix: fix query bug
  • Loading branch information
whdalsrnt authored Apr 29, 2024
2 parents 671c8ed + c5cd283 commit b316f13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@
author_email="[email protected]",
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",
Expand Down
21 changes: 16 additions & 5 deletions src/spaceone/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

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

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

0 comments on commit b316f13

Please sign in to comment.