Skip to content

Commit c738bd0

Browse files
committed
feat: modify read csv method chunk size
Signed-off-by: ImMin5 <[email protected]>
1 parent 16aacab commit c738bd0

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,25 @@ def begin_create_operation(self, scope: str, parameters: dict) -> list:
101101
raise ERROR_UNKNOWN(message=f"[ERROR] begin_create_operation failed")
102102

103103
def get_cost_data(self, blobs: list, options: dict) -> list:
104+
_LOGGER.debug(f"[get_cost_data] options: {options}")
105+
106+
total_cost_count = 0
104107
for blob in blobs:
105108
cost_csv = self._download_cost_data(blob)
106109

107-
df = pd.read_csv(StringIO(cost_csv), low_memory=False)
108-
df = df.replace({np.nan: None})
109-
110-
costs_data = df.to_dict("records")
111-
112-
_LOGGER.debug(
113-
f"[get_cost_data] costs count: {len(costs_data)}, options: {options}"
110+
df_chunk = pd.read_csv(
111+
StringIO(cost_csv), low_memory=False, chunksize=_PAGE_SIZE
114112
)
115113

116-
# Paginate
117-
page_count = int(len(costs_data) / _PAGE_SIZE) + 1
114+
for df in df_chunk:
115+
df = df.replace({np.nan: None})
118116

119-
for page_num in range(page_count):
120-
offset = _PAGE_SIZE * page_num
121-
yield costs_data[offset : offset + _PAGE_SIZE]
117+
costs_data = df.to_dict("records")
118+
total_cost_count += len(costs_data)
119+
yield costs_data
122120

123-
del df
121+
del cost_csv
122+
_LOGGER.debug(f"[get_cost_data] total_cost_count: {total_cost_count}")
124123

125124
def list_by_billing_account(self):
126125
billing_account_name = self.billing_account_id

src/cloudforet/cost_analysis/manager/cost_manager.py

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def get_data(
7979
scope = self._make_scope(
8080
secret_data, task_options, collect_scope, tenant_id
8181
)
82+
8283
blobs = self.azure_cm_connector.begin_create_operation(
8384
scope, parameters
8485
)
@@ -221,6 +222,7 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
221222
result["metercategory"] = self._set_product_from_benefit_name(
222223
benefit_name
223224
)
225+
224226
if result.get("benefitid") != "" and result.get("benefitid"):
225227
additional_info["Benefit Id"] = result["benefitid"]
226228

0 commit comments

Comments
 (0)