Skip to content

Commit

Permalink
[ADXT-591] Load balance fakeintake service between several ECS cluste…
Browse files Browse the repository at this point in the history
…rs (#1119)
  • Loading branch information
KevinFairise2 authored Sep 25, 2024
1 parent 7442fc4 commit 283b257
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
19 changes: 16 additions & 3 deletions resources/aws/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (

// AWS ECS
DDInfraEcsExecKMSKeyID = "aws/ecs/execKMSKeyID"
DDInfraEcsFargateFakeintakeClusterArn = "aws/ecs/fargateFakeintakeClusterArn"
DDInfraEcsFargateFakeintakeClusterArns = "aws/ecs/fargateFakeintakeClusterArns"
DDInfraEcsFakeintakeLBs = "aws/ecs/defaultfakeintakeLBs"
DDInfraEcsTaskExecutionRole = "aws/ecs/taskExecutionRole"
DDInfraEcsTaskRole = "aws/ecs/taskRole"
Expand Down Expand Up @@ -73,6 +73,7 @@ type Environment struct {

randomSubnets pulumi.StringArrayOutput
randomLBIdx pulumi.IntOutput
randomECSArn pulumi.StringOutput
}

var _ config.Env = (*Environment)(nil)
Expand Down Expand Up @@ -139,6 +140,14 @@ func NewEnvironment(ctx *pulumi.Context, options ...func(*Environment)) (Environ
}
env.randomLBIdx = shuffleLB.Result

shuffleFakeintakeECS, err := random.NewRandomShuffle(env.Ctx(), env.Namer.ResourceName("rnd-ecs"), &random.RandomShuffleArgs{
Inputs: pulumi.ToStringArray(env.DefaultFakeintakeECSArns()),
ResultCount: pulumi.IntPtr(1),
}, env.WithProviders(config.ProviderRandom))
if err != nil {
return Environment{}, err
}
env.randomECSArn = shuffleFakeintakeECS.Results.Index(pulumi.Int(0))
return env, nil
}

Expand Down Expand Up @@ -201,6 +210,10 @@ func (e *Environment) DefaultSubnets() []string {
return e.GetStringListWithDefault(e.InfraConfig, DDInfraDefaultSubnetsParamName, e.envDefault.ddInfra.defaultSubnets)
}

func (e *Environment) DefaultFakeintakeECSArns() []string {
return e.GetStringListWithDefault(e.InfraConfig, DDInfraEcsFargateFakeintakeClusterArns, e.envDefault.ddInfra.ecs.fargateFakeintakeClusterArn)
}

func (e *Environment) DefaultFakeintakeLBs() []FakeintakeLBConfig {
var fakeintakeLBConfig FakeintakeLBConfig
return e.GetObjectWithDefault(e.InfraConfig, DDInfraEcsFakeintakeLBs, fakeintakeLBConfig, e.envDefault.ddInfra.ecs.defaultFakeintakeLBs).([]FakeintakeLBConfig)
Expand Down Expand Up @@ -257,8 +270,8 @@ func (e *Environment) ECSExecKMSKeyID() string {
return e.GetStringWithDefault(e.InfraConfig, DDInfraEcsExecKMSKeyID, e.envDefault.ddInfra.ecs.execKMSKeyID)
}

func (e *Environment) ECSFargateFakeintakeClusterArn() string {
return e.GetStringWithDefault(e.InfraConfig, DDInfraEcsFargateFakeintakeClusterArn, e.envDefault.ddInfra.ecs.fargateFakeintakeClusterArn)
func (e *Environment) ECSFargateFakeintakeClusterArn() pulumi.StringOutput {
return e.randomECSArn
}

func (e *Environment) ECSFakeintakeLBListenerArn() pulumi.StringOutput {
Expand Down
10 changes: 5 additions & 5 deletions resources/aws/environmentDefaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ddInfra struct {

type ddInfraECS struct {
execKMSKeyID string
fargateFakeintakeClusterArn string
fargateFakeintakeClusterArn []string
defaultFakeintakeLBs []FakeintakeLBConfig
taskExecutionRole string
taskRole string
Expand Down Expand Up @@ -108,7 +108,7 @@ func sandboxDefault() environmentDefault {

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:601427279990:key/c84f93c2-a562-4a59-a326-918fbe7235c7",
fargateFakeintakeClusterArn: "arn:aws:ecs:us-east-1:601427279990:cluster/fakeintake-ecs",
fargateFakeintakeClusterArn: []string{"arn:aws:ecs:us-east-1:601427279990:cluster/fakeintake-ecs"},
taskExecutionRole: "arn:aws:iam::601427279990:role/ecsExecTaskExecutionRole",
taskRole: "arn:aws:iam::601427279990:role/ecsExecTaskRole",
instanceProfile: "arn:aws:iam::601427279990:instance-profile/ecsInstanceRole",
Expand Down Expand Up @@ -151,7 +151,7 @@ func agentSandboxDefault() environmentDefault {

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:376334461865:key/1d1fe533-a4f1-44ee-99ec-225b44fcb9ed",
fargateFakeintakeClusterArn: "arn:aws:ecs:us-east-1:376334461865:cluster/fakeintake-ecs",
fargateFakeintakeClusterArn: []string{"arn:aws:ecs:us-east-1:376334461865:cluster/fakeintake-ecs-stress-test"},
defaultFakeintakeLBs: []FakeintakeLBConfig{
{listenerArn: "arn:aws:elasticloadbalancing:us-east-1:376334461865:listener/app/fakeintake/3bbebae6506eb8cb/eea87c947a30f106", baseHost: ".lb1.fi.sandbox.dda-testing.com"},
{listenerArn: "arn:aws:elasticloadbalancing:us-east-1:376334461865:listener/app/fakeintake2/e514320b44979d84/3df6c797d971c13b", baseHost: ".lb2.fi.sandbox.dda-testing.com"},
Expand Down Expand Up @@ -213,7 +213,7 @@ func agentQADefault() environmentDefault {

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:669783387624:key/384373bc-6d99-4d68-84b5-b76b756b0af3",
fargateFakeintakeClusterArn: "arn:aws:ecs:us-east-1:669783387624:cluster/fakeintake-ecs",
fargateFakeintakeClusterArn: []string{"arn:aws:ecs:us-east-1:669783387624:cluster/fakeintake-ecs", "arn:aws:ecs:us-east-1:669783387624:cluster/fakeintake-ecs-2", "arn:aws:ecs:us-east-1:669783387624:cluster/fakeintake-ecs-3"},
defaultFakeintakeLBs: []FakeintakeLBConfig{
{listenerArn: "arn:aws:elasticloadbalancing:us-east-1:669783387624:listener/app/fakeintake/de7956e70776e471/ddfa738893c2dc0e", baseHost: ".lb1.fi.qa.dda-testing.com"},
{listenerArn: "arn:aws:elasticloadbalancing:us-east-1:669783387624:listener/app/fakeintake2/d59e26c0a29d8567/52a83f7da0f000ee", baseHost: ".lb2.fi.qa.dda-testing.com"},
Expand Down Expand Up @@ -273,7 +273,7 @@ func tsePlaygroundDefault() environmentDefault {

ecs: ddInfraECS{
execKMSKeyID: "arn:aws:kms:us-east-1:570690476889:key/f1694e5a-bb52-42a7-b414-dfd34fbd6759",
fargateFakeintakeClusterArn: "arn:aws:ecs:us-east-1:570690476889:cluster/fakeintake-ecs",
fargateFakeintakeClusterArn: []string{"arn:aws:ecs:us-east-1:570690476889:cluster/fakeintake-ecs", "arn:aws:ecs:us-east-1:570690476889:cluster/fakeintake-ecs-2", "arn:aws:ecs:us-east-1:570690476889:cluster/fakeintake-ecs-3"},
taskExecutionRole: "arn:aws:iam::570690476889:role/ecsExecTaskExecutionRole",
taskRole: "arn:aws:iam::570690476889:role/ecsExecTaskRole",
instanceProfile: "arn:aws:iam::570690476889:instance-profile/ecsInstanceRole",
Expand Down
9 changes: 5 additions & 4 deletions scenarios/aws/fakeintake/fakeintake.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,24 @@ func NewECSFargateInstance(e aws.Environment, name string, option ...Option) (*f
// fargateSvcNoLB deploys one fakeintake container to a dedicated Fargate cluster
// Hardcoded on sandbox
func fargateSvcNoLB(e aws.Environment, namer namer.Namer, taskDef *awsxEcs.FargateTaskDefinition, fi *fakeintake.Fakeintake, opts ...pulumi.ResourceOption) error {
fargateService, err := ecs.FargateService(e, namer.ResourceName("srv"), pulumi.String(e.ECSFargateFakeintakeClusterArn()), taskDef.TaskDefinition.Arn(), nil, opts...)
fargateService, err := ecs.FargateService(e, namer.ResourceName("srv"), e.ECSFargateFakeintakeClusterArn(), taskDef.TaskDefinition.Arn(), nil, opts...)
if err != nil {
return err
}

// Hack passing taskDef.TaskDefinition.Arn() to execute apply function
// when taskDef has an ARN, thus it is defined on AWS side
output := pulumi.All(taskDef.TaskDefinition.Arn(), fargateService.Service.Name()).ApplyT(func(args []any) ([]string, error) {
output := pulumi.All(taskDef.TaskDefinition.Arn(), fargateService.Service.Name(), e.ECSFargateFakeintakeClusterArn()).ApplyT(func(args []any) ([]string, error) {
serviceName := args[1].(string)
fakeintakeECSArn := args[2].(string)
var ipAddress string
err := backoff.Retry(func() error {
e.Ctx().Log.Debug("waiting for fakeintake task private ip", nil)
ecsClient, err := ecs.NewECSClient(e.Ctx().Context(), e)
if err != nil {
return err
}
ipAddress, err = ecsClient.GetTaskPrivateIP(e.ECSFargateFakeintakeClusterArn(), serviceName)
ipAddress, err = ecsClient.GetTaskPrivateIP(fakeintakeECSArn, serviceName)
if err != nil {
return err
}
Expand Down Expand Up @@ -199,7 +200,7 @@ func fargateSvcLB(e aws.Environment, namer namer.Namer, taskDef *awsxEcs.Fargate
},
}

_, err = ecs.FargateService(e, namer.ResourceName("srv"), pulumi.String(e.ECSFargateFakeintakeClusterArn()), taskDef.TaskDefinition.Arn(), balancerArray, opts...)
_, err = ecs.FargateService(e, namer.ResourceName("srv"), e.ECSFargateFakeintakeClusterArn(), taskDef.TaskDefinition.Arn(), balancerArray, opts...)
if err != nil {
return err
}
Expand Down

0 comments on commit 283b257

Please sign in to comment.