@@ -108,7 +108,7 @@ def run_unified_cost(self, params: dict):
108
108
109
109
unified_cost_job_vo = self ._get_unified_cost_job (domain_id , aggregation_month )
110
110
111
- aggregation_date = self ._get_aggregation_date (
111
+ aggregation_execution_date = self ._get_aggregation_date (
112
112
unified_cost_config , aggregation_month , is_confirmed
113
113
)
114
114
exchange_date = self ._get_exchange_date (
@@ -139,7 +139,8 @@ def run_unified_cost(self, params: dict):
139
139
workspace_id ,
140
140
currency_map ,
141
141
exchange_date ,
142
- aggregation_date ,
142
+ aggregation_execution_date ,
143
+ aggregation_month ,
143
144
is_confirmed ,
144
145
)
145
146
self ._delete_old_unified_costs (
@@ -321,14 +322,18 @@ def create_unified_cost_with_workspace(
321
322
workspace_id : Union [str , None ],
322
323
currency_map : dict ,
323
324
exchange_date : datetime ,
324
- aggregation_date : datetime ,
325
+ aggregation_execution_date : datetime ,
326
+ aggregation_month : str ,
325
327
is_confirmed : bool = False ,
326
328
) -> None :
327
329
328
330
identity_mgr = IdentityManager (token = config .get_global ("TOKEN" ))
329
331
workspace_ids = [workspace_id ]
330
332
331
- workspace_name = identity_mgr .get_workspace (workspace_id , domain_id )
333
+ if workspace_id :
334
+ workspace_name = identity_mgr .get_workspace (workspace_id , domain_id )
335
+ else :
336
+ workspace_name = None
332
337
333
338
v_workspace_ids = self ._get_virtual_workspace_ids_from_ds_account (
334
339
domain_id , workspace_id
@@ -346,8 +351,7 @@ def create_unified_cost_with_workspace(
346
351
domain_id , workspace_id
347
352
)
348
353
349
- unified_cost_billed_year = aggregation_date .strftime ("%Y" )
350
- unified_cost_billed_month = aggregation_date .strftime ("%Y-%m" )
354
+ unified_cost_billed_year = aggregation_month .split ("-" )[0 ]
351
355
352
356
query = {
353
357
"group_by" : [
@@ -368,12 +372,12 @@ def create_unified_cost_with_workspace(
368
372
"fields" : {
369
373
"cost" : {"key" : "cost" , "operator" : "sum" },
370
374
},
371
- "start" : unified_cost_billed_year ,
372
- "end" : unified_cost_billed_month ,
375
+ "start" : aggregation_month ,
376
+ "end" : aggregation_month ,
373
377
"filter" : [
374
378
{"k" : "domain_id" , "v" : domain_id , "o" : "eq" },
375
379
{"k" : "data_source_id" , "v" : data_source_ids , "o" : "in" },
376
- {"k" : "billed_month" , "v" : unified_cost_billed_month , "o" : "eq" },
380
+ {"k" : "billed_month" , "v" : aggregation_month , "o" : "eq" },
377
381
{"k" : "workspace_id" , "v" : workspace_ids , "o" : "in" },
378
382
{"k" : "billed_year" , "v" : unified_cost_billed_year , "o" : "eq" },
379
383
],
@@ -388,7 +392,7 @@ def create_unified_cost_with_workspace(
388
392
cursor = self .cost_mgr .analyze_monthly_costs (query , domain_id )
389
393
390
394
exchange_date_str = exchange_date .strftime ("%Y-%m-%d" )
391
- aggregation_date_str = aggregation_date .strftime ("%Y-%m-%d" )
395
+ aggregation_execution_date_str = aggregation_execution_date .strftime ("%Y-%m-%d" )
392
396
393
397
row_count = 0
394
398
for row in cursor :
@@ -439,23 +443,31 @@ def create_unified_cost_with_workspace(
439
443
aggregated_unified_cost_data ["exchange_source" ] = exchange_source
440
444
441
445
aggregated_unified_cost_data ["is_confirmed" ] = is_confirmed
442
- aggregated_unified_cost_data ["aggregation_date" ] = aggregation_date_str
446
+ aggregated_unified_cost_data ["aggregation_date" ] = (
447
+ aggregation_execution_date_str
448
+ )
443
449
444
450
self .unified_cost_mgr .create_unified_cost (aggregated_unified_cost_data )
451
+ row_count += 1
445
452
446
453
_LOGGER .debug (
447
454
f"[create_unified_cost_with_workspace] create count: { row_count } (workspace_id: { workspace_id } )"
448
455
)
449
456
450
457
def _get_data_source_currency_map (
451
- self , domain_id : str , workspace_id : str
458
+ self , domain_id : str , workspace_id : Union [ str , None ]
452
459
) -> Tuple [dict , dict , list ]:
453
460
data_source_currency_map = {}
454
461
data_source_name_map = {}
462
+ workspace_ids = ["*" ]
463
+
464
+ if workspace_id :
465
+ workspace_ids .append (workspace_id )
466
+
455
467
query = {
456
468
"filter" : [
457
469
{"k" : "domain_id" , "v" : domain_id , "o" : "eq" },
458
- {"k" : "workspace_id" , "v" : [ workspace_id , "*" ] , "o" : "in" },
470
+ {"k" : "workspace_id" , "v" : workspace_ids , "o" : "in" },
459
471
]
460
472
}
461
473
@@ -473,7 +485,7 @@ def _get_data_source_currency_map(
473
485
return data_source_currency_map , data_source_name_map , data_source_ids
474
486
475
487
def _get_virtual_workspace_ids_from_ds_account (
476
- self , domain_id : str , workspace_id : str
488
+ self , domain_id : str , workspace_id : Union [ str , None ]
477
489
) -> list :
478
490
v_workspace_ids = []
479
491
ds_account_vos = self .ds_account_mgr .filter_data_source_accounts (
0 commit comments