Skip to content

Commit 03101aa

Browse files
Merge pull request #3041 from aws-observability/update43frommain
Update43frommain
2 parents 3a9f6a2 + 39a549a commit 03101aa

File tree

4 files changed

+121
-13
lines changed

4 files changed

+121
-13
lines changed

.github/config/testcases.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
"containerinsight_eks"
1818
]
1919
},
20+
{
21+
"name": "collector-ci-amd64-1-28",
22+
"region": "us-west-2",
23+
"excluded_tests": [
24+
"containerinsight_eks"
25+
]
26+
},
27+
{
28+
"name": "collector-ci-amd64-1-29",
29+
"region": "us-west-2",
30+
"excluded_tests": [
31+
"containerinsight_eks"
32+
]
33+
},
2034
{
2135
"name": "collector-ci-amd64-1-30",
2236
"region": "us-west-2",
@@ -50,6 +64,20 @@
5064
"containerinsight_eks"
5165
]
5266
},
67+
{
68+
"name": "collector-ci-arm64-1-28",
69+
"region": "us-west-2",
70+
"excluded_tests": [
71+
"containerinsight_eks"
72+
]
73+
},
74+
{
75+
"name": "collector-ci-arm64-1-29",
76+
"region": "us-west-2",
77+
"excluded_tests": [
78+
"containerinsight_eks"
79+
]
80+
},
5381
{
5482
"name": "collector-ci-arm64-1-30",
5583
"region": "us-west-2",
@@ -77,6 +105,14 @@
77105
"name": "collector-ci-fargate-1-27",
78106
"region": "us-west-2"
79107
},
108+
{
109+
"name": "collector-ci-fargate-1-28",
110+
"region": "us-west-2"
111+
},
112+
{
113+
"name": "collector-ci-fargate-1-29",
114+
"region": "us-west-2"
115+
},
80116
{
81117
"name": "collector-ci-fargate-1-30",
82118
"region": "us-west-2"

.github/scripts/test-collector-ctl.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,33 @@ test_collector_ctl_with_samecfg_restart() {
8686
echo "${FUNCNAME[0]} ... OK"
8787
}
8888

89+
test_collector_ctl_with_featureflag() {
90+
#start collector with default config
91+
$ADOT_CTL -a start -f "-adot.exporter.datadogexporter.deprecation"
92+
93+
echo "${FUNCNAME[0]} ... OK"
94+
}
95+
96+
test_collector_ctl_with_featureflag_samecfg_restart() {
97+
#populate default conf by starting without -c
98+
$ADOT_CTL -a start -f "-adot.exporter.signalfx.deprecation"
99+
100+
#restarting with different flags and -c should start collector as expected
101+
$ADOT_CTL -a start -c "file:/opt/aws/aws-otel-collector/etc/config.yaml" -f "-adot.exporter.datadogexporter.deprecation"
102+
$ADOT_CTL -a status
103+
echo "==============================================="
104+
echo "Contents of $ENV_FILE:"
105+
cat "$ENV_FILE"
106+
echo "==============================================="
107+
echo "${FUNCNAME[0]} ... OK"
108+
}
109+
89110
setup
90111

91112
## Tests
92113
test_collector_ctl_does_not_overwrite_env
93114
test_collector_ctl_with_sed_special_chars
94115
test_collector_ctl_with_samecfg
95116
test_collector_ctl_with_samecfg_restart
117+
test_collector_ctl_with_featureflag
118+
test_collector_ctl_with_featureflag_samecfg_restart

tools/ctl/linux/aws-otel-collector-ctl.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ SYSTEMD='false'
2727

2828
UsageString="
2929
30-
usage: aws-otel-collector-ctl -a stop|start|status| [-c <config-uri>]
30+
usage: aws-otel-collector-ctl -a stop|start|status| [-c <config-uri>] [-f <feature-gate>]
3131
3232
e.g.
33-
1. start collector on onPermise host with a custom .yaml config file:
33+
1. start collector on onPremise host with a custom .yaml config file:
3434
sudo aws-otel-collector-ctl -c /tmp/config.yaml -a start
35-
2. stop the running collector
35+
2. start collector on onPremise host using featuregate:
36+
sudo aws-otel-collector-ctl -c /tmp/config.yaml -f +adot.example.featuregate -a start
37+
3. stop the running collector
3638
sudo aws-otel-collector-ctl -a stop
37-
3. query agent status:
39+
4. query agent status:
3840
sudo aws-otel-collector-ctl -a status
3941
4042
-a: action
@@ -48,6 +50,10 @@ UsageString="
4850
- https uri. E.g.: https://example.com/config
4951
- s3 uri. E.g.: s3://bucket/config
5052
53+
-f: feature-gate
54+
<feature-gates> - enable or disable feature gate
55+
- E.g.: Enabling : +adot.example.featuregate
56+
- disabling : -adot.example.featuregate
5157
"
5258

5359
aoc_config_remote_uri() {
@@ -69,7 +75,7 @@ aoc_config_local_uri() {
6975

7076

7177
if [ -n "$config" ] && [ -f "$config" ]; then
72-
# do not copy if the default congif directory is provided for the -f flag.
78+
# do not copy if the default config directory is provided for the -f flag.
7379
# copying a file to the same location produces an error.
7480
if [ ! "$config" = "$CONFDIR/config.yaml" ]; then
7581
cp "$config" $CONFDIR/config.yaml
@@ -80,6 +86,15 @@ aoc_config_local_uri() {
8086
fi
8187
}
8288

89+
aoc_config_feature_gates() {
90+
feature_gates="${1:-}"
91+
92+
sed -i '/^feature_gates=.*$/d' $ENV_FILE
93+
if [ -n "$feature_gates" ]; then
94+
echo "feature_gates=\"--feature-gates '${feature_gates}'\"" >> $ENV_FILE
95+
fi
96+
}
97+
8398
# Used in case the collector starts for the first time without a configuration parameter
8499
# Safe to run as this will not overwrite a file if one exists in default location already.
85100
aoc_ensure_default_config() {
@@ -100,6 +115,7 @@ is_remote_uri() {
100115

101116
aoc_start() {
102117
config="${1:-}"
118+
feature_gates="${2:-}"
103119

104120
# The previous configuration should be used if no configuration parameter is passed
105121
aoc_ensure_default_config
@@ -111,6 +127,11 @@ aoc_start() {
111127
fi
112128
fi
113129

130+
# Handle feature gates
131+
if [ -n "$feature_gates" ]; then
132+
aoc_config_feature_gates "$feature_gates"
133+
fi
134+
114135
if [ "${SYSTEMD}" = 'true' ]; then
115136
systemctl daemon-reload
116137
systemctl enable aws-otel-collector.service
@@ -190,6 +211,7 @@ main() {
190211
action=''
191212
mode='ec2'
192213
config_location=''
214+
feature_gates=''
193215

194216
# detect which init system is in use
195217
if [ "$(/sbin/init --version 2>/dev/null | grep -c upstart)" = 1 ]; then
@@ -205,7 +227,7 @@ main() {
205227
fi
206228

207229
OPTIND=1
208-
while getopts ":ha:c:m:" opt; do
230+
while getopts ":ha:c:m:f:" opt; do
209231
case "${opt}" in
210232
h)
211233
echo "${UsageString}"
@@ -214,6 +236,7 @@ main() {
214236
a) action="${OPTARG}" ;;
215237
c) config_location="${OPTARG}" ;;
216238
m) mode="${OPTARG}" ;;
239+
f) feature_gates="${OPTARG}" ;;
217240
\?)
218241
echo "Invalid option: -${OPTARG} ${UsageString}" >&2
219242
;;
@@ -240,7 +263,7 @@ main() {
240263

241264
case "${action}" in
242265
stop) aoc_stop ;;
243-
start) aoc_start "${config_location}" ;;
266+
start) aoc_start "${config_location}" "${feature_gates}" ;;
244267
status) aoc_status ;;
245268
# helper for rpm+deb uninstallation hooks, not expected to be called manually
246269
preun) aoc_preun ;;

