Skip to content

Commit

Permalink
Merge pull request #102 from ImMin5/master
Browse files Browse the repository at this point in the history
Filter temporary tags from azure contain '.' at key field
  • Loading branch information
ImMin5 authored Sep 24, 2024
2 parents e02e495 + a88f5a2 commit f83d383
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non

additional_info["Term"] = term

if azure_additional_info := result.get("additionalinfo"):
azure_additional_info: dict = json.loads(azure_additional_info)
if ri_normalization_ratio := azure_additional_info.get(
"RINormalizationRatio"
):
additional_info["RI Normalization Ratio"] = ri_normalization_ratio

if options.get("cost_metric") == "AmortizedCost":
if result.get("pricingmodel") in ["Reservation", "SavingsPlan"]:
meter_id = result.get("meterid")
Expand Down Expand Up @@ -658,18 +665,25 @@ def _make_scope(

@staticmethod
def _convert_tags_str_to_dict(tags_str: Union[str, None]) -> dict:
tags = {}
try:
if tags_str is None:
return {}
if tags_str:
if tags_str[0] != "{" and tags_str[:-1] != "}":
tags_str = "{" + tags_str + "}"

# todo: temporary remove key value include "."
tags_info: dict = json.loads(tags_str)

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

tags = json.loads(tags_str)
return tags
except Exception as e:
_LOGGER.error(f"[_convert_tags_str_to_dict] tags : {tags_str} {e}")
return {}
_LOGGER.error(
f"[_convert_tags_str_to_dict] tags : {tags_str} {e}", exc_info=True
)
return tags

@staticmethod
def _set_product_from_benefit_name(benefit_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"Billing Tenant Id": {"name": "Billing Tenant Id", "visible": True},
"Adjustment Name": {"name": "Adjustment Name", "visible": False},
"Product Id": {"name": "Product Id", "visible": False},
"RI Normalization Ratio": {"name": "RI Normalization Ratio", "visible": False},
}

_METADATA_INFO_ADDITIONAL_INFO_MPA = {
Expand Down

0 comments on commit f83d383

Please sign in to comment.