Skip to content

Commit 529e115

Browse files
committed
adding env vars and fixing windows control script
1 parent 430b098 commit 529e115

8 files changed

Lines changed: 53 additions & 52 deletions

File tree

cfg/envconfig/envconfig.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import (
1212

1313
const (
1414
//the following are the names of environment variables
15-
HTTP_PROXY = "HTTP_PROXY" //nolint:revive
16-
HTTPS_PROXY = "HTTPS_PROXY" //nolint:revive
17-
NO_PROXY = "NO_PROXY" //nolint:revive
18-
AWS_CA_BUNDLE = "AWS_CA_BUNDLE" //nolint:revive
19-
AWS_SDK_LOG_LEVEL = "AWS_SDK_LOG_LEVEL" //nolint:revive
20-
CWAGENT_USER_AGENT = "CWAGENT_USER_AGENT" //nolint:revive
21-
CWAGENT_LOG_LEVEL = "CWAGENT_LOG_LEVEL" //nolint:revive
22-
CWAGENT_ROLE = "CWAGENT_ROLE" //nolint:revive
23-
CWAGENT_USAGE_DATA = "CWAGENT_USAGE_DATA" //nolint:revive
24-
IMDS_NUMBER_RETRY = "IMDS_NUMBER_RETRY" //nolint:revive
15+
HTTP_PROXY = "HTTP_PROXY" //nolint:revive
16+
HTTPS_PROXY = "HTTPS_PROXY" //nolint:revive
17+
NO_PROXY = "NO_PROXY" //nolint:revive
18+
AWS_CA_BUNDLE = "AWS_CA_BUNDLE" //nolint:revive
19+
AWS_SDK_LOG_LEVEL = "AWS_SDK_LOG_LEVEL" //nolint:revive
20+
AWS_USE_DUALSTACK_ENDPOINT = "AWS_USE_DUALSTACK_ENDPOINT" //nolint:revive
21+
CWAGENT_USER_AGENT = "CWAGENT_USER_AGENT" //nolint:revive
22+
CWAGENT_LOG_LEVEL = "CWAGENT_LOG_LEVEL" //nolint:revive
23+
CWAGENT_ROLE = "CWAGENT_ROLE" //nolint:revive
24+
CWAGENT_USAGE_DATA = "CWAGENT_USAGE_DATA" //nolint:revive
25+
IMDS_NUMBER_RETRY = "IMDS_NUMBER_RETRY" //nolint:revive
2526
RunInContainer = "RUN_IN_CONTAINER"
2627
RunAsHostProcessContainer = "RUN_AS_HOST_PROCESS_CONTAINER"
2728
RunInAWS = "RUN_IN_AWS"

packaging/windows/amazon-cloudwatch-agent-ctl.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Function CWAConfig() {
309309
if ($ConfigLocation -eq $AllConfig) {
310310
Remove-Item -Path "${JSON_DIR}\*" -Force -ErrorAction SilentlyContinue
311311
} else {
312-
$downloader_cmd = "${CWAProgramFiles}\config-downloader.exe --output-dir `"${JSON_DIR}`" --download-source `"${ConfigLocation}`" --mode `"${param_mode}`" --config `"${COMMON_CONIG}`" --multi-config `"${multi_config}`""
312+
$downloader_cmd = "`"${CWAProgramFiles}\config-downloader.exe`" --output-dir `"${JSON_DIR}`" --download-source `"${ConfigLocation}`" --mode `"${param_mode}`" --config `"${COMMON_CONIG}`" --multi-config `"${multi_config}`""
313313
if ($d) {
314314
$downloader_cmd += " --dualstack"
315315
}
@@ -325,11 +325,11 @@ Function CWAConfig() {
325325
Remove-Item "${OTEL_YAML}" -Force -ErrorAction SilentlyContinue
326326
} else {
327327
Write-Output "Start configuration validation..."
328-
& cmd /c "`"$CWAProgramFiles\config-translator.exe`" --input ${JSON} --input-dir ${JSON_DIR} --output ${TOML} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} 2>&1"
328+
& cmd /c "`"${CWAProgramFiles}\config-translator.exe`" --input ${JSON} --input-dir ${JSON_DIR} --output ${TOML} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config} 2>&1"
329329
CheckCMDResult
330330
# Let command pass so we can check return code and give user-friendly error-message
331331
$ErrorActionPreference = "Continue"
332-
& cmd /c "`"${CWAProgramFiles}\amazon-cloudwatch-agent.exe`" --schematest --config ${TOML} 2>&1" | Out-File $CVLogFile
332+
& cmd /c "`"${CWAProgramFiles}\amazon-cloudwatch-agent.exe`" --schematest --config `"${TOML}`" 2>&1" | Out-File $CVLogFile
333333
if ($LASTEXITCODE -ne 0) {
334334
Write-Output "Configuration validation second phase failed"
335335
Write-Output "======== Error Log ========"
@@ -414,7 +414,7 @@ Function SetLogLevelAll() {
414414
}
415415
}
416416

417-
& cmd /c "`"${CWAProgramFiles}\amazon-cloudwatch-agent.exe`" --setenv CWAGENT_LOG_LEVEL=${LogLevel} --envconfig ${ENV_CONFIG} 2>&1"
417+
& cmd /c "`"${CWAProgramFiles}\amazon-cloudwatch-agent.exe`" --setenv CWAGENT_LOG_LEVEL=${LogLevel} --envconfig `"${ENV_CONFIG}`" 2>&1"
418418
CheckCMDResult "" "Set CWAGENT_LOG_LEVEL to ${LogLevel}"
419419
}
420420

tool/downloader/downloader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
configaws "github.com/aws/amazon-cloudwatch-agent/cfg/aws"
1818
"github.com/aws/amazon-cloudwatch-agent/cfg/commonconfig"
19+
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
1920
"github.com/aws/amazon-cloudwatch-agent/internal/constants"
2021
"github.com/aws/amazon-cloudwatch-agent/translator/config"
2122
"github.com/aws/amazon-cloudwatch-agent/translator/util"
@@ -66,7 +67,7 @@ func RunDownloader(mode, downloadLocation, outputDir, inputConfig, multiConfig s
6667
util.SetSSLEnv(cc.SSLMap())
6768

6869
if useDualStack {
69-
os.Setenv("AWS_USE_DUALSTACK_ENDPOINT", "true")
70+
os.Setenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT, "true")
7071
}
7172

7273
// Validate required parameters

translator/tocwconfig/toenvconfig/toEnvConfig.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ import (
1515
)
1616

1717
const (
18-
userAgentKey = "user_agent"
19-
debugKey = "debug"
20-
awsSdkLogLevelKey = "aws_sdk_log_level"
21-
usageDataKey = "usage_data"
22-
useDualStackEndpointKey = "use_dualstack_endpoint"
18+
userAgentKey = "user_agent"
19+
debugKey = "debug"
20+
awsSdkLogLevelKey = "aws_sdk_log_level"
21+
usageDataKey = "usage_data"
2322
)
2423

2524
func ToEnvConfig(jsonConfigValue map[string]interface{}) []byte {
@@ -43,13 +42,12 @@ func ToEnvConfig(jsonConfigValue map[string]interface{}) []byte {
4342
envVars[envconfig.CWAGENT_USAGE_DATA] = "FALSE"
4443
}
4544

46-
if useDualStack, ok := agentMap[useDualStackEndpointKey].(bool); ok {
45+
if useDualStack, ok := agentMap[agent.UseDualStackEndpointKey].(bool); ok {
4746
if useDualStack {
48-
envVars["AWS_USE_DUALSTACK_ENDPOINT"] = "true"
47+
envVars[envconfig.AWS_USE_DUALSTACK_ENDPOINT] = "true"
4948
} else {
50-
envVars["AWS_USE_DUALSTACK_ENDPOINT"] = "false"
49+
envVars[envconfig.AWS_USE_DUALSTACK_ENDPOINT] = "false"
5150
}
52-
} else {
5351
}
5452
}
5553

translator/tocwconfig/toenvconfig/toEnvConfig_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ func TestToEnvConfig(t *testing.T) {
6060
name: "agent section with dual-stack endpoint enabled",
6161
input: map[string]interface{}{
6262
agent.SectionKey: map[string]interface{}{
63-
useDualStackEndpointKey: true,
63+
agent.UseDualStackEndpointKey: true,
6464
},
6565
},
6666
envVars: map[string]string{},
6767
expectedEnv: map[string]string{
68-
"AWS_USE_DUALSTACK_ENDPOINT": "true",
68+
envconfig.AWS_USE_DUALSTACK_ENDPOINT: "true",
6969
},
7070
contextSetup: func() {
7171
context.CurrentContext().SetProxy(map[string]string{})
@@ -76,12 +76,12 @@ func TestToEnvConfig(t *testing.T) {
7676
name: "agent section with dual-stack endpoint disabled",
7777
input: map[string]interface{}{
7878
agent.SectionKey: map[string]interface{}{
79-
useDualStackEndpointKey: false,
79+
agent.UseDualStackEndpointKey: false,
8080
},
8181
},
8282
envVars: map[string]string{},
8383
expectedEnv: map[string]string{
84-
"AWS_USE_DUALSTACK_ENDPOINT": "false",
84+
envconfig.AWS_USE_DUALSTACK_ENDPOINT: "false",
8585
},
8686
contextSetup: func() {
8787
context.CurrentContext().SetProxy(map[string]string{})
@@ -92,20 +92,20 @@ func TestToEnvConfig(t *testing.T) {
9292
name: "combined configuration with dual-stack",
9393
input: map[string]interface{}{
9494
agent.SectionKey: map[string]interface{}{
95-
userAgentKey: "custom-agent",
96-
debugKey: true,
97-
useDualStackEndpointKey: true,
98-
awsSdkLogLevelKey: "INFO",
95+
userAgentKey: "custom-agent",
96+
debugKey: true,
97+
agent.UseDualStackEndpointKey: true,
98+
awsSdkLogLevelKey: "INFO",
9999
},
100100
},
101101
envVars: map[string]string{},
102102
expectedEnv: map[string]string{
103-
envconfig.CWAGENT_USER_AGENT: "custom-agent",
104-
envconfig.CWAGENT_LOG_LEVEL: "DEBUG",
105-
envconfig.AWS_SDK_LOG_LEVEL: "INFO",
106-
"AWS_USE_DUALSTACK_ENDPOINT": "true",
107-
envconfig.HTTP_PROXY: "http://proxy.test",
108-
envconfig.AWS_CA_BUNDLE: "/test/ca-bundle.pem",
103+
envconfig.CWAGENT_USER_AGENT: "custom-agent",
104+
envconfig.CWAGENT_LOG_LEVEL: "DEBUG",
105+
envconfig.AWS_SDK_LOG_LEVEL: "INFO",
106+
envconfig.AWS_USE_DUALSTACK_ENDPOINT: "true",
107+
envconfig.HTTP_PROXY: "http://proxy.test",
108+
envconfig.AWS_CA_BUNDLE: "/test/ca-bundle.pem",
109109
},
110110
contextSetup: func() {
111111
context.CurrentContext().SetProxy(map[string]string{
@@ -120,7 +120,7 @@ func TestToEnvConfig(t *testing.T) {
120120
name: "invalid dual-stack type string",
121121
input: map[string]interface{}{
122122
agent.SectionKey: map[string]interface{}{
123-
useDualStackEndpointKey: "true",
123+
agent.UseDualStackEndpointKey: "true",
124124
},
125125
},
126126
expectedEnv: map[string]string{},
@@ -133,7 +133,7 @@ func TestToEnvConfig(t *testing.T) {
133133
name: "invalid dual-stack type number",
134134
input: map[string]interface{}{
135135
agent.SectionKey: map[string]interface{}{
136-
useDualStackEndpointKey: 1,
136+
agent.UseDualStackEndpointKey: 1,
137137
},
138138
},
139139
expectedEnv: map[string]string{},
@@ -146,7 +146,7 @@ func TestToEnvConfig(t *testing.T) {
146146
name: "invalid dual-stack type nil",
147147
input: map[string]interface{}{
148148
agent.SectionKey: map[string]interface{}{
149-
useDualStackEndpointKey: nil,
149+
agent.UseDualStackEndpointKey: nil,
150150
},
151151
},
152152
expectedEnv: map[string]string{},

translator/translate/agent/agent.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
var ChildRule = map[string]translator.Rule{}
1313

1414
const (
15-
SectionKey = "agent"
16-
Mode = "mode"
15+
SectionKey = "agent"
16+
Mode = "mode"
17+
UseDualStackEndpointKey = "use_dualstack_endpoint"
1718
)
1819

1920
func GetCurPath() string {

translator/translate/agent/use_dualstack_endpoint.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *UseDualStackEndpoint) ApplyRule(input interface{}) (returnKey string, r
1717
return
1818
}
1919

20-
dualStackValue, exists := agentMap["use_dualstack_endpoint"]
20+
dualStackValue, exists := agentMap[UseDualStackEndpointKey]
2121
if !exists {
2222
returnKey, returnVal = "", nil
2323
return
@@ -30,10 +30,10 @@ func (r *UseDualStackEndpoint) ApplyRule(input interface{}) (returnKey string, r
3030
}
3131

3232
Global_Config.UseDualStackEndpoint = val
33-
returnKey, returnVal = "use_dualstack_endpoint", val
33+
returnKey, returnVal = UseDualStackEndpointKey, val
3434
return
3535
}
3636

3737
func init() {
38-
RegisterRule("use_dualstack_endpoint", new(UseDualStackEndpoint))
38+
RegisterRule(UseDualStackEndpointKey, new(UseDualStackEndpoint))
3939
}

translator/translate/agent/use_dualstack_endpoint_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func TestUseDualStackEndpoint_ApplyRule(t *testing.T) {
2424
}{
2525
"EnableDualStack": {
2626
input: map[string]interface{}{
27-
"use_dualstack_endpoint": true,
27+
UseDualStackEndpointKey: true,
2828
},
29-
expectedKey: "use_dualstack_endpoint",
29+
expectedKey: UseDualStackEndpointKey,
3030
expectedValue: true,
3131
expectedGlobal: true,
3232
},
3333
"DisableDualStack": {
3434
input: map[string]interface{}{
35-
"use_dualstack_endpoint": false,
35+
UseDualStackEndpointKey: false,
3636
},
37-
expectedKey: "use_dualstack_endpoint",
37+
expectedKey: UseDualStackEndpointKey,
3838
expectedValue: false,
3939
expectedGlobal: false,
4040
},
@@ -48,15 +48,15 @@ func TestUseDualStackEndpoint_ApplyRule(t *testing.T) {
4848
},
4949
"InvalidFieldTypeString": {
5050
input: map[string]interface{}{
51-
"use_dualstack_endpoint": "true",
51+
UseDualStackEndpointKey: "true",
5252
},
5353
expectedKey: "",
5454
expectedValue: translator.ErrorMessages,
5555
expectedGlobal: false,
5656
},
5757
"InvalidFieldTypeInt": {
5858
input: map[string]interface{}{
59-
"use_dualstack_endpoint": 1,
59+
UseDualStackEndpointKey: 1,
6060
},
6161
expectedKey: "",
6262
expectedValue: translator.ErrorMessages,

0 commit comments

Comments
 (0)