tools/ctl/windows/aws-otel-collector-ctl.ps1

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Param (
1919
[Parameter(Mandatory = $false)]
2020
[string]$ConfigLocation = 'default',
2121
[Parameter(Mandatory = $false)]
22+
[string]$FeatureGates,
23+
[Parameter(Mandatory = $false)]
2224
[switch]$Start = $false,
2325
[Parameter(Mandatory = $false)]
2426
[string]$Mode = 'ec2',
@@ -37,9 +39,11 @@ $UsageString = @"
3739
e.g.
3840
1. start collector with a custom .yaml config file:
3941
aws-otel-collector-ctl.ps1 -c /tmp/config.yaml -a start
40-
2. stop the running collector:
42+
2. start collector with a custom .yaml config file:
43+
aws-otel-collector-ctl.ps1 -f +adot.example.featuregate -a start
44+
3. stop the running collector:
4145
aws-otel-collector-ctl.ps1 -a stop
42-
3. query agent status:
46+
4. query agent status:
4347
aws-otel-collector-ctl.ps1 -a status
4448
4549
-a: action
@@ -52,6 +56,10 @@ $UsageString = @"
5256
- http uri. E.g.: http://example.com/config
5357
- https uri. E.g.: https://example.com/config
5458
- s3 uri. E.g.: s3://bucket/config
59+
-f: <feature-gates>
60+
- enable or disable feature gates
61+
- E.g.: Enabling: "+adot.example.featuregate"
62+
- disabling: "-adot.example.featuregate"
5563
5664
"@
5765

@@ -86,14 +94,32 @@ Function Set-Service-Config-Uri ([string]$uri) {
8694
sc.exe config "${AOCServiceName}" binPath= "${aoc_cmd}"
8795
}
8896

97+
Function Set-Service-Config-Uri-With-FeatureGates ([string]$uri, [string]$featureGates) {
98+
Write-Output "Applying feature gate ${featureGates} "
99+
$aoc_cmd = "\""${AOCProgramFiles}\.aws-otel-collector.exe\"" --config=\""${uri}\"" --feature-gates=\""${featureGates}\"""
100+
sc.exe config "${AOCServiceName}" binPath= "${aoc_cmd}"
101+
}
102+
89103
Function Test-Remote-Uri ([string]$uri) {
90104
return $uri -match "^[a-zA-Z0-9]+://" -and $uri -notmatch "^file:"
91105
}
92106

93107
Function AOCStart() {
94108

95109
if($ConfigLocation -and $ConfigLocation -ne 'default') {
110+
111+
# Check for feature gates before configuring service
112+
if ($FeatureGates) {
96113
if (Test-Remote-Uri $ConfigLocation) {
114+
Set-Service-Config-Uri-With-FeatureGates ${ConfigLocation} ${FeatureGates}
115+
} else {
116+
# Strip file scheme in case it is present
117+
$ConfigLocation = "$ConfigLocation" -replace "^file:", ""
118+
119+
Copy-Item "${ConfigLocation}" -Destination ${ProgramFilesYAML}
120+
Set-Service-Config-Uri-With-FeatureGates ${ProgramFilesYAML} ${FeatureGates}
121+
}
122+
} elseif (Test-Remote-Uri $ConfigLocation) {
97123
Set-Service-Config-Uri ${ConfigLocation}
98124
} else {
99125
# Strip file scheme in case it is present
@@ -121,6 +147,7 @@ Function AOCStart() {
121147
& sc.exe failureflag "${AOCServiceName}" 1 | Out-Null
122148
}
123149
}
150+
124151
$svc | Start-Service
125152
}
126153

@@ -131,7 +158,6 @@ Function AOCStop() {
131158
}
132159
}
133160

134-
135161
Function AOCStatus() {
136162

137163
$timefmt=''
@@ -150,18 +176,18 @@ Function AOCStatus() {
150176
$timefmt = Get-Date -Date ${processStart} -Format "s"
151177
}
152178
}
153-
179+
154180
$status = AOCRunstatus
155181
$version = ([IO.File]::ReadAllText("${VersionFile}")).Trim()
156-
182+
157183
Write-Output "{"
158184
Write-Output " `"status`": `"${status}`","
159185
Write-Output " `"starttime`": `"${timefmt}`","
160186
Write-Output " `"version`": `"${version}`""
161187
Write-Output "}"
162188
}
163189

164-
# Translate platform status names to those used across all AOCgent's platforms
190+
# Translate platform status names to those used across all AOCAgent's platforms
165191
Function AOCRunstatus() {
166192
$running = $false
167193
$svc = Get-Service -Name "${AOCServiceName}" -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)