Skip to content

Commit a88f5a2

Browse files
committed
feat: filter temporary tags from azure contain '.' at key field
Signed-off-by: ImMin5 <[email protected]>
1 parent e02e495 commit a88f5a2

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/cloudforet/cost_analysis/manager/cost_manager.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
332332

333333
additional_info["Term"] = term
334334

335+
if azure_additional_info := result.get("additionalinfo"):
336+
azure_additional_info: dict = json.loads(azure_additional_info)
337+
if ri_normalization_ratio := azure_additional_info.get(
338+
"RINormalizationRatio"
339+
):
340+
additional_info["RI Normalization Ratio"] = ri_normalization_ratio
341+
335342
if options.get("cost_metric") == "AmortizedCost":
336343
if result.get("pricingmodel") in ["Reservation", "SavingsPlan"]:
337344
meter_id = result.get("meterid")
@@ -658,18 +665,25 @@ def _make_scope(
658665

659666
@staticmethod
660667
def _convert_tags_str_to_dict(tags_str: Union[str, None]) -> dict:
668+
tags = {}
661669
try:
662-
if tags_str is None:
663-
return {}
670+
if tags_str:
671+
if tags_str[0] != "{" and tags_str[:-1] != "}":
672+
tags_str = "{" + tags_str + "}"
673+
674+
# todo: temporary remove key value include "."
675+
tags_info: dict = json.loads(tags_str)
664676

665-
if tags_str[0] != "{" and tags_str[:-1] != "}":
666-
tags_str = "{" + tags_str + "}"
677+
for key in tags_info.keys():
678+
if "." not in key:
679+
tags[key] = tags_info[key]
667680

668-
tags = json.loads(tags_str)
669681
return tags
670682
except Exception as e:
671-
_LOGGER.error(f"[_convert_tags_str_to_dict] tags : {tags_str} {e}")
672-
return {}
683+
_LOGGER.error(
684+
f"[_convert_tags_str_to_dict] tags : {tags_str} {e}", exc_info=True
685+
)
686+
return tags
673687

674688
@staticmethod
675689
def _set_product_from_benefit_name(benefit_name):

src/cloudforet/cost_analysis/manager/data_source_manager.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"Billing Tenant Id": {"name": "Billing Tenant Id", "visible": True},
6666
"Adjustment Name": {"name": "Adjustment Name", "visible": False},
6767
"Product Id": {"name": "Product Id", "visible": False},
68+
"RI Normalization Ratio": {"name": "RI Normalization Ratio", "visible": False},
6869
}
6970

7071
_METADATA_INFO_ADDITIONAL_INFO_MPA = {

0 commit comments

Comments
 (0)