in source/lambda/shared/elb_load_monitor/elb_listener_rule.py [0:0]
def shed(self, source_group_arn: str, weight_to_shed: int, max_shed_weight: int) -> None:
if source_group_arn not in self.forward_configs:
logger.debug('No target group ' + source_group_arn + ' found for rule ' + self.elb_rule_arn +
' nothing to shed')
return
current_source_weight = self.forward_configs.get(source_group_arn)
if max_shed_weight == (100 - current_source_weight):
logger.debug(
'No more load permitted to be shed for ' + source_group_arn)
return
new_source_weight = current_source_weight - weight_to_shed
if max_shed_weight < (100 - new_source_weight):
new_source_weight = 100 - max_shed_weight
weight_to_shed = current_source_weight - new_source_weight
logger.debug(
'Desired shed amount exceeds total maximum shed amount, shedding by new amount:' + str(weight_to_shed))
# if new_source_weight < 0:
# # source weight cannot be < 0
# new_source_weight = 0
self.forward_configs[source_group_arn] = new_source_weight
logger.debug('Shedding ' + str(weight_to_shed) +
' percent from ' + source_group_arn + '. new weight: ' + str(self.forward_configs[source_group_arn]))
per_target_weight_to_shed = weight_to_shed
num_forwards = len(self.forward_configs)
remainder_weight = 0
if num_forwards > 2:
# if more than 2 forward configs, then split the weight evenly among the remaining 2 targets
div_mod = divmod(weight_to_shed, (len(self.forward_configs) - 1))
per_target_weight_to_shed = div_mod[0]
remainder_weight = div_mod[1]
for key in self.forward_configs.keys():
num_forwards -= 1
if key == source_group_arn:
continue
new_weight = self.forward_configs.get(
key) + per_target_weight_to_shed
if (num_forwards == 0):
new_weight += remainder_weight
logger.debug('Receiving ' + str(per_target_weight_to_shed) +
' percent from ' + source_group_arn + ' on ' +
key + '. New load in : ' + key + ' ' + str(new_weight))
self.forward_configs[key] = new_weight
return