Skip to content

Commit 2cc4878

Browse files
authored
Merge pull request #2971 from aws-observability/featureflag
Add configuration support for feature flag in linux script
2 parents 357f9c7 + f9e3246 commit 2cc4878

File tree

3 files changed

+73
-12
lines changed

3 files changed

+73
-12
lines changed

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

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

89+
test_collector_ctl_with_featureflag() {
90+
#staart coll default conf by starting without -c
91+
$ADOT_CTL -a start -f "-adot.exporter.datadogexporter.deprecation"
92+
93+
echo "${FUNCNAME[0]} ... OK"
94+
}
95+
8996
setup
9097

9198
## Tests
9299
test_collector_ctl_does_not_overwrite_env
93100
test_collector_ctl_with_sed_special_chars
94101
test_collector_ctl_with_samecfg
95102
test_collector_ctl_with_samecfg_restart
103+
test_collector_ctl_with_featureflag

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

Lines changed: 30 additions & 6 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() {
@@ -80,6 +86,16 @@ 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+
98+
8399
# Used in case the collector starts for the first time without a configuration parameter
84100
# Safe to run as this will not overwrite a file if one exists in default location already.
85101
aoc_ensure_default_config() {
@@ -100,6 +116,7 @@ is_remote_uri() {
100116

101117
aoc_start() {
102118
config="${1:-}"
119+
feature_gates="${2:-}"
103120

104121
# The previous configuration should be used if no configuration parameter is passed
105122
aoc_ensure_default_config
@@ -111,6 +128,11 @@ aoc_start() {
111128
fi
112129
fi
113130

131+
# Handle feature gates
132+
if [ -n "$feature_gates" ]; then
133+
aoc_config_feature_gates "$feature_gates"
134+
fi
135+
114136
if [ "${SYSTEMD}" = 'true' ]; then
115137
systemctl daemon-reload
116138
systemctl enable aws-otel-collector.service
@@ -190,6 +212,7 @@ main() {
190212
action=''
191213
mode='ec2'
192214
config_location=''
215+
feature_gates=''
193216

194217
# detect which init system is in use
195218
if [ "$(/sbin/init --version 2>/dev/null | grep -c upstart)" = 1 ]; then
@@ -205,7 +228,7 @@ main() {
205228
fi
206229

207230
OPTIND=1
208-
while getopts ":ha:c:m:" opt; do
231+
while getopts ":ha:c:m:f:" opt; do
209232
case "${opt}" in
210233
h)
211234
echo "${UsageString}"
@@ -214,6 +237,7 @@ main() {
214237
a) action="${OPTARG}" ;;
215238
c) config_location="${OPTARG}" ;;
216239
m) mode="${OPTARG}" ;;
240+
f) feature_gates="${OPTARG}" ;;
217241
\?)
218242
echo "Invalid option: -${OPTARG} ${UsageString}" >&2
219243
;;
@@ -240,7 +264,7 @@ main() {
240264

241265
case "${action}" in
242266
stop) aoc_stop ;;
243-
start) aoc_start "${config_location}" ;;
267+
start) aoc_start "${config_location}" "${feature_gates}" ;;
244268
status) aoc_status ;;
245269
# helper for rpm+deb uninstallation hooks, not expected to be called manually
246270
preun) aoc_preun ;;

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

Lines changed: 35 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

@@ -81,19 +89,40 @@ Function Get-Service-Config-Uri() {
8189
return $Matches.1
8290
}
8391

92+
93+
8494
Function Set-Service-Config-Uri ([string]$uri) {
8595
$aoc_cmd = "\""${AOCProgramFiles}\.aws-otel-collector.exe\"" --config=\""${uri}\"""
8696
sc.exe config "${AOCServiceName}" binPath= "${aoc_cmd}"
8797
}
8898

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

93109
Function AOCStart() {
94110

95111
if($ConfigLocation -and $ConfigLocation -ne 'default') {
112+
113+
# Check for feature gates before configuring service
114+
if ($FeatureGates) {
115+
Write-Output "Applying feature gate"
96116
if (Test-Remote-Uri $ConfigLocation) {
117+
Set-Service-Config-Uri-With-FeatureGates ${ConfigLocation} ${FeatureGates}
118+
} else {
119+
# Strip file scheme in case it is present
120+
$ConfigLocation = "$ConfigLocation" -replace "^file:", ""
121+
122+
Copy-Item "${ConfigLocation}" -Destination ${ProgramFilesYAML}
123+
Set-Service-Config-Uri-With-FeatureGates ${ProgramFilesYAML} ${FeatureGates}
124+
}
125+
} elseif (Test-Remote-Uri $ConfigLocation) {
97126
Set-Service-Config-Uri ${ConfigLocation}
98127
} else {
99128
# Strip file scheme in case it is present
@@ -121,6 +150,7 @@ Function AOCStart() {
121150
& sc.exe failureflag "${AOCServiceName}" 1 | Out-Null
122151
}
123152
}
153+
124154
$svc | Start-Service
125155
}
126156

@@ -131,7 +161,6 @@ Function AOCStop() {
131161
}
132162
}
133163

134-
135164
Function AOCStatus() {
136165

137166
$timefmt=''
@@ -150,18 +179,18 @@ Function AOCStatus() {
150179
$timefmt = Get-Date -Date ${processStart} -Format "s"
151180
}
152181
}
153-
182+
154183
$status = AOCRunstatus
155184
$version = ([IO.File]::ReadAllText("${VersionFile}")).Trim()
156-
185+
157186
Write-Output "{"
158187
Write-Output " `"status`": `"${status}`","
159188
Write-Output " `"starttime`": `"${timefmt}`","
160189
Write-Output " `"version`": `"${version}`""
161190
Write-Output "}"
162191
}
163192

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

0 commit comments

Comments
 (0)