Skip to content

Add total count logging and improve secret data handling in cost manager #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cloudforet/cost_analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def cost_get_data(params: dict) -> Generator[dict, None, None]:

params["schema"] = params.pop("schema_name", None)
params["secret_data"] = __get_secret_data(secret_data, task_options)

is_benefit_job = task_options.get("is_benefit_job", False)
cost_metric = options.get("cost_metric", "ActualCost")

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

tenant_id = task_options["billing_tenant_id"]
billing_tenant_id = task_options["billing_tenant_id"]

for _secret_data in secrets:
if _secret_data["tenant_id"] == tenant_id:
if _secret_data["tenant_id"] == billing_tenant_id:
return _secret_data

elif _secret_data.get("subscription_id") == task_options.get("subscription_id"):
elif _secret_data.get("subscription_id") and _secret_data.get(
"subscription_id"
) == task_options.get("subscription_id"):
return _secret_data

return secret_data
return secrets[0]
7 changes: 5 additions & 2 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ def _make_benefit_cost_data(
account_agreement_type: str = None,
) -> list:
benefit_costs_data = []
total_count = 0

try:
combined_results = self._combine_rows_and_columns_from_results(
results.get("properties").get("rows"),
results.get("properties").get("columns"),
)
total_count += len(combined_results)
for cb_result in combined_results:
billed_at = self._set_billed_date(cb_result.get("UsageDate", end))
if not billed_at:
Expand All @@ -419,13 +422,13 @@ def _make_benefit_cost_data(
except Exception as e:
_LOGGER.error(f"[_make_cost_data] make data error: {e}", exc_info=True)
raise e

_LOGGER.info(f"[get_benefit_data] total count: {total_count}")
return benefit_costs_data

def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
print(result)
additional_info = {
"Pricing Model": result.get("PricingModel"),
"Frequency": result.get("BillingFrequency"),
"Benefit Id": result.get("BenefitId"),
"Benefit Name": result.get("BenefitName"),
"Reservation Id": result.get("ReservationId"),
Expand Down
Loading