Skip to content

Commit eaf1934

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

14 files changed

Lines changed: 335 additions & 68 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: 1 addition & 1 deletion
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
}

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

tool/downloader/downloader_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func TestRunDownloaderFromFlags_DualStackFlag(t *testing.T) {
3232

3333
for _, tt := range tests {
3434
t.Run(tt.name, func(t *testing.T) {
35-
// Create mock flags
3635
flags := map[string]*string{
3736
"mode": stringPtr("ec2"),
3837
"download-source": stringPtr("default"),
@@ -42,9 +41,6 @@ func TestRunDownloaderFromFlags_DualStackFlag(t *testing.T) {
4241
"dualstack": stringPtr(tt.dualStackValue),
4342
}
4443

45-
// Test that the flag parsing works correctly
46-
// We can't easily test the full RunDownloader function without mocking AWS services,
47-
// but we can test that the flag conversion logic works
4844
result := *flags["dualstack"] == "true"
4945
if result != tt.expectedResult {
5046
t.Errorf("Expected dualstack flag conversion to be %v, got %v", tt.expectedResult, result)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[agent]
2+
collection_jitter = "0s"
3+
debug = false
4+
flush_interval = "1s"
5+
flush_jitter = "0s"
6+
hostname = ""
7+
interval = "60s"
8+
logfile = "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
9+
logtarget = "lumberjack"
10+
metric_batch_size = 1000
11+
metric_buffer_limit = 10000
12+
omit_hostname = false
13+
precision = ""
14+
quiet = false
15+
round_interval = false
16+
use_dualstack_endpoint = true
17+
18+
[inputs]
19+
20+
[[inputs.cpu]]
21+
collect_cpu_time = true
22+
fieldpass = ["usage_idle", "usage_nice", "usage_guest", "time_active", "usage_active"]
23+
interval = "10s"
24+
percpu = true
25+
report_active = true
26+
totalcpu = false
27+
[inputs.cpu.tags]
28+
"aws:StorageResolution" = "true"
29+
d1 = "foo"
30+
d2 = "bar"
31+
32+
[outputs]
33+
34+
[[outputs.cloudwatch]]
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"agent": {
3+
"region": "us-west-2",
4+
"use_dualstack_endpoint": true
5+
},
6+
"metrics": {
7+
"metrics_destinations": {
8+
"amp": {
9+
"workspace_id": "ws-12345"
10+
},
11+
"cloudwatch": {
12+
}
13+
},
14+
"metrics_collected": {
15+
"cpu": {
16+
"resources": [
17+
"*"
18+
],
19+
"drop_original_metrics": [
20+
"cpu_usage_idle",
21+
"time_active"
22+
],
23+
"measurement": [
24+
{
25+
"name": "cpu_usage_idle",
26+
"rename": "CPU_USAGE_IDLE",
27+
"unit": "unit"
28+
},
29+
{
30+
"name": "cpu_usage_nice",
31+
"unit": "unit"
32+
},
33+
"cpu_usage_guest",
34+
"time_active",
35+
"usage_active"
36+
],
37+
"totalcpu": false,
38+
"metrics_collection_interval": 10,
39+
"append_dimensions": {
40+
"d1": "foo",
41+
"d2": "bar"
42+
}
43+
}
44+
},
45+
"append_dimensions": {
46+
"ImageId": "${aws:ImageId}",
47+
"InstanceId": "${aws:InstanceId}",
48+
"InstanceType": "${aws:InstanceType}",
49+
"AutoScalingGroupName": "${aws:AutoScalingGroupName}"
50+
},
51+
"aggregation_dimensions": [
52+
[
53+
"ImageId"
54+
],
55+
[
56+
"InstanceId",
57+
"InstanceType"
58+
],
59+
[
60+
"d1"
61+
],
62+
[]
63+
]
64+
}
65+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
exporters:
2+
awscloudwatch:
3+
drop_original_metrics:
4+
CPU_USAGE_IDLE: true
5+
cpu_time_active: true
6+
force_flush_interval: 1m0s
7+
max_datums_per_call: 1000
8+
max_values_per_datum: 150
9+
middleware: agenthealth/metrics
10+
namespace: CWAgent
11+
region: us-west-2
12+
resource_to_telemetry_conversion:
13+
enabled: true
14+
rollup_dimensions:
15+
- - ImageId
16+
- - InstanceId
17+
- InstanceType
18+
- - d1
19+
- []
20+
prometheusremotewrite/amp:
21+
add_metric_suffixes: true
22+
auth:
23+
authenticator: sigv4auth
24+
endpoint: https://aps-workspaces.us-west-2.api.aws/workspaces/ws-12345/api/v1/remote_write
25+
idle_conn_timeout: 1m30s
26+
max_batch_size_bytes: 3000000
27+
max_idle_conns: 100
28+
namespace: ""
29+
remote_write_queue:
30+
enabled: true
31+
num_consumers: 5
32+
queue_size: 10000
33+
resource_to_telemetry_conversion:
34+
clear_after_copy: true
35+
enabled: true
36+
retry_on_failure:
37+
enabled: true
38+
initial_interval: 50ms
39+
max_elapsed_time: 5m0s
40+
max_interval: 30s
41+
multiplier: 1.5
42+
randomization_factor: 0.5
43+
send_metadata: false
44+
target_info:
45+
enabled: true
46+
timeout: 5s
47+
write_buffer_size: 524288
48+
extensions:
49+
agenthealth/metrics:
50+
is_usage_data_enabled: true
51+
stats:
52+
operations:
53+
- PutMetricData
54+
usage_flags:
55+
mode: EC2
56+
region_type: ACJ
57+
agenthealth/statuscode:
58+
is_status_code_enabled: true
59+
is_usage_data_enabled: true
60+
stats:
61+
usage_flags:
62+
mode: EC2
63+
region_type: ACJ
64+
entitystore:
65+
mode: ec2
66+
region: us-west-2
67+
sigv4auth:
68+
assume_role:
69+
sts_region: us-west-2
70+
region: us-west-2
71+
processors:
72+
awsentity/resource:
73+
entity_type: Resource
74+
platform: ec2
75+
scrape_datapoint_attribute: true
76+
batch/host/amp:
77+
metadata_cardinality_limit: 1000
78+
send_batch_max_size: 0
79+
send_batch_size: 8192
80+
timeout: 1m0s
81+
deltatocumulative/host/amp:
82+
max_stale: 336h0m0s
83+
max_streams: 9223372036854775807
84+
ec2tagger:
85+
ec2_instance_tag_keys:
86+
- AutoScalingGroupName
87+
ec2_metadata_tags:
88+
- ImageId
89+
- InstanceId
90+
- InstanceType
91+
imds_retries: 1
92+
middleware: agenthealth/statuscode
93+
refresh_tags_interval: 0s
94+
refresh_volumes_interval: 0s
95+
rollup:
96+
attribute_groups:
97+
- - ImageId
98+
- - InstanceId
99+
- InstanceType
100+
- - d1
101+
- []
102+
cache_size: 1000
103+
drop_original:
104+
- CPU_USAGE_IDLE
105+
- cpu_time_active
106+
transform:
107+
error_mode: propagate
108+
flatten_data: false
109+
log_statements: []
110+
metric_statements:
111+
- context: metric
112+
error_mode: propagate
113+
statements:
114+
- set(unit, "unit") where name == "cpu_usage_idle"
115+
- set(name, "CPU_USAGE_IDLE") where name == "cpu_usage_idle"
116+
- set(unit, "unit") where name == "cpu_usage_nice"
117+
trace_statements: []
118+
receivers:
119+
telegraf_cpu:
120+
collection_interval: 10s
121+
initial_delay: 1s
122+
timeout: 0s
123+
service:
124+
extensions:
125+
- agenthealth/metrics
126+
- agenthealth/statuscode
127+
- sigv4auth
128+
- entitystore
129+
pipelines:
130+
metrics/host/amp:
131+
exporters:
132+
- prometheusremotewrite/amp
133+
processors:
134+
- ec2tagger
135+
- transform
136+
- rollup
137+
- batch/host/amp
138+
- deltatocumulative/host/amp
139+
receivers:
140+
- telegraf_cpu
141+
metrics/host/cloudwatch:
142+
exporters:
143+
- awscloudwatch
144+
processors:
145+
- ec2tagger
146+
- transform
147+
- awsentity/resource
148+
receivers:
149+
- telegraf_cpu
150+
telemetry:
151+
logs:
152+
encoding: console
153+
level: info
154+
output_paths:
155+
- /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
156+
sampling:
157+
enabled: true
158+
initial: 2
159+
thereafter: 500
160+
tick: 10s
161+
metrics:
162+
level: None
163+
traces:
164+
level: None

translator/tocwconfig/tocwconfig_unix_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ func TestAMPConfig(t *testing.T) {
4040
checkTranslation(t, "amp_config_linux", "darwin", nil, "")
4141
}
4242

43+
func TestDualStackConfig(t *testing.T) {
44+
resetContext(t)
45+
context.CurrentContext().SetMode(config.ModeEC2)
46+
testutil.SetPrometheusRemoteWriteTestingEnv(t)
47+
expectedEnvVars := map[string]string{
48+
"AWS_USE_DUALSTACK_ENDPOINT": "true",
49+
}
50+
checkTranslation(t, "dualstack_config", "linux", expectedEnvVars, "")
51+
}
52+
4353
func TestJMXConfigLinux(t *testing.T) {
4454
resetContext(t)
4555
context.CurrentContext().SetMode(config.ModeEC2)

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

0 commit comments

Comments
 (0)