Skip to content

Commit d137010

Browse files
niladrix719Warashi
andauthored
ECS: Add UI Logs for Listener Rules in TRAFFIC_ROUTING and ROLLBACK (#5842)
* ECS: Add UI Logs for Listener Rules in TRAFFIC_ROUTING and ROLLBACK Signed-off-by: “niladrix719” <[email protected]> * resolved conflicts Signed-off-by: “niladrix719” <[email protected]> * applied requested changes Signed-off-by: “niladrix719” <[email protected]> * fix: lint Signed-off-by: “niladrix719” <[email protected]> * added note for ModifyListeners method Signed-off-by: “niladrix719” <[email protected]> * Update pkg/app/piped/platformprovider/ecs/client.go Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]> Signed-off-by: Niladri Adhikary <[email protected]> --------- Signed-off-by: “niladrix719” <[email protected]> Signed-off-by: Niladri Adhikary <[email protected]> Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
1 parent c3d15b3 commit d137010

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

pkg/app/piped/executor/ecs/ecs.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,34 @@ func routing(ctx context.Context, in *executor.Input, platformProviderName strin
505505
return false
506506
}
507507

508-
if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
508+
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg)
509+
if err != nil {
509510
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)
511+
512+
if len(modifiedRules) > 0 {
513+
logModifiedRules(in.LogPersister, modifiedRules)
514+
}
510515
return false
511516
}
512517

518+
logModifiedRules(in.LogPersister, modifiedRules)
519+
513520
return true
514521
}
522+
523+
// Logs information about modified ELB listener rules.
524+
func logModifiedRules(logPersister executor.LogPersister, modifiedRules []string) {
525+
if len(modifiedRules) == 0 {
526+
logPersister.Info("No ELB listener rules were modified")
527+
return
528+
}
529+
530+
if len(modifiedRules) == 1 {
531+
logPersister.Infof("Modified ELB listener rule: %s", modifiedRules[0])
532+
} else {
533+
logPersister.Infof("Modified %d ELB listener rules:", len(modifiedRules))
534+
for _, rule := range modifiedRules {
535+
logPersister.Infof(" - %s", rule)
536+
}
537+
}
538+
}

pkg/app/piped/executor/ecs/rollback.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,18 @@ func rollbackELB(ctx context.Context, in *executor.Input, client provider.Client
194194
return false
195195
}
196196

197-
if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
197+
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg)
198+
if err != nil {
198199
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)
200+
201+
if len(modifiedRules) > 0 {
202+
logModifiedRules(in.LogPersister, modifiedRules)
203+
}
199204
return false
200205
}
201206

207+
logModifiedRules(in.LogPersister, modifiedRules)
208+
202209
in.LogPersister.Infof("Successfully rolled back ELB listeners of target groups %s (PRIMARY) and %s (CANARY)", *primaryTargetGroup.TargetGroupArn, canaryTargetGroupArn)
203210
return true
204211
}

pkg/app/piped/platformprovider/ecs/client.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,19 @@ func (c *client) getLoadBalancerArn(ctx context.Context, targetGroupArn string)
472472
return output.TargetGroups[0].LoadBalancerArns[0], nil
473473
}
474474

475-
func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) error {
475+
func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) ([]string, error) {
476476
if len(routingTrafficCfg) != 2 {
477-
return fmt.Errorf("invalid listener configuration: requires 2 target groups")
477+
return nil, fmt.Errorf("invalid listener configuration: requires 2 target groups")
478478
}
479479

480+
modifiedRuleArns := make([]string, 0)
481+
480482
for _, listenerArn := range listenerArns {
481483
describeRulesOutput, err := c.elbClient.DescribeRules(ctx, &elasticloadbalancingv2.DescribeRulesInput{
482484
ListenerArn: aws.String(listenerArn),
483485
})
484486
if err != nil {
485-
return fmt.Errorf("failed to describe rules of listener %s: %w", listenerArn, err)
487+
return modifiedRuleArns, fmt.Errorf("failed to describe rules of listener %s: %w", listenerArn, err)
486488
}
487489

488490
for _, rule := range describeRulesOutput.Rules {
@@ -519,20 +521,22 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou
519521
DefaultActions: modifiedActions,
520522
})
521523
if err != nil {
522-
return fmt.Errorf("failed to modify default rule %s: %w", *rule.RuleArn, err)
524+
return modifiedRuleArns, fmt.Errorf("failed to modify default rule %s: %w", *rule.RuleArn, err)
523525
}
526+
modifiedRuleArns = append(modifiedRuleArns, fmt.Sprintf("default rule of listener %s", listenerArn))
524527
} else {
525528
_, err := c.elbClient.ModifyRule(ctx, &elasticloadbalancingv2.ModifyRuleInput{
526529
RuleArn: rule.RuleArn,
527530
Actions: modifiedActions,
528531
})
529532
if err != nil {
530-
return fmt.Errorf("failed to modify rule %s: %w", *rule.RuleArn, err)
533+
return modifiedRuleArns, fmt.Errorf("failed to modify rule %s: %w", *rule.RuleArn, err)
531534
}
535+
modifiedRuleArns = append(modifiedRuleArns, *rule.RuleArn)
532536
}
533537
}
534538
}
535-
return nil
539+
return modifiedRuleArns, nil
536540
}
537541

538542
func (c *client) TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error {

pkg/app/piped/platformprovider/ecs/ecs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ type ELB interface {
6666
GetListenerArns(ctx context.Context, targetGroup types.LoadBalancer) ([]string, error)
6767
// ModifyListeners modifies the actions of type ActionTypeEnumForward to perform routing traffic
6868
// to the given target groups. Other actions won't be modified.
69-
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) error
69+
// Note: This method will return any successfully modified rule ARNs even when returning an error.
70+
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) (modifiedRuleArns []string, err error)
7071
}
7172

7273
// Registry holds a pool of aws client wrappers.

0 commit comments

Comments
 (0)