1010from .cache import ttl_lru_cache
1111from .const_cost_aws import (
1212 FILTER_ATTRIBUTABLE_COSTS ,
13- FILTER_FIXED_COSTS ,
13+ FILTER_CORE_COSTS ,
1414 FILTER_HOME_STORAGE_COSTS ,
1515 FILTER_USAGE_COSTS ,
1616 GRANULARITY_DAILY ,
@@ -71,7 +71,7 @@ def query_hub_names(date_range: DateRange):
7171 date_range: DateRange object containing the time period for the query
7272
7373 Returns:
74- List of hub names, with empty/None values converted to "support "
74+ List of hub names, with empty/None values converted to "core "
7575 """
7676 # Use AWS-formatted dates (exclusive end date) for Cost Explorer API
7777 from_date , to_date = date_range .aws_range
@@ -81,7 +81,7 @@ def query_hub_names(date_range: DateRange):
8181 TimePeriod = {"Start" : from_date , "End" : to_date },
8282 TagKey = "2i2c:hub-name" ,
8383 )
84- hub_names = [t or "support " for t in response ["Tags" ]]
84+ hub_names = [t or "core " for t in response ["Tags" ]]
8585 return hub_names
8686
8787
@@ -317,63 +317,63 @@ def _create_base_filter() -> dict:
317317 }
318318
319319
320- def _process_fixed_costs (entries_by_date , fixed_cost_response ):
320+ def _process_core_costs (entries_by_date , core_cost_response ):
321321 """
322- Helper function to get fixed costs and deduct this from compute costs.
322+ Helper function to get core infrastructure costs and deduct this from compute costs.
323323
324324 This is because core node compute and root volumes, support EBS volumes
325325 and NAT Gateway (if it exists), are mapped to compute by default under
326326 the EC2 - Other service.
327327
328328 Args:
329329 entries_by_date: Dictionary indexed by date containing component entries
330- fixed_cost_response : AWS Cost Explorer response for fixed costs
330+ core_cost_response : AWS Cost Explorer response for core costs
331331 """
332332 logger .debug (
333- f"Processing fixed costs: { pformat (fixed_cost_response ['ResultsByTime' ])} "
333+ f"Processing core costs: { pformat (core_cost_response ['ResultsByTime' ])} "
334334 )
335- for fixed_e in fixed_cost_response ["ResultsByTime" ]:
336- date = fixed_e ["TimePeriod" ]["Start" ]
335+ for core_e in core_cost_response ["ResultsByTime" ]:
336+ date = core_e ["TimePeriod" ]["Start" ]
337337
338- # Calculate total fixed cost for this date
339- fixed_cost = 0.0
340- for g in fixed_e ["Groups" ]:
341- fixed_cost += float (g ["Metrics" ]["UnblendedCost" ]["Amount" ])
338+ # Calculate total core cost for this date
339+ core_cost = 0.0
340+ for g in core_e ["Groups" ]:
341+ core_cost += float (g ["Metrics" ]["UnblendedCost" ]["Amount" ])
342342
343- if fixed_cost > 0 :
343+ if core_cost > 0 :
344344 date_entries = entries_by_date .get (date , {})
345345
346346 # Subtract from compute component (EC2 - Other maps to compute)
347347 compute_entry = date_entries .get ("compute" )
348348 if compute_entry :
349349 current_compute_cost = float (compute_entry ["cost" ])
350- new_compute_cost = max (0.0 , current_compute_cost - fixed_cost )
350+ new_compute_cost = max (0.0 , current_compute_cost - core_cost )
351351 compute_entry ["cost" ] = f"{ new_compute_cost :.2f} "
352352 logger .debug (
353- f"Adjusted compute cost for { date } (fixed cost): { current_compute_cost :.2f} -> { new_compute_cost :.2f} "
353+ f"Adjusted compute cost for { date } (core cost): { current_compute_cost :.2f} -> { new_compute_cost :.2f} "
354354 )
355355
356- # Add to fixed component
357- fixed_entry = date_entries .get ("fixed " )
358- if fixed_entry :
359- current_fixed_cost = float (fixed_entry ["cost" ])
360- new_fixed_cost = current_fixed_cost + fixed_cost
361- fixed_entry ["cost" ] = f"{ new_fixed_cost :.2f} "
356+ # Add to core component
357+ core_entry = date_entries .get ("core " )
358+ if core_entry :
359+ current_core_cost = float (core_entry ["cost" ])
360+ new_core_cost = current_core_cost + core_cost
361+ core_entry ["cost" ] = f"{ new_core_cost :.2f} "
362362 logger .debug (
363- f"Updated fixed cost for { date } : { current_fixed_cost :.2f} -> { new_fixed_cost :.2f} "
363+ f"Updated core cost for { date } : { current_core_cost :.2f} -> { new_core_cost :.2f} "
364364 )
365365 else :
366- # Create new fixed entry if it doesn't exist
366+ # Create new core entry if it doesn't exist
367367 new_entry = {
368368 "date" : date ,
369- "cost" : f"{ fixed_cost :.2f} " ,
370- "component" : "fixed " ,
369+ "cost" : f"{ core_cost :.2f} " ,
370+ "component" : "core " ,
371371 }
372372 # Update index
373373 if date not in entries_by_date :
374374 entries_by_date [date ] = {}
375- entries_by_date [date ]["fixed " ] = new_entry
376- logger .debug (f"Added new fixed entry for { date } : { fixed_cost :.2f} " )
375+ entries_by_date [date ]["core " ] = new_entry
376+ logger .debug (f"Added new core entry for { date } : { core_cost :.2f} " )
377377
378378
379379@ttl_lru_cache (seconds_to_live = 3600 )
@@ -490,25 +490,25 @@ def query_total_costs_per_component(
490490 f"Entries by date after home storage processing: { entries_by_date } \n \n "
491491 )
492492
493- # Query fixed costs (core nodes, hub databases, support components)
494- # These should be subtracted from compute and added to a "fixed " component
495- fixed_cost_filter = _create_base_filter ()
496- _add_hub_filter (fixed_cost_filter , hub_name )
497- fixed_cost_filter ["And" ].append (FILTER_FIXED_COSTS )
493+ # Query core costs (core nodes, hub databases, support components)
494+ # These should be subtracted from compute and added to a "core " component
495+ core_cost_filter = _create_base_filter ()
496+ _add_hub_filter (core_cost_filter , hub_name )
497+ core_cost_filter ["And" ].append (FILTER_CORE_COSTS )
498498
499- fixed_cost_response = query_aws_cost_explorer (
499+ core_cost_response = query_aws_cost_explorer (
500500 metrics = [METRICS_UNBLENDED_COST ],
501501 granularity = GRANULARITY_DAILY ,
502502 from_date = from_date ,
503503 to_date = to_date ,
504- filter = fixed_cost_filter ,
504+ filter = core_cost_filter ,
505505 group_by = [GROUP_BY_SERVICE_DIMENSION ],
506506 )
507507
508- # Process fixed costs and adjust compute costs accordingly
509- _process_fixed_costs (entries_by_date , fixed_cost_response )
508+ # Process core costs and adjust compute costs accordingly
509+ _process_core_costs (entries_by_date , core_cost_response )
510510
511- logger .debug (f"Entries by date after fixed cost processing: { entries_by_date } \n \n " )
511+ logger .debug (f"Entries by date after core cost processing: { entries_by_date } \n \n " )
512512
513513 # Generate final response from index, sorted by date
514514 final_response = []
0 commit comments