diff --git a/src/spaceone/cost_analysis/manager/cost_report_manager.py b/src/spaceone/cost_analysis/manager/cost_report_manager.py index 06d4b3f7..a11c0303 100644 --- a/src/spaceone/cost_analysis/manager/cost_report_manager.py +++ b/src/spaceone/cost_analysis/manager/cost_report_manager.py @@ -41,6 +41,7 @@ def filter_cost_reports(self, **conditions) -> QuerySet: return self.cost_report_model.filter(**conditions) def list_cost_reports(self, query: dict) -> Tuple[QuerySet, int]: + _LOGGER.debug(f"[list_cost_reports] query: {query}") return self.cost_report_model.query(**query) def stat_cost_reports(self, query: dict) -> dict: diff --git a/src/spaceone/cost_analysis/model/cost_report/database.py b/src/spaceone/cost_analysis/model/cost_report/database.py index c49b2179..f0830055 100644 --- a/src/spaceone/cost_analysis/model/cost_report/database.py +++ b/src/spaceone/cost_analysis/model/cost_report/database.py @@ -37,5 +37,24 @@ class CostReport(MongoModel): "-created_at", "-report_number", ], - "indexes": ["cost_report_config_id", "status", "domain_id", "workspace_id"], + "indexes": [ + { + "fields": [ + "cost_report_config_id", + "status", + "domain_id", + "workspace_id", + ], + "name": "COMPOUND_INDEX_FOR_CONFIRM_REPORT", + }, + { + "fields": [ + "report_month", + "status", + "domain_id", + "workspace_id", + ], + "name": "COMPOUND_INDEX_FOR_CONFIRM_REPORT_2", + }, + ], } diff --git a/src/spaceone/cost_analysis/model/cost_report_data/database.py b/src/spaceone/cost_analysis/model/cost_report_data/database.py index 954dcf97..81016bc0 100644 --- a/src/spaceone/cost_analysis/model/cost_report_data/database.py +++ b/src/spaceone/cost_analysis/model/cost_report_data/database.py @@ -21,9 +21,8 @@ class CostReportData(MongoModel): data_source_id = StringField(max_length=40) cost_report_id = StringField(max_length=40) cost_report_config_id = StringField(max_length=40) - workspace_id = StringField( - max_length=40, default=None, null=True - ) # todo workspace_id required + project_id = StringField(max_length=40, default=None, null=True) + workspace_id = StringField(max_length=40) domain_id = StringField(max_length=40) created_at = DateTimeField(auto_now_add=True) @@ -36,9 +35,19 @@ class CostReportData(MongoModel): "workspace_id", ], "ordering": ["is_confirmed", "-report_year"], + "change_query_keys": {"user_projects": "project_id"}, "indexes": [ - "cost_report_config_id", - "cost_report_id", - "domain_id", + { + "fields": [ + "cost_report_config_id", + "cost_report_id", + "domain_id", + ], + "name": "COMPOUND_INDEX_FOR_DEFAULT_COST_REPORT_DATA", + }, + { + "fields": ["is_confirmed", "domain_id", "workspace_id", "project_id"], + "name": "COMPOUND_INDEX_FOR_WORKSPACE_LANDING", + }, ], } diff --git a/src/spaceone/cost_analysis/model/cost_report_data/request.py b/src/spaceone/cost_analysis/model/cost_report_data/request.py index d0931178..df7bedf4 100644 --- a/src/spaceone/cost_analysis/model/cost_report_data/request.py +++ b/src/spaceone/cost_analysis/model/cost_report_data/request.py @@ -27,7 +27,10 @@ class CostReportDataAnalyzeQueryRequest(BaseModel): product: Union[str, None] = None provider: Union[str, None] = None data_source_id: Union[str, None] = None + cost_report_id: Union[str, None] = None cost_report_config_id: Union[str, None] = None + user_projects: Union[list, None] = None + project_id: Union[str, None] = None workspace_id: Union[str, None] = None domain_id: str diff --git a/src/spaceone/cost_analysis/service/cost_report_data_service.py b/src/spaceone/cost_analysis/service/cost_report_data_service.py index 3343e815..0c9af3bd 100644 --- a/src/spaceone/cost_analysis/service/cost_report_data_service.py +++ b/src/spaceone/cost_analysis/service/cost_report_data_service.py @@ -77,7 +77,7 @@ def list( @transaction( permission="cost-analysis:CostReportData.read", - role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER"], + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"], ) @append_query_filter( [ @@ -85,10 +85,13 @@ def list( "provider", "is_confirmed", "cost_report_config_id", + "cost_report_id", "cost_report_data_id", "data_source_id", "workspace_id", "domain_id", + "project_id", + "user_projects", ] ) @append_keyword_filter(