| 1 | package App::FargateStack::Builder::Autoscaling; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use CLI::Simple::Constants qw(:booleans); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use List::Util qw(none any uniq pairs max); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use App::FargateStack::AutoscalingConfig; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use App::FargateStack::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use App::FargateStack::Builder::Utils qw(log_die dmp choose); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub build_autoscaling { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_autoscaling: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my ( $config, $tasks ) = $self->common_args(qw(config tasks)); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | foreach my $task_name ( keys %{$tasks} ) { | |||||||||||||||||||||||||||||||||||||||||
| 27 | # autoscaling only applies to http & daemon tasks | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | next if $tasks->{$task_name} =~ /^(?:task|scheduled)$/xsm; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | next | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if !exists $tasks->{$task_name}->{autoscaling}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->_build_autoscaling($task_name); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $SUCCESS; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub _build_autoscaling { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_autoscaling: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $dryrun = $self->get_dryrun; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $task = $self->get_config->{tasks}->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $app_autoscaling = $self->fetch_application_autoscaling; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $policy_name = $self->create_default( 'autoscaling-policy-name', $task_name ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | my $autoscaling_config | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | = eval { return App::FargateStack::AutoscalingConfig->new( config => $task->{autoscaling}, policy_name => $policy_name ); }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | log_die( $self, $EVAL_ERROR ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $autoscaling_config or $App::FargateStack::Builder::Autoscaling::EVAL_ERROR
MC/DC0%0/2
not $autoscaling_config or $App::FargateStack::Builder::Autoscaling::EVAL_ERROR
not $autoscaling_config
$App::FargateStack::Builder::Autoscaling::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $autoscaling_configB= $App::FargateStack::Builder::Autoscaling::EVAL_ERROR
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | if !$autoscaling_config || $EVAL_ERROR; | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $resource_id = $self->_resource_id($task_name); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # scheduled actions | ||||||||||||||||||||||||||||||||||||||||||
| 62 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $autoscaling_config->has_scheduled_action ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $self->build_scheduled_actions( | |||||||||||||||||||||||||||||||||||||||||
| 65 | task => $task, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | app_autoscaling => $app_autoscaling, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | autoscaling_config => $autoscaling_config, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $scaling_policy = $app_autoscaling->describe_scaling_policies( | |||||||||||||||||||||||||||||||||||||||||
| 73 | service_namespace => 'ecs', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | policy_names => $policy_name, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | query => 'ScalingPolicies', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not describe scaling policies for: [%s]', $resource_id ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $scaling_policy = $scaling_policy->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | return | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if !$autoscaling_config->get_cpu && !$autoscaling_config->get_requests; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$autoscaling_config->get_cpu or $autoscaling_config->get_requests
MC/DC0%0/2
$autoscaling_config->get_cpu or $autoscaling_config->get_requests
$autoscaling_config->get_cpu
$autoscaling_config->get_requests
Truth table0%0/3
A or B
A= $autoscaling_config->get_cpuB= $autoscaling_config->get_requests
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $policy_configuration = $self->create_policy_configuration( $task_name, $autoscaling_config ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( !$scaling_policy ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->log_warn( 'autoscaling: policy: [%s] does not exist...will be created...%s', $policy_name, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | $self->inc_required_resources( | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | 'autoscaling:scaling-policy' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ($dryrun) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return $dryrun ? 'arn:???' : $autoscaling_config->get_policy_arn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $arn = $self->create_autoscaling_policy( | |||||||||||||||||||||||||||||||||||||||||
| 99 | app_autoscaling => $app_autoscaling, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | min_capacity => $autoscaling_config->get_min_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | max_capacity => $autoscaling_config->get_max_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | policy_name => $policy_name, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | policy_configuration => $policy_configuration, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $autoscaling_config->update( policy_arn => $arn ); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $current_policy = $scaling_policy->{TargetTrackingScalingPolicyConfiguration}; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $diffs = $self->display_diffs( $policy_configuration, $current_policy ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($diffs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->log_error( "autoscaling: scaling policy: [%s] has changed:\n%s\n", $policy_name, $diffs ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | log_die( $self, 'autoscaling: aborting update...use --force to force update' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | if !$self->get_force; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->log_warn( 'autoscaling: scaling policy: [%s] will be updated...%s', $policy_name, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $arn = $self->create_autoscaling_policy( | |||||||||||||||||||||||||||||||||||||||||
| 127 | app_autoscaling => $app_autoscaling, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | min_capacity => $autoscaling_config->get_min_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | max_capacity => $autoscaling_config->get_max_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | policy_name => $policy_name, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | policy_configuration => $policy_configuration, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $autoscaling_config->update( policy_arn => $arn ); # the arn should not change, but why not? | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $self->log_info( 'autoscaling: scaling policy: [%s] has not changed...skipping', $policy_name ); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->inc_existing_resources( autoscaling => $autoscaling_config->get_policy_arn ); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub _resource_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resource_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return sprintf 'service/%s/%s', $self->get_config->{cluster}->{name}, $task_name; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub create_policy_configuration { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_policy_configuration: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my ( $self, $task_name, $autoscaling_config ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $scale_in_cooldown = $autoscaling_config->get_scale_in_cooldown; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $scale_out_cooldown = $autoscaling_config->get_scale_out_cooldown; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $metric = $autoscaling_config->get_metric; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $metric_value = $autoscaling_config->get_metric_value; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | my $predefined_metric_type = { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | cpu => 'ECSServiceAverageCPUUtilization', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | requests => 'ALBRequestCountPerTarget', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | }->{$metric}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $resource_label = $metric eq 'requests' ? $self->create_resource_label($task_name) : q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my $predefined_metric_specficiation = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | PredefinedMetricType => $predefined_metric_type, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | $resource_label ? ( ResourceLabel => $resource_label ) : () | ||||||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $policy_configuration = { | |||||||||||||||||||||||||||||||||||||||||
| 178 | TargetValue => $metric_value, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | PredefinedMetricSpecification => $predefined_metric_specficiation, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ScaleOutCooldown => $scale_out_cooldown, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ScaleInCooldown => $scale_in_cooldown, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | $self->log_debug( | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return Dumper( | |||||||||||||||||||||||||||||||||||||||||
| 187 | [ policy_configuration => $policy_configuration, | ||||||||||||||||||||||||||||||||||||||||||
| 188 | metric => $metric, | ||||||||||||||||||||||||||||||||||||||||||
| 189 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return $policy_configuration; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub create_resource_label { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_resource_label: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $task = $config->{tasks}->{$task_name}; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $target_arn = $task->{target_group_arn}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my ($tg_part) = $target_arn =~ /(targetgroup\/.*)$/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $alb_arn = $config->{alb}->{arn}; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my ($alb_part) = $alb_arn =~ /loadbalancer\/(.*)$/xsm; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | return sprintf '%s/%s', $alb_part, $tg_part; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub create_autoscaling_policy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_autoscaling_policy: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | my ( $resource_id, $min_capacity, $max_capacity, $policy_name, $policy_configuration, $app_autoscaling ) | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | = @args{qw(resource_id min_capacity max_capacity policy_name policy_configuration app_autoscaling)}; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $query = sprintf 'ScalableTargets[?ResourceId == `%s`]|[0]', $resource_id; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $scalable_targets = $app_autoscaling->describe_scalable_targets( service_namespace => 'ecs', query => $query ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not describe scalable targets for: [%s]', $resource_id ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ( !$scalable_targets ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $app_autoscaling->register_scalable_target( | |||||||||||||||||||||||||||||||||||||||||
| 232 | service_namespace => 'ecs', | ||||||||||||||||||||||||||||||||||||||||||
| 233 | scalable_dimension => 'ecs:service:DesiredCount', | ||||||||||||||||||||||||||||||||||||||||||
| 234 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 235 | min_capacity => $min_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 236 | max_capacity => $max_capacity, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not register scalable target for: [%s]', $resource_id ); | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $scaling_policy = $app_autoscaling->put_scaling_policy( | |||||||||||||||||||||||||||||||||||||||||
| 243 | policy_name => $policy_name, | ||||||||||||||||||||||||||||||||||||||||||
| 244 | service_namespace => 'ecs', | ||||||||||||||||||||||||||||||||||||||||||
| 245 | scalable_dimension => 'ecs:service:DesiredCount', | ||||||||||||||||||||||||||||||||||||||||||
| 246 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | policy_type => 'TargetTrackingScaling', | ||||||||||||||||||||||||||||||||||||||||||
| 248 | policy_configuration => encode_json($policy_configuration), | ||||||||||||||||||||||||||||||||||||||||||
| 249 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not create scaling policy target for: [%s]', $resource_id ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return $scaling_policy->{PolicyARN}; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub build_scheduled_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_scheduled_actions: not called CC=21 SCAR=61.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | my ( $task, $resource_id, $app_autoscaling, $autoscaling_config ) | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | = @args{qw(task resource_id app_autoscaling autoscaling_config)}; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $dryrun = $self->get_dryrun; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $parsed_actions = $autoscaling_config->get_scheduled_actions; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # configured actions, could be new or existing | ||||||||||||||||||||||||||||||||||||||||||
| 272 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my @actions = keys %{$parsed_actions}; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 276 | # fetch existing scheduled actions | ||||||||||||||||||||||||||||||||||||||||||
| 277 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $schedules = $app_autoscaling->describe_scheduled_actions( service_namespace => 'ecs' ); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not describe scheduled actions' ); | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | my $scheduled_actions = { map { ( $_->{ScheduledActionName} => $_ ) } @{ $schedules->{ScheduledActions} // [] } }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$schedules->{"ScheduledActions"} // []
MC/DC0%0/1
$schedules->{"ScheduledActions"} // []
$schedules->{"ScheduledActions"}
Truth table0%0/2
A
A= $schedules->{"ScheduledActions"}
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my @scheduled_action_names = keys %{$scheduled_actions}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # collect new scheduled actions... | ||||||||||||||||||||||||||||||||||||||||||
| 287 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my %put_scheduled_actions; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | foreach my $action_name (@actions) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $action = $parsed_actions->{$action_name}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ( none { $_ =~ /$action_name/xsm } @scheduled_action_names ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->log_warn( 'autoscaling: schedule action: [%s] does not exist...will be created...%s', $action_name, $dryrun ); | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->inc_required_resources( 'autoscaling:scheduled-action' => $action_name ); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | $self->log_debug( sub { return Dumper( [ action => $action ] ) } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $put_scheduled_actions{$action_name} = $action; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my @existing_actions = grep { $_ =~ /$action_name/xsm } @scheduled_action_names; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | foreach (@existing_actions) { | |||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $target_action = $scheduled_actions->{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $min_capacity = $target_action->{ScalableTargetAction}->{MinCapacity}; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $max_capacity = $target_action->{ScalableTargetAction}->{MaxCapacity}; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $schedule = $target_action->{Schedule}; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | my $scale_type = $target_action->{ScheduledActionName} =~ /\-in\-/xsm ? 'ScaleIn' : 'ScaleOut'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ( $schedule eq $action->{$scale_type}->{Schedule} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$schedule eq $action->{$scale_type}{"Schedule"} and $min_capacity == $action->{$scale_type}{"Action"}{"MinCapacity"} and $max_capacity == $action->{$scale_type}{"Action"}{"MaxCapacity"}
$schedule eq $action->{$scale_type}{"Schedule"} and $min_capacity == $action->{$scale_type}{"Action"}{"MinCapacity"}
MC/DC0%0/3
$schedule eq $action->{$scale_type}{"Schedule"} and $min_capacity == $action->{$scale_type}{"Action"}{"MinCapacity"} and $max_capacity == $action->{$scale_type}{"Action"}{"MaxCapacity"}
$schedule eq $action->{$scale_type}{"Schedule"}
$min_capacity == $action->{$scale_type}{"Action"}{"MinCapacity"}
$max_capacity == $action->{$scale_type}{"Action"}{"MaxCapacity"}
Truth table0%0/4
A and B and C
A= $schedule eq $action->{$scale_type}{"Schedule"}B= $min_capacity == $action->{$scale_type}{"Action"}{"MinCapacity"}C= $max_capacity == $action->{$scale_type}{"Action"}{"MaxCapacity"}
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | && $min_capacity == $action->{$scale_type}->{Action}->{MinCapacity} | ||||||||||||||||||||||||||||||||||||||||||
| 316 | && $max_capacity == $action->{$scale_type}->{Action}->{MaxCapacity} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $self->log_info( 'autoscaling: scheduled action: [%s] for [%s] has not changed...skipping', $action_name, $scale_type ); | |||||||||||||||||||||||||||||||||||||||||
| 319 | $self->inc_existing_resources( | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 'autoscaling:scheduled' => [ | ||||||||||||||||||||||||||||||||||||||||||
| 321 | join "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 322 | sprintf '%s min_capacity:%s max_capacity: %s', $target_action->{Schedule}, | ||||||||||||||||||||||||||||||||||||||||||
| 323 | $target_action->{ScalableTargetAction}->{MinCapacity}, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | $target_action->{ScalableTargetAction}->{MaxCapacity} | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ] | |||||||||||||||||||||||||||||||||||||||||
| 327 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->log_warn( 'autoscaling: scheduled action: [%s] for [%s] has changed...will be updated...%s', | |||||||||||||||||||||||||||||||||||||||||
| 332 | $action_name, $scale_type, $dryrun ); | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $self->inc_required_resources( 'autoscaling:scheduled-action' => $action_name ); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $put_scheduled_actions{$action_name} = $action; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # Sanity check the top-level metric based capacities and scheduled actions min/max capacities | ||||||||||||||||||||||||||||||||||||||||||
| 341 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ( !$autoscaling_config->get_cpu && !$autoscaling_config->get_requests ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$autoscaling_config->get_cpu || $autoscaling_config->get_requests
MC/DC0%0/2
$autoscaling_config->get_cpu || $autoscaling_config->get_requests
$autoscaling_config->get_cpu
$autoscaling_config->get_requests
Truth table0%0/3
A || B
A= $autoscaling_config->get_cpuB= $autoscaling_config->get_requests
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # Rule: 1 If no metric scaling action exists, min/max should be equal | ||||||||||||||||||||||||||||||||||||||||||
| 345 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $error_msg = <<'END_OF_ERROR_MESSAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 347 | ERROR: Configuration for schedule '%s' is inconsistent. | ||||||||||||||||||||||||||||||||||||||||||
| 348 | It defines a min_capacity (%d) that is different from its max_capacity (%d) | ||||||||||||||||||||||||||||||||||||||||||
| 349 | for its 'in' period, but no metric-based scaling policy (cpu or requests) has been defined. | ||||||||||||||||||||||||||||||||||||||||||
| 350 | Without a metric policy, the service can only scale to the minimum capacity and will never reach the maximum. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | To resolve this, please set min_capacity and max_capacity to the same value for a fixed-capacity schedule. | ||||||||||||||||||||||||||||||||||||||||||
| 352 | END_OF_ERROR_MESSAGE | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | foreach my $p ( pairs %put_scheduled_actions ) { | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ( $p->[1]->{ScaleOut}->{Action}->{MinCapacity} != $p->[1]->{ScaleOut}->{Action}->{MaxCapacity} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | $self->log_die( | ||||||||||||||||||||||||||||||||||||||||||
| 357 | $error_msg, $p->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 358 | $p->[1]->{ScaleOut}->{Action}->{MinCapacity}, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | $p->[1]->{ScaleOut}->{Action}->{MaxCapacity} | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if ( $p->[1]->{ScaleIn}->{Action}->{MinCapacity} != $p->[1]->{ScaleIn}->{Action}->{MaxCapacity} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | $self->log_die( | ||||||||||||||||||||||||||||||||||||||||||
| 365 | $error_msg, $p->[0], | ||||||||||||||||||||||||||||||||||||||||||
| 366 | $p->[1]->{ScaleIn}->{Action}->{MinCapacity}, | ||||||||||||||||||||||||||||||||||||||||||
| 367 | $p->[1]->{ScaleIn}->{Action}->{MaxCapacity} | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | # presumbably existing schedules are sane...but we will check anyway | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | foreach (@scheduled_action_names) { | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $min_capacity = $scheduled_actions->{$_}->{ScalableTargetAction}{MinCapacity}; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my $max_capacity = $scheduled_actions->{$_}->{ScalableTargetAction}{MaxCapacity}; | |||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | log_die( $self, $error_msg, $min_capacity, $max_capacity ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | if $min_capacity != $max_capacity; | ||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # Rule 2: top-level max_capacity >= scheduled action max capacity | ||||||||||||||||||||||||||||||||||||||||||
| 384 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $error_msg = <<'END_OF_ERROR_MESSAGE'; | |||||||||||||||||||||||||||||||||||||||||
| 386 | ERROR: Configuration for a scheduled action is inconsistent. | ||||||||||||||||||||||||||||||||||||||||||
| 387 | It defines a max_capacity (%d) that is greater than the top-level max_capacity (%d). | ||||||||||||||||||||||||||||||||||||||||||
| 388 | In App::FargateStack, the top-level 'max_capacity' is the absolute ceiling for the service at all times. | ||||||||||||||||||||||||||||||||||||||||||
| 389 | To resolve this, please set the top-level 'max_capacity' to the highest value your service should ever scale to (%d or greater). | ||||||||||||||||||||||||||||||||||||||||||
| 390 | END_OF_ERROR_MESSAGE | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $min_capacity = $autoscaling_config->get_min_capacity; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $max_capacity = $autoscaling_config->get_max_capacity; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | # new action max takes precendent over existing action max capacity | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $max_scheduled_capacity; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | foreach ( uniq @scheduled_action_names, keys %put_scheduled_actions ) { | |||||||||||||||||||||||||||||||||||||||||
| 399 | $max_scheduled_capacity | ||||||||||||||||||||||||||||||||||||||||||
| 400 | = max exists $put_scheduled_actions{$_} | ||||||||||||||||||||||||||||||||||||||||||
| 401 | ? $put_scheduled_actions{$_}{ScaleOut}{Action}{MaxCapacity} | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | : $scheduled_actions->{$_}->{ScalableTargetAction}{MaxCapacity}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if ( $max_capacity < $max_scheduled_capacity ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $self->log_die( $error_msg, $max_scheduled_capacity, $max_capacity, $max_scheduled_capacity ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | if ( !$dryrun ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | foreach my $p ( pairs %put_scheduled_actions ) { | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my ( $action_name, $action ) = @{$p}; | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | $self->put_scheduled_action( | ||||||||||||||||||||||||||||||||||||||||||
| 415 | name => $action_name . '-out', | ||||||||||||||||||||||||||||||||||||||||||
| 416 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | action => $action->{ScaleOut}->{Action}, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | schedule => $action->{ScaleOut}->{Schedule}, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | $self->put_scheduled_action( | ||||||||||||||||||||||||||||||||||||||||||
| 422 | name => $action_name . '-in', | ||||||||||||||||||||||||||||||||||||||||||
| 423 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | action => $action->{ScaleIn}->{Action}, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | schedule => $action->{ScaleIn}->{Schedule}, | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 434 | aws application-autoscaling put-scheduled-action \ | ||||||||||||||||||||||||||||||||||||||||||
| 435 | --service-namespace ecs \ | ||||||||||||||||||||||||||||||||||||||||||
| 436 | --resource-id service/app-fargatestack-website-cluster/apache \ | ||||||||||||||||||||||||||||||||||||||||||
| 437 | --scalable-dimension ecs:service:DesiredCount \ | ||||||||||||||||||||||||||||||||||||||||||
| 438 | --schedule 'cron(0 18 ? * MON-FRI *)' \ | ||||||||||||||||||||||||||||||||||||||||||
| 439 | --scheduled-action-name foo \ | ||||||||||||||||||||||||||||||||||||||||||
| 440 | --scalable-target-action '{"MinCapacity":1, "MaxCapacity":2}' | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub put_scheduled_action { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_scheduled_action: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my ( $action_name, $resource_id, $schedule, $action ) = @args{qw(name resource_id schedule action)}; | |||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $app_autoscaling = $self->fetch_application_autoscaling; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $result = $app_autoscaling->put_scheduled_action( | |||||||||||||||||||||||||||||||||||||||||
| 454 | resource_id => $resource_id, | ||||||||||||||||||||||||||||||||||||||||||
| 455 | schedule => $schedule, | ||||||||||||||||||||||||||||||||||||||||||
| 456 | scalable_target_action => encode_json($action), | ||||||||||||||||||||||||||||||||||||||||||
| 457 | name => $self->create_default( 'scheduled-action-name', $action_name ), | ||||||||||||||||||||||||||||||||||||||||||
| 458 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $app_autoscaling->check_result( message => 'ERROR: could not put scheduled event: [%s]', $action_name ); | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||