Skip to content

Commit 55093a0

Browse files
authored
Use msi capabilities for puppet (#4978)
* Use latest MSI capabilities instead of custom code in Puppet * Cover legacy and latest MSI on Windows tests
1 parent 2b9de81 commit 55093a0

File tree

7 files changed

+90
-51
lines changed

7 files changed

+90
-51
lines changed

.github/workflows/puppet-test.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ jobs:
109109
- name: Test puppet deployment
110110
id: pytest
111111
continue-on-error: true
112+
env:
113+
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
112114
run: |
113115
distro="${{ matrix.DISTRO }}"
114116
if [[ "$distro" = "amazonlinux-2" ]]; then
@@ -122,12 +124,12 @@ jobs:
122124
fi
123125
python3 -u -m pytest -s --verbose -k "$tests" \
124126
internal/buildscripts/packaging/tests/deployments/puppet/puppet_test.py
125-
env:
126-
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
127127
128128
# qemu, networking, running systemd in containers, etc., can be flaky
129129
- name: Re-run failed tests
130130
if: ${{ steps.pytest.outcome == 'failure' }}
131+
env:
132+
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
131133
run: |
132134
distro="${{ matrix.DISTRO }}"
133135
if [[ "$distro" = "amazonlinux-2" ]]; then
@@ -142,8 +144,6 @@ jobs:
142144
python3 -u -m pytest -s --verbose -k "$tests" \
143145
--last-failed \
144146
internal/buildscripts/packaging/tests/deployments/puppet/puppet_test.py
145-
env:
146-
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
147147
148148
puppet-test-windows:
149149
name: puppet-test-windows
@@ -157,6 +157,7 @@ jobs:
157157
OS: [ "windows-2022" ]
158158
PUPPET_RELEASE: [ "6.0.2", "7.21.0" ]
159159
TEST_CASE: [ "default", "custom_vars" ]
160+
WIN_COLLECTOR_VERSION: [ "0.86.0", "latest" ]
160161
fail-fast: false
161162
steps:
162163
- name: Check out the codebase.
@@ -175,19 +176,23 @@ jobs:
175176
- name: Test puppet deployment
176177
id: pytest
177178
continue-on-error: true
179+
env:
180+
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
181+
WIN_COLLECTOR_VERSION: "${{ matrix.WIN_COLLECTOR_VERSION }}"
178182
run: |
183+
if ($Env:WIN_COLLECTOR_VERSION -eq 'latest') { $Env:WIN_COLLECTOR_VERSION="$(curl -sS https://dl.signalfx.com/splunk-otel-collector/msi/release/latest.txt)" }
179184
pytest -s --verbose -m windows `
180185
-k ${{ matrix.TEST_CASE }} `
181186
internal/buildscripts/packaging/tests/deployments/puppet/puppet_test.py
182-
env:
183-
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
184187
185188
- name: Re-run failed tests
186189
if: ${{ steps.pytest.outcome == 'failure' }}
190+
env:
191+
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
192+
WIN_COLLECTOR_VERSION: "${{ matrix.WIN_COLLECTOR_VERSION }}"
187193
run: |
194+
if ($Env:WIN_COLLECTOR_VERSION -eq 'latest') { $Env:WIN_COLLECTOR_VERSION="$(curl -sS https://dl.signalfx.com/splunk-otel-collector/msi/release/latest.txt)" }
188195
pytest -s --verbose -m windows `
189196
--last-failed `
190197
-k ${{ matrix.TEST_CASE }} `
191198
internal/buildscripts/packaging/tests/deployments/puppet/puppet_test.py
192-
env:
193-
PUPPET_RELEASE: "${{ matrix.PUPPET_RELEASE }}"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Class for collecting the configuration options for the splunk-otel-collector service
2+
class splunk_otel_collector::collector_win_config_options {
3+
$base_env_vars = {
4+
'SPLUNK_ACCESS_TOKEN' => $splunk_otel_collector::splunk_access_token,
5+
'SPLUNK_API_URL' => $splunk_otel_collector::splunk_api_url,
6+
'SPLUNK_BUNDLE_DIR' => $splunk_otel_collector::splunk_bundle_dir,
7+
'SPLUNK_COLLECTD_DIR' => $splunk_otel_collector::splunk_collectd_dir,
8+
'SPLUNK_CONFIG' => $splunk_otel_collector::collector_config_dest,
9+
'SPLUNK_HEC_TOKEN' => $splunk_otel_collector::splunk_hec_token,
10+
'SPLUNK_HEC_URL' => $splunk_otel_collector::splunk_hec_url,
11+
'SPLUNK_INGEST_URL' => $splunk_otel_collector::splunk_ingest_url,
12+
'SPLUNK_MEMORY_TOTAL_MIB' => $splunk_otel_collector::splunk_memory_total_mib,
13+
'SPLUNK_REALM' => $splunk_otel_collector::splunk_realm,
14+
'SPLUNK_TRACE_URL' => $splunk_otel_collector::splunk_trace_url,
15+
}
16+
17+
$ballast_size_mib = if $splunk_otel_collector::collector_version != 'latest' and
18+
versioncmp($splunk_otel_collector::collector_version, '0.97.0') < 0 and
19+
!$splunk_otel_collector::splunk_ballast_size_mib.strip().empty() {
20+
{ 'SPLUNK_BALLAST_SIZE_MIB' => $splunk_otel_collector::splunk_ballast_size_mib }
21+
} else {
22+
{}
23+
}
24+
25+
$gomemlimit = if ($splunk_otel_collector::collector_version == 'latest' or
26+
versioncmp($splunk_otel_collector::collector_version, '0.97.0') >= 0) and
27+
!$splunk_otel_collector::gomemlimit.strip().empty() {
28+
{ 'GOMEMLIMIT' => $splunk_otel_collector::gomemlimit }
29+
} else {
30+
{}
31+
}
32+
33+
$listen_interface = if !$splunk_otel_collector::splunk_listen_interface.strip().empty() {
34+
{ 'SPLUNK_LISTEN_INTERFACE' => $splunk_otel_collector::splunk_listen_interface }
35+
} else {
36+
{}
37+
}
38+
39+
$collector_env_vars = stdlib::merge($base_env_vars, $ballast_size_mib, $gomemlimit, $listen_interface)
40+
}

deployments/puppet/manifests/collector_win_install.pp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Download and install the splunk-otel-collector MSI on Windows
22
class splunk_otel_collector::collector_win_install ($repo_url, $version, $package_name, $service_name) {
3+
contain 'splunk_otel_collector::collector_win_config_options'
4+
35
$msi_name = "splunk-otel-collector-${version}-amd64.msi"
46
$collector_path = "${::win_programfiles}\\Splunk\\OpenTelemetry Collector\\otelcol.exe"
57
$registry_key = 'HKLM\SYSTEM\CurrentControlSet\Services\splunk-otel-collector'
@@ -11,8 +13,11 @@
1113
}
1214

1315
-> package { $package_name:
14-
ensure => $version,
15-
source => "${::win_temp}\\${msi_name}",
16+
ensure => $version,
17+
source => "${::win_temp}\\${msi_name}",
18+
require => Class['splunk_otel_collector::collector_win_config_options'],
19+
# If the MSI is not configurable, the install_options below will be ignored during installation.
20+
install_options => $splunk_otel_collector::collector_win_config_options::collector_env_vars,
1621
}
1722
}
1823

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,29 @@
11
# Class for setting the registry values for the splunk-otel-collector service
2-
class splunk_otel_collector::collector_win_registry () {
2+
class splunk_otel_collector::collector_win_registry {
3+
# Ensure splunk_otel_collector::collector_win_config_options is applied first
4+
require splunk_otel_collector::collector_win_config_options
5+
36
$unordered_collector_env_vars = $splunk_otel_collector::collector_additional_env_vars.map |$var, $value| {
47
"${var}=${value}"
58
}
6-
+ [
7-
"SPLUNK_ACCESS_TOKEN=${splunk_otel_collector::splunk_access_token}",
8-
"SPLUNK_API_URL=${splunk_otel_collector::splunk_api_url}",
9-
"SPLUNK_BUNDLE_DIR=${splunk_otel_collector::splunk_bundle_dir}",
10-
"SPLUNK_COLLECTD_DIR=${splunk_otel_collector::splunk_collectd_dir}",
11-
"SPLUNK_CONFIG=${splunk_otel_collector::collector_config_dest}",
12-
"SPLUNK_HEC_TOKEN=${splunk_otel_collector::splunk_hec_token}",
13-
"SPLUNK_HEC_URL=${splunk_otel_collector::splunk_hec_url}",
14-
"SPLUNK_INGEST_URL=${splunk_otel_collector::splunk_ingest_url}",
15-
"SPLUNK_MEMORY_TOTAL_MIB=${splunk_otel_collector::splunk_memory_total_mib}",
16-
"SPLUNK_REALM=${splunk_otel_collector::splunk_realm}",
17-
"SPLUNK_TRACE_URL=${splunk_otel_collector::splunk_trace_url}",
18-
]
19-
+ if ($splunk_otel_collector::collector_version != 'latest' and
20-
versioncmp($splunk_otel_collector::collector_version, '0.97.0') < 0 ) and
21-
!$splunk_otel_collector::splunk_ballast_size_mib.strip().empty()
22-
{
23-
["SPLUNK_BALLAST_SIZE_MIB=${splunk_otel_collector::splunk_ballast_size_mib}"]
24-
} else {
25-
[]
26-
}
27-
+ if ($splunk_otel_collector::collector_version == 'latest' or
28-
versioncmp($splunk_otel_collector::collector_version, '0.97.0') >= 0 ) and
29-
!$splunk_otel_collector::gomemlimit.strip().empty()
9+
+ if !empty($splunk_otel_collector::collector_additional_env_vars) or
10+
versioncmp($splunk_otel_collector::collector_version, '0.98.0') < 0
3011
{
31-
["GOMEMLIMIT=${splunk_otel_collector::gomemlimit}"]
32-
} else {
33-
[]
34-
}
35-
+ if !$splunk_otel_collector::splunk_listen_interface.strip().empty() {
36-
["SPLUNK_LISTEN_INTERFACE=${splunk_otel_collector::splunk_listen_interface}"]
12+
$splunk_otel_collector::collector_win_config_options::collector_env_vars.map |$var, $value| {
13+
"${var}=${value}"
14+
}
3715
} else {
3816
[]
3917
}
4018

4119
$collector_env_vars = sort($unordered_collector_env_vars)
4220

43-
registry_value { "HKLM\\SYSTEM\\CurrentControlSet\\Services\\splunk-otel-collector\\Environment":
44-
ensure => 'present',
45-
type => array,
46-
data => $collector_env_vars,
47-
require => Registry_key["HKLM\\SYSTEM\\CurrentControlSet\\Services\\splunk-otel-collector"],
21+
if !empty($collector_env_vars) {
22+
registry_value { "HKLM\\SYSTEM\\CurrentControlSet\\Services\\splunk-otel-collector\\Environment":
23+
ensure => 'present',
24+
type => array,
25+
data => $collector_env_vars,
26+
require => Registry_key["HKLM\\SYSTEM\\CurrentControlSet\\Services\\splunk-otel-collector"],
27+
}
4828
}
4929
}

deployments/puppet/manifests/init.pp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,16 @@
195195
subscribe => [File[$collector_config_dest, $env_file_path]],
196196
}
197197
} else {
198-
file { $collector_config_dest:
199-
source => $collector_config_source,
200-
require => Class['splunk_otel_collector::collector_win_install'],
198+
if $collector_config_source != $splunk_otel_collector::params::default_win_config_file {
199+
file { $collector_config_dest:
200+
source => $collector_config_source,
201+
require => Class['splunk_otel_collector::collector_win_install'],
202+
}
203+
} else {
204+
file { $collector_config_dest:
205+
ensure => file,
206+
require => Class['splunk_otel_collector::collector_win_install'],
207+
}
201208
}
202209

203210
-> class { 'splunk_otel_collector::collector_win_registry': }

deployments/puppet/manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
$splunk_bundle_dir = "${collector_install_dir}\\agent-bundle"
3434
$splunk_collectd_dir = "${splunk_bundle_dir}\\run\\collectd"
3535
$collector_config_source = "${collector_install_dir}\\agent_config.yaml"
36+
$default_win_config_file = $collector_config_source
3637
$collector_config_dest = "${collector_config_dir}\\agent_config.yaml"
3738
$fluentd_base_url = 'https://s3.amazonaws.com/packages.treasuredata.com'
3839
$fluentd_version = $fluentd_version_default

internal/buildscripts/packaging/tests/deployments/puppet/puppet_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def test_puppet_with_custom_instrumentation(distro, puppet_release, version, wit
429429
WIN_INSTALL_DIR = r"C:\Program Files\Splunk\OpenTelemetry Collector"
430430
WIN_CONFIG_PATH = r"C:\ProgramData\Splunk\OpenTelemetry Collector\agent_config.yaml"
431431

432+
WIN_COLLECTOR_VERSION = os.environ.get("WIN_COLLECTOR_VERSION", "123.456.789") # Windows require a pre-defined version, use an inexistent version to force a test failure
432433

433434
def run_win_puppet_setup(puppet_release):
434435
assert has_choco(), "choco not installed!"
@@ -466,7 +467,7 @@ def test_win_puppet_default():
466467
class {{ splunk_otel_collector:
467468
splunk_access_token => '{SPLUNK_ACCESS_TOKEN}',
468469
splunk_realm => '{SPLUNK_REALM}',
469-
collector_version => '0.86.0',
470+
collector_version => '{WIN_COLLECTOR_VERSION}',
470471
}}
471472
"""
472473
run_win_puppet_agent(config)
@@ -496,7 +497,7 @@ def test_win_puppet_custom_vars():
496497

497498
api_url = "https://fake-splunk-api.com"
498499
ingest_url = "https://fake-splunk-ingest.com"
499-
config = CUSTOM_VARS_CONFIG.substitute(api_url=api_url, ingest_url=ingest_url, version="0.48.0")
500+
config = CUSTOM_VARS_CONFIG.substitute(api_url=api_url, ingest_url=ingest_url, version=WIN_COLLECTOR_VERSION)
500501

501502
run_win_puppet_agent(config)
502503

0 commit comments

Comments
 (0)