Skip to content

ECS: Add UI Logs for Listener Rules in TRAFFIC_ROUTING and ROLLBACK #5842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,34 @@ func routing(ctx context.Context, in *executor.Input, platformProviderName strin
return false
}

if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg)
if err != nil {
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)

if len(modifiedRules) > 0 {
logModifiedRules(in.LogPersister, modifiedRules)
}
return false
}

logModifiedRules(in.LogPersister, modifiedRules)

return true
}

// Logs information about modified ELB listener rules.
func logModifiedRules(logPersister executor.LogPersister, modifiedRules []string) {
if len(modifiedRules) == 0 {
logPersister.Info("No ELB listener rules were modified")
return
}

if len(modifiedRules) == 1 {
logPersister.Infof("Modified ELB listener rule: %s", modifiedRules[0])
} else {
logPersister.Infof("Modified %d ELB listener rules:", len(modifiedRules))
for _, rule := range modifiedRules {
logPersister.Infof(" - %s", rule)
}
}
}
9 changes: 8 additions & 1 deletion pkg/app/piped/executor/ecs/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,18 @@ func rollbackELB(ctx context.Context, in *executor.Input, client provider.Client
return false
}

if err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg); err != nil {
modifiedRules, err := client.ModifyListeners(ctx, currListenerArns, routingTrafficCfg)
if err != nil {
in.LogPersister.Errorf("Failed to routing traffic to PRIMARY/CANARY variants: %v", err)

if len(modifiedRules) > 0 {
logModifiedRules(in.LogPersister, modifiedRules)
}
return false
}

logModifiedRules(in.LogPersister, modifiedRules)

in.LogPersister.Infof("Successfully rolled back ELB listeners of target groups %s (PRIMARY) and %s (CANARY)", *primaryTargetGroup.TargetGroupArn, canaryTargetGroupArn)
return true
}
16 changes: 10 additions & 6 deletions pkg/app/piped/platformprovider/ecs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,19 @@ func (c *client) getLoadBalancerArn(ctx context.Context, targetGroupArn string)
return output.TargetGroups[0].LoadBalancerArns[0], nil
}

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

modifiedRuleArns := make([]string, 0)

for _, listenerArn := range listenerArns {
describeRulesOutput, err := c.elbClient.DescribeRules(ctx, &elasticloadbalancingv2.DescribeRulesInput{
ListenerArn: aws.String(listenerArn),
})
if err != nil {
return fmt.Errorf("failed to describe rules of listener %s: %w", listenerArn, err)
return modifiedRuleArns, fmt.Errorf("failed to describe rules of listener %s: %w", listenerArn, err)
}

for _, rule := range describeRulesOutput.Rules {
Expand Down Expand Up @@ -519,20 +521,22 @@ func (c *client) ModifyListeners(ctx context.Context, listenerArns []string, rou
DefaultActions: modifiedActions,
})
if err != nil {
return fmt.Errorf("failed to modify default rule %s: %w", *rule.RuleArn, err)
return modifiedRuleArns, fmt.Errorf("failed to modify default rule %s: %w", *rule.RuleArn, err)
}
modifiedRuleArns = append(modifiedRuleArns, fmt.Sprintf("default rule of listener %s", listenerArn))
} else {
_, err := c.elbClient.ModifyRule(ctx, &elasticloadbalancingv2.ModifyRuleInput{
RuleArn: rule.RuleArn,
Actions: modifiedActions,
})
if err != nil {
return fmt.Errorf("failed to modify rule %s: %w", *rule.RuleArn, err)
return modifiedRuleArns, fmt.Errorf("failed to modify rule %s: %w", *rule.RuleArn, err)
}
modifiedRuleArns = append(modifiedRuleArns, *rule.RuleArn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In error handlings, return the current modifiedRuleArns and show UI log in order to tell which rules are modified

}
}
}
return nil
return modifiedRuleArns, nil
}

func (c *client) TagResource(ctx context.Context, resourceArn string, tags []types.Tag) error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/piped/platformprovider/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ type ELB interface {
GetListenerArns(ctx context.Context, targetGroup types.LoadBalancer) ([]string, error)
// ModifyListeners modifies the actions of type ActionTypeEnumForward to perform routing traffic
// to the given target groups. Other actions won't be modified.
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) error
// Note: This method will return any successfully modified rule ARNs even when returning an error.
ModifyListeners(ctx context.Context, listenerArns []string, routingTrafficCfg RoutingTrafficConfig) (modifiedRuleArns []string, err error)
}

// Registry holds a pool of aws client wrappers.
Expand Down