Skip to content

Commit fc25083

Browse files
committed
ECS: Add UI Logs for Listener Rules in TRAFFIC_ROUTING and ROLLBACK
Signed-off-by: “niladrix719” <[email protected]>
1 parent 207555d commit fc25083

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,17 @@ func routing(ctx context.Context, in *executor.Input, platformProviderName strin
467467
return false
468468
}
469469

470-
if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
470+
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg);
471+
if err != nil {
471472
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)
472473
return false
473474
}
475+
476+
if len(modifiedRules) > 0 {
477+
in.LogPersister.Infof("Successfully modified ELB listener rules: %s", strings.Join(modifiedRules, ", "))
478+
} else {
479+
in.LogPersister.Info("No ELB listener rules were modified")
480+
}
474481

475482
return true
476483
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package ecs
1717
import (
1818
"context"
1919
"errors"
20+
"strings"
2021

2122
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
2223

@@ -158,10 +159,17 @@ func rollback(ctx context.Context, in *executor.Input, platformProviderName stri
158159
return false
159160
}
160161

161-
if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
162+
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg);
163+
if err != nil {
162164
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)
163165
return false
164166
}
167+
168+
if len(modifiedRules) > 0 {
169+
in.LogPersister.Infof("Successfully modified ELB listener rules: %s", strings.Join(modifiedRules, ", "))
170+
} else {
171+
in.LogPersister.Info("No ELB listener rules were modified")
172+
}
165173
}
166174

167175
// Delete previous ACTIVE taskSets

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

Lines changed: 11 additions & 7 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 nil, 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)
523-
}
524+
return nil, fmt.Errorf("failed to modify default rule %s: %w", *rule.RuleArn, err)
525+
}
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 nil, 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type ELB interface {
6464
GetListenerArns(ctx context.Context, targetGroup types.LoadBalancer) ([]string, error)
6565
// ModifyListeners modifies the actions of type ActionTypeEnumForward to perform routing traffic
6666
// to the given target groups. Other actions won't be modified.
67-
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) error
67+
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) ([]string, error)
6868
}
6969

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

0 commit comments

Comments
 (0)