diff --git a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py index ba2df9e..9c115ef 100644 --- a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py +++ b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py @@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) -_PAGE_SIZE = 5000 +_PAGE_SIZE = 6000 class AzureCostMgmtConnector(BaseConnector): diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index 707c41c..37d8804 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -109,6 +109,9 @@ def _make_cost_data( if not billed_date: continue + if self._skip_cost_data_rule(result): + continue + data = self._make_data_info(result, billed_date, options, tenant_id) costs_data.append(data) @@ -222,9 +225,6 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non if result.get("productname"): additional_info["Product Name"] = result["productname"] - if result.get("unitprice") != "" and result.get("unitprice"): - additional_info["Unit Price"] = result["unitprice"] - if result.get("customername") != "" and result.get("customername"): additional_info["Customer Name"] = result["customername"] @@ -243,7 +243,7 @@ def _get_cost_from_result_with_options(self, result: dict, options: dict) -> flo cost = self._convert_str_to_float_format( result.get("costinbillingcurrency", 0.0) ) - if options.get("pay_as_you_go", False) and result.get("chargetype") == "Usage": + if options.get("pay_as_you_go", False): cost = self.get_pay_as_you_go_cost(result, cost) return cost @@ -470,3 +470,9 @@ def _check_task_options(task_options): raise ERROR_REQUIRED_PARAMETER(key="task_options.subscription_id") elif task_options["collect_scope"] == "customer_tenants": raise ERROR_REQUIRED_PARAMETER(key="task_options.customer_tenants") + + @staticmethod + def _skip_cost_data_rule(result: dict) -> bool: + if result.get("customertenentname") and not result.get("customertenantid"): + return True + return False diff --git a/src/cloudforet/cost_analysis/manager/data_source_manager.py b/src/cloudforet/cost_analysis/manager/data_source_manager.py index fc632ae..7204299 100644 --- a/src/cloudforet/cost_analysis/manager/data_source_manager.py +++ b/src/cloudforet/cost_analysis/manager/data_source_manager.py @@ -1,10 +1,7 @@ import logging from spaceone.core.manager import BaseManager -from cloudforet.cost_analysis.model.data_source_model import ( - PluginMetadata, - DEFAULT_ACCOUNT_CONNECT_POLICES, -) +from cloudforet.cost_analysis.model.data_source_model import PluginMetadata from cloudforet.cost_analysis.connector.azure_cost_mgmt_connector import ( AzureCostMgmtConnector, ) @@ -28,7 +25,7 @@ def init_response(options): if options.get("use_account_routing"): plugin_metadata.use_account_routing = True - plugin_metadata.account_connect_polices = DEFAULT_ACCOUNT_CONNECT_POLICES + plugin_metadata.account_match_key = "additional_info.Tenant Id" plugin_metadata.validate() return {"metadata": plugin_metadata.to_primitive()} diff --git a/src/cloudforet/cost_analysis/model/data_source_model.py b/src/cloudforet/cost_analysis/model/data_source_model.py index e00f715..0c66467 100644 --- a/src/cloudforet/cost_analysis/model/data_source_model.py +++ b/src/cloudforet/cost_analysis/model/data_source_model.py @@ -18,50 +18,16 @@ } ] -DEFAULT_ACCOUNT_CONNECT_POLICES = [ - { - "name": "connect_account_to_workspace", - "polices": { - "connect_account_to_workspace": { - "operator": "in", - "source": "account_id", - "target": "references", - } - }, - }, - { - "name": "connect_cost_to_account", - "polices": { - "connect_cost_to_account": { - "operator": "eq", - "source": "additional_info.Tenant Id", - "target": "account_id", - } - }, - }, -] - class MatchServiceAccount(Model): source = StringType(required=True) target = StringType(required=True) -class ConnectResource(Model): - operator = StringType(choices=["in", "eq"], default=["eq"]) - source = StringType(required=True) - target = StringType(required=True) - - class Actions(Model): match_service_account = ModelType(MatchServiceAccount) -class Polices(Model): - connect_account_to_workspace = ModelType(ConnectResource) - connect_cost_to_account = ModelType(ConnectResource) - - class Options(Model): stop_processing = BooleanType(default=False) @@ -92,8 +58,8 @@ class PluginMetadata(Model): data_source_rules = ListType( ModelType(DataSourceRule), default=_DEFAULT_DATA_SOURCE_RULES ) - account_connect_polices = ListType(ModelType(AccountMatchPolicy), default=[]) supported_secret_types = ListType(StringType, default=["MANUAL"]) currency = StringType(default="KRW") use_account_routing = BooleanType(default=False) alias = DictType(StringType, default={}) + account_match_key = StringType(default=None)