Skip to content

Commit f622722

Browse files
committed
feat: add Consumed Service field from azure raws data
Signed-off-by: ImMin5 <mino@megazone.com>
1 parent 23e5051 commit f622722

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

src/cloudforet/cost_analysis/conf/cost_conf.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
{"type": "Dimension", "name": "ReservationName"},
3838
{"type": "Dimension", "name": "ChargeType"},
3939
{"type": "Dimension", "name": "MeterCategory"},
40+
{"type": "Dimension", "name": "ConsumedService"},
4041
]
4142

4243
BENEFIT_GROUPING_MPA = [
@@ -53,11 +54,6 @@
5354
{"type": "Dimension", "name": "TenantId"},
5455
]
5556

56-
GROUPING_EA_AGREEMENT_OPTION = [
57-
{"type": "Dimension", "name": "DepartmentName"},
58-
{"type": "Dimension", "name": "EnrollmentAccountName"},
59-
]
60-
6157
REGION_MAP = {
6258
"global": "Global",
6359
"unknown": "Unknown",

src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def query_usage_http(
138138
"dataset": {
139139
"granularity": GRANULARITY,
140140
"aggregation": AGGREGATION,
141-
"grouping": BENEFIT_GROUPING,
142141
"filter": BENEFIT_FILTER,
143142
},
144143
}

src/cloudforet/cost_analysis/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
22
from typing import Generator
3+
4+
from spaceone.core.error import ERROR_INVALID_PARAMETER_TYPE
35
from spaceone.cost_analysis.plugin.data_source.lib.server import DataSourcePluginServer
46

57
from .manager import CostManager, DataSourceManager, JobManager
@@ -187,6 +189,13 @@ def __remove_duplicate_list_of_dict(changed: list) -> list:
187189
return unique_list
188190

189191

192+
def __check_secret_data(secret_data: dict):
193+
customer_tenants = secret_data.get("customer_tenants", []) or []
194+
195+
if not isinstance(customer_tenants, list):
196+
raise ERROR_INVALID_PARAMETER_TYPE(key="customer_tenants", type="list")
197+
198+
190199
def __get_secret_data(secret_data: dict, task_options: dict) -> dict:
191200
secrets = secret_data.get("secrets", [secret_data])
192201
if len(secrets) == 1:

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import time
55
import pandas as pd
6-
from typing import Union, Tuple
6+
from typing import Union, Tuple, Any, Generator
77
from datetime import datetime, timezone
88

99
from spaceone.core.error import *
@@ -321,6 +321,9 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
321321
if result.get("metername") != "" and result.get("metername"):
322322
additional_info["Meter Name"] = result["metername"]
323323

324+
if result.get("consumedservice") != "" and result.get("consumedservice"):
325+
additional_info["Consumed Service"] = result["consumedservice"]
326+
324327
if result.get("term") != "" and result.get("term"):
325328
term = result.get("term")
326329
if isinstance(term, str):
@@ -424,24 +427,28 @@ def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
424427
"Charge Type": result.get("ChargeType"),
425428
}
426429

427-
if result.get("SubscriptionId"):
428-
additional_info["Subscription Id"] = result.get("SubscriptionId")
430+
if subscription_id := result.get("SubscriptionId"):
431+
additional_info["Subscription Id"] = subscription_id
429432

430-
if result.get("CustomerName"):
431-
additional_info["Customer Name"] = result.get("CustomerName")
433+
if customer_name := result.get("CustomerName"):
434+
additional_info["Customer Name"] = customer_name
432435

433-
if result.get("CustomerTenantId"):
434-
additional_info["Tenant Id"] = result.get("CustomerTenantId")
436+
if customer_id := result.get("CustomerTenantId"):
437+
additional_info["Tenant Id"] = customer_id
435438
elif result.get("TenantId"):
436439
additional_info["Tenant Id"] = result.get("TenantId")
437440

438-
if result.get("DepartmentName"):
439-
additional_info["Department Name"] = result.get("DepartmentName")
441+
if department_name := result.get("DepartmentName"):
442+
additional_info["Department Name"] = department_name
440443

441-
if result.get("EnrollmentAccountName"):
442-
additional_info["Enrollment Account Name"] = result.get(
443-
"EnrollmentAccountName"
444-
)
444+
if enrollment_account_name := result.get("EnrollmentAccountName"):
445+
additional_info["Enrollment Account Name"] = enrollment_account_name
446+
447+
if service_family := result.get("ServiceFamily"):
448+
additional_info["Service Family"] = service_family
449+
450+
if consumed_service := result.get("ConsumedService"):
451+
additional_info["Consumed Service"] = consumed_service
445452

446453
usage_quantity = self._convert_str_to_float_format(
447454
result.get("UsageQuantity", 0.0)

src/cloudforet/cost_analysis/manager/data_source_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"Reservation Id": {"name": "Reservation Id", "visible": False},
6060
"Reservation Name": {"name": "Reservation Name", "visible": False},
6161
"Service Family": {"name": "Service Family", "visible": True},
62+
"Consumed Service": {"name": "Consumed Service", "visible": True},
6263
"Term": {"name": "Term", "visible": False},
6364
"Usage Type Details": {"name": "Usage Type Details", "visible": True},
6465
"Exchange Rate": {"name": "Exchange Rate", "visible": False},

src/cloudforet/cost_analysis/manager/job_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ def get_tasks(
193193
else:
194194
raise ERROR_INVALID_SECRET_TYPE(secret_type=options.get("secret_type"))
195195

196+
_LOGGER.debug(f"[get_tasks] tasks: {tasks}")
197+
_LOGGER.debug(f"[get_tasks] changed: {changed}")
198+
_LOGGER.debug(f"[get_tasks] synced_accounts: {synced_accounts}")
196199
tasks = {"tasks": tasks, "changed": changed, "synced_accounts": synced_accounts}
197200
return tasks
198201

@@ -265,7 +268,7 @@ def _get_customer_tenants(
265268
self, secret_data: dict, linked_accounts: list = None
266269
) -> Tuple[list, list]:
267270
first_sync_customer_tenants = []
268-
customer_tenants = secret_data.get(
271+
customer_tenants: list = secret_data.get(
269272
"customer_tenants", self._get_tenants_from_billing_account()
270273
)
271274
if len(customer_tenants) == 0:

0 commit comments

Comments
 (0)