Skip to content

Commit

Permalink
cache listeners on routing stage for later use (pipe-cd#4599)
Browse files Browse the repository at this point in the history
* cache current listeners for later use

Signed-off-by: nnnkkk7 <[email protected]>

* get listeners from cache

Signed-off-by: nnnkkk7 <[email protected]>

* use currListenerArns instead of addedListeners

Signed-off-by: nnnkkk7 <[email protected]>

---------

Signed-off-by: nnnkkk7 <[email protected]>
Signed-off-by: sZma5a <[email protected]>
  • Loading branch information
nnnkkk7 authored and sZma5a committed Dec 17, 2023
1 parent df4953f commit 4a7c6ec
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"go.uber.org/zap"
Expand All @@ -38,6 +39,7 @@ const (
trafficRoutePrimaryMetadataKey = "primary-percentage"
trafficRouteCanaryMetadataKey = "canary-percentage"
canaryScaleMetadataKey = "canary-scale"
currentListenersKey = "current-listeners"
)

type registerer interface {
Expand Down Expand Up @@ -439,17 +441,30 @@ func routing(ctx context.Context, in *executor.Input, platformProviderName strin
},
}

metadata := map[string]string{
metadataPercentage := map[string]string{
trafficRoutePrimaryMetadataKey: strconv.FormatInt(int64(primary), 10),
trafficRouteCanaryMetadataKey: strconv.FormatInt(int64(canary), 10),
}
if err := in.MetadataStore.Stage(in.Stage.Id).PutMulti(ctx, metadata); err != nil {
if err := in.MetadataStore.Stage(in.Stage.Id).PutMulti(ctx, metadataPercentage); err != nil {
in.Logger.Error("Failed to store traffic routing config to metadata store", zap.Error(err))
}

currListenerArns, err := client.GetListenerArns(ctx, primaryTargetGroup)
if err != nil {
in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
var currListenerArns []string
value, ok := in.MetadataStore.Shared().Get(currentListenersKey)
if ok {
currListenerArns = strings.Split(value, ",")
} else {
currListenerArns, err = client.GetListenerArns(ctx, primaryTargetGroup)
if err != nil {
in.LogPersister.Errorf("Failed to get current active listeners: %v", err)
return false
}
}

// Store created listeners to use later.
metadata := strings.Join(currListenerArns, ",")
if err := in.MetadataStore.Shared().Put(ctx, currentListenersKey, metadata); err != nil {
in.LogPersister.Errorf("Unable to store created listeners to metadata store: %v", err)
return false
}

Expand Down

0 comments on commit 4a7c6ec

Please sign in to comment.