Skip to content

Commit c0ac3cc

Browse files
authored
Merge pull request #110 from ImMin5/master
Add total count logging and improve secret data handling in cost manager
2 parents 1a49033 + 5927d68 commit c0ac3cc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/cloudforet/cost_analysis/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def cost_get_data(params: dict) -> Generator[dict, None, None]:
161161

162162
params["schema"] = params.pop("schema_name", None)
163163
params["secret_data"] = __get_secret_data(secret_data, task_options)
164+
164165
is_benefit_job = task_options.get("is_benefit_job", False)
165166
cost_metric = options.get("cost_metric", "ActualCost")
166167

@@ -201,13 +202,15 @@ def __get_secret_data(secret_data: dict, task_options: dict) -> dict:
201202
if len(secrets) == 1:
202203
return secrets[0]
203204

204-
tenant_id = task_options["billing_tenant_id"]
205+
billing_tenant_id = task_options["billing_tenant_id"]
205206

206207
for _secret_data in secrets:
207-
if _secret_data["tenant_id"] == tenant_id:
208+
if _secret_data["tenant_id"] == billing_tenant_id:
208209
return _secret_data
209210

210-
elif _secret_data.get("subscription_id") == task_options.get("subscription_id"):
211+
elif _secret_data.get("subscription_id") and _secret_data.get(
212+
"subscription_id"
213+
) == task_options.get("subscription_id"):
211214
return _secret_data
212215

213-
return secret_data
216+
return secrets[0]

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,14 @@ def _make_benefit_cost_data(
403403
account_agreement_type: str = None,
404404
) -> list:
405405
benefit_costs_data = []
406+
total_count = 0
407+
406408
try:
407409
combined_results = self._combine_rows_and_columns_from_results(
408410
results.get("properties").get("rows"),
409411
results.get("properties").get("columns"),
410412
)
413+
total_count += len(combined_results)
411414
for cb_result in combined_results:
412415
billed_at = self._set_billed_date(cb_result.get("UsageDate", end))
413416
if not billed_at:
@@ -419,13 +422,13 @@ def _make_benefit_cost_data(
419422
except Exception as e:
420423
_LOGGER.error(f"[_make_cost_data] make data error: {e}", exc_info=True)
421424
raise e
422-
425+
_LOGGER.info(f"[get_benefit_data] total count: {total_count}")
423426
return benefit_costs_data
424427

425428
def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
429+
print(result)
426430
additional_info = {
427431
"Pricing Model": result.get("PricingModel"),
428-
"Frequency": result.get("BillingFrequency"),
429432
"Benefit Id": result.get("BenefitId"),
430433
"Benefit Name": result.get("BenefitName"),
431434
"Reservation Id": result.get("ReservationId"),

0 commit comments

Comments
 (0)