Skip to content

Commit

Permalink
[mq] working branch - merge 5cd5adf on top of main at 6fb9eef
Browse files Browse the repository at this point in the history
{"baseBranch":"main","baseCommit":"6fb9eefe000403c2a30076356ebf2843419e4ee3","createdAt":"2024-02-15T16:05:42.141988Z","headSha":"5cd5adf35d907231c20e5ba60fbf871e6a89d660","id":"5815a90c-1987-4019-be4a-5f85ae400a30","priority":"200","pullRequestNumber":"622","queuedAt":"2024-02-15T16:05:42.137085Z","status":"STATUS_QUEUED"}
  • Loading branch information
dd-mergequeue[bot] authored Feb 15, 2024
2 parents 6f0ce02 + 5cd5adf commit ee69367
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
32 changes: 27 additions & 5 deletions components/datadog/agent/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agent
import (
"github.com/DataDog/test-infra-definitions/common/config"
"github.com/DataDog/test-infra-definitions/common/utils"
"github.com/DataDog/test-infra-definitions/components/datadog/ecsagentparams"
"github.com/DataDog/test-infra-definitions/components/datadog/fakeintake"
"github.com/DataDog/test-infra-definitions/resources/aws"

Expand All @@ -12,7 +13,12 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func ECSLinuxDaemonDefinition(e aws.Environment, name string, apiKeySSMParamName pulumi.StringInput, fakeintake *fakeintake.Fakeintake, clusterArn pulumi.StringInput) (*ecs.EC2Service, error) {
func ECSLinuxDaemonDefinition(e aws.Environment, name string, apiKeySSMParamName pulumi.StringInput, fakeintake *fakeintake.Fakeintake, clusterArn pulumi.StringInput, options ...ecsagentparams.Option) (*ecs.EC2Service, error) {
params, err := ecsagentparams.NewParams(options...)
if err != nil {
return nil, err
}

return ecs.NewEC2Service(e.Ctx, e.Namer.ResourceName(name), &ecs.EC2ServiceArgs{
Name: e.CommonNamer.DisplayName(255, pulumi.String(name)),
Cluster: clusterArn,
Expand All @@ -26,7 +32,7 @@ func ECSLinuxDaemonDefinition(e aws.Environment, name string, apiKeySSMParamName
EnableExecuteCommand: pulumi.BoolPtr(true),
TaskDefinitionArgs: &ecs.EC2ServiceTaskDefinitionArgs{
Containers: map[string]ecs.TaskDefinitionContainerDefinitionArgs{
"datadog-agent": ecsLinuxAgentSingleContainerDefinition(*e.CommonEnvironment, apiKeySSMParamName, fakeintake),
"datadog-agent": ecsLinuxAgentSingleContainerDefinition(*e.CommonEnvironment, apiKeySSMParamName, fakeintake, params),
},
ExecutionRole: &awsx.DefaultRoleWithPolicyArgs{
RoleArn: pulumi.StringPtr(e.ECSTaskExecutionRole()),
Expand Down Expand Up @@ -67,7 +73,7 @@ func ECSLinuxDaemonDefinition(e aws.Environment, name string, apiKeySSMParamName
}, e.WithProviders(config.ProviderAWS, config.ProviderAWSX))
}

func ecsLinuxAgentSingleContainerDefinition(e config.CommonEnvironment, apiKeySSMParamName pulumi.StringInput, fakeintake *fakeintake.Fakeintake) ecs.TaskDefinitionContainerDefinitionArgs {
func ecsLinuxAgentSingleContainerDefinition(e config.CommonEnvironment, apiKeySSMParamName pulumi.StringInput, fakeintake *fakeintake.Fakeintake, params *ecsagentparams.Params) ecs.TaskDefinitionContainerDefinitionArgs {
return ecs.TaskDefinitionContainerDefinitionArgs{
Cpu: pulumi.IntPtr(200),
Memory: pulumi.IntPtr(512),
Expand All @@ -79,7 +85,7 @@ func ecsLinuxAgentSingleContainerDefinition(e config.CommonEnvironment, apiKeySS
Add: pulumi.ToStringArray([]string{"SYS_ADMIN", "SYS_RESOURCE", "SYS_PTRACE", "NET_ADMIN", "NET_BROADCAST", "NET_RAW", "IPC_LOCK", "CHOWN"}),
},
},
Environment: append(ecs.TaskDefinitionKeyValuePairArray{
Environment: append(append(ecs.TaskDefinitionKeyValuePairArray{
ecs.TaskDefinitionKeyValuePairArgs{
Name: pulumi.StringPtr("DD_CHECKS_TAG_CARDINALITY"),
Value: pulumi.StringPtr("high"),
Expand Down Expand Up @@ -116,7 +122,7 @@ func ecsLinuxAgentSingleContainerDefinition(e config.CommonEnvironment, apiKeySS
Name: pulumi.StringPtr("DD_PROCESS_AGENT_ENABLED"),
Value: pulumi.StringPtr("true"),
},
}, ecsFakeintakeAdditionalEndpointsEnv(fakeintake)...),
}, ecsAgentAdditionalEndpointsEnv(params)...), ecsFakeintakeAdditionalEndpointsEnv(fakeintake)...),
Secrets: ecs.TaskDefinitionSecretArray{
ecs.TaskDefinitionSecretArgs{
Name: pulumi.String("DD_API_KEY"),
Expand Down Expand Up @@ -195,6 +201,18 @@ func ecsLinuxAgentSingleContainerDefinition(e config.CommonEnvironment, apiKeySS
}
}

func ecsAgentAdditionalEndpointsEnv(params *ecsagentparams.Params) []ecs.TaskDefinitionKeyValuePairInput {
if params == nil {
return []ecs.TaskDefinitionKeyValuePairInput{}
}

taskDefArray := []ecs.TaskDefinitionKeyValuePairInput{}
for k, v := range params.AgentServiceEnvironment {
taskDefArray = append(taskDefArray, ecs.TaskDefinitionKeyValuePairArgs{Name: pulumi.StringPtr(k), Value: pulumi.StringPtr(v)})
}
return taskDefArray
}

func ecsFakeintakeAdditionalEndpointsEnv(fakeintake *fakeintake.Fakeintake) []ecs.TaskDefinitionKeyValuePairInput {
if fakeintake == nil {
return []ecs.TaskDefinitionKeyValuePairInput{}
Expand All @@ -208,6 +226,10 @@ func ecsFakeintakeAdditionalEndpointsEnv(fakeintake *fakeintake.Fakeintake) []ec
Name: pulumi.StringPtr("DD_REMOTE_CONFIGURATION_NO_TLS_VALIDATION"),
Value: pulumi.StringPtr("true"),
},
ecs.TaskDefinitionKeyValuePairArgs{
Name: pulumi.StringPtr("DD_PROCESS_CONFIG_PROCESS_DD_URL"),
Value: pulumi.Sprintf("https://%s", fakeintake.Host),
},
ecs.TaskDefinitionKeyValuePairArgs{
Name: pulumi.StringPtr("DD_ADDITIONAL_ENDPOINTS"),
Value: pulumi.Sprintf(`{"https://%s": ["FAKEAPIKEY"]}`, fakeintake.Host),
Expand Down
33 changes: 33 additions & 0 deletions components/datadog/ecsagentparams/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ecsagentparams

import "github.com/DataDog/test-infra-definitions/common"

// Params defines the parameters for the ECS Agent installation.
// The Params configuration uses the [Functional options pattern].
//
// The available options are:
// - [WithAgentServiceEnvVariable]
//
// [Functional options pattern]: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

type Params struct {
// AgentServiceEnvironment is a map of environment variables to set in the docker compose agent service's environment.
AgentServiceEnvironment map[string]string
}

type Option = func(*Params) error

func NewParams(options ...Option) (*Params, error) {
version := &Params{
AgentServiceEnvironment: make(map[string]string),
}
return common.ApplyOption(version, options)
}

// WithAgentServiceEnvVariable set an environment variable in the docker compose agent service's environment.
func WithAgentServiceEnvVariable(key string, value string) func(*Params) error {
return func(p *Params) error {
p.AgentServiceEnvironment[key] = value
return nil
}
}

0 comments on commit ee69367

Please sign in to comment.