From b4003d79406be8e5e873915e08bd8d59b086e455 Mon Sep 17 00:00:00 2001 From: naoki kuroda <68233204+nnnkkk7@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:43:33 +0900 Subject: [PATCH] cache listeners on routing stage for later use (#4599) * cache current listeners for later use Signed-off-by: nnnkkk7 * get listeners from cache Signed-off-by: nnnkkk7 * use currListenerArns instead of addedListeners Signed-off-by: nnnkkk7 --------- Signed-off-by: nnnkkk7 --- pkg/app/piped/executor/ecs/ecs.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/app/piped/executor/ecs/ecs.go b/pkg/app/piped/executor/ecs/ecs.go index a3e643f2f4..c0d871c231 100644 --- a/pkg/app/piped/executor/ecs/ecs.go +++ b/pkg/app/piped/executor/ecs/ecs.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "strconv" + "strings" "github.com/aws/aws-sdk-go-v2/service/ecs/types" "go.uber.org/zap" @@ -38,6 +39,7 @@ const ( trafficRoutePrimaryMetadataKey = "primary-percentage" trafficRouteCanaryMetadataKey = "canary-percentage" canaryScaleMetadataKey = "canary-scale" + currentListenersKey = "current-listeners" ) type registerer interface { @@ -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 }