Skip to content

Commit 77529d2

Browse files
authored
Use msi capabilities for chef (#4949)
* Use latest MSI capabilities instead of custom code in Chef * Lint fixes * Try to see the properties string * Fix creation of msi_install_properties * Remove debug message
1 parent 46ced7c commit 77529d2

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Cookbook:: splunk_otel_collector
2+
# Recipe:: collector_win_config_options
3+
4+
collector_env_vars = [
5+
{ name: 'SPLUNK_ACCESS_TOKEN', type: :string, data: node['splunk_otel_collector']['splunk_access_token'].to_s },
6+
{ name: 'SPLUNK_API_URL', type: :string, data: node['splunk_otel_collector']['splunk_api_url'].to_s },
7+
{ name: 'SPLUNK_BUNDLE_DIR', type: :string, data: node['splunk_otel_collector']['splunk_bundle_dir'].to_s },
8+
{ name: 'SPLUNK_COLLECTD_DIR', type: :string, data: node['splunk_otel_collector']['splunk_collectd_dir'].to_s },
9+
{ name: 'SPLUNK_CONFIG', type: :string, data: node['splunk_otel_collector']['collector_config_dest'].to_s },
10+
{ name: 'SPLUNK_HEC_TOKEN', type: :string, data: node['splunk_otel_collector']['splunk_hec_token'].to_s },
11+
{ name: 'SPLUNK_HEC_URL', type: :string, data: node['splunk_otel_collector']['splunk_hec_url'].to_s },
12+
{ name: 'SPLUNK_INGEST_URL', type: :string, data: node['splunk_otel_collector']['splunk_ingest_url'].to_s },
13+
{ name: 'SPLUNK_REALM', type: :string, data: node['splunk_otel_collector']['splunk_realm'].to_s },
14+
{ name: 'SPLUNK_MEMORY_TOTAL_MIB', type: :string, data: node['splunk_otel_collector']['splunk_memory_total_mib'].to_s },
15+
{ name: 'SPLUNK_TRACE_URL', type: :string, data: node['splunk_otel_collector']['splunk_trace_url'].to_s },
16+
]
17+
18+
unless node['splunk_otel_collector']['gomemlimit'].to_s.strip.empty?
19+
collector_env_vars.push({ name: 'GOMEMLIMIT', type: :string, data: node['splunk_otel_collector']['gomemlimit'].to_s })
20+
end
21+
unless node['splunk_otel_collector']['splunk_listen_interface'].to_s.strip.empty?
22+
collector_env_vars.push({ name: 'SPLUNK_LISTEN_INTERFACE', type: :string, data: node['splunk_otel_collector']['splunk_listen_interface'].to_s })
23+
end
24+
25+
node['splunk_otel_collector']['collector_additional_env_vars'].each do |key, value|
26+
collector_env_vars.push({ name: key, type: :string, data: value.to_s })
27+
end
28+
29+
node.default['splunk_otel_collector']['collector_win_env_vars'] = collector_env_vars

deployments/chef/recipes/collector_win_install.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@
2020
only_if { !::File.exist?(node['splunk_otel_collector']['collector_version_file']) || (::File.readlines(node['splunk_otel_collector']['collector_version_file']).first.strip != collector_version) }
2121
end
2222

23+
msi_is_configurable = Gem::Version.new(collector_version) >= Gem::Version.new('0.98.0')
24+
node.default['splunk_otel_collector']['collector_msi_is_configurable'] = msi_is_configurable
25+
msi_install_properties = node['splunk_otel_collector']['collector_win_env_vars']
26+
.reject { |item| item[:data].nil? || item[:data] == '' }
27+
.map { |item| "#{item[:name]}=\"#{item[:data]}\"" }
28+
.join(' ')
29+
2330
windows_package 'splunk-otel-collector' do
2431
source "#{ENV['TEMP']}/splunk-otel-collector-#{collector_version}-amd64.msi"
32+
options msi_install_properties # If the MSI is not configurable, this will be ignored during installation.
2533
action :install
2634
notifies :restart, 'windows_service[splunk-otel-collector]', :delayed
2735
only_if { !::File.exist?(node['splunk_otel_collector']['collector_version_file']) || (::File.readlines(node['splunk_otel_collector']['collector_version_file']).first.strip != collector_version) }

deployments/chef/recipes/collector_win_registry.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
11
# Cookbook:: splunk_otel_collector
22
# Recipe:: collector_win_registry
33

4-
collector_env_vars = [
5-
{ name: 'SPLUNK_ACCESS_TOKEN', type: :string, data: node['splunk_otel_collector']['splunk_access_token'].to_s },
6-
{ name: 'SPLUNK_API_URL', type: :string, data: node['splunk_otel_collector']['splunk_api_url'].to_s },
7-
{ name: 'SPLUNK_BUNDLE_DIR', type: :string, data: node['splunk_otel_collector']['splunk_bundle_dir'].to_s },
8-
{ name: 'SPLUNK_COLLECTD_DIR', type: :string, data: node['splunk_otel_collector']['splunk_collectd_dir'].to_s },
9-
{ name: 'SPLUNK_CONFIG', type: :string, data: node['splunk_otel_collector']['collector_config_dest'].to_s },
10-
{ name: 'SPLUNK_HEC_TOKEN', type: :string, data: node['splunk_otel_collector']['splunk_hec_token'].to_s },
11-
{ name: 'SPLUNK_HEC_URL', type: :string, data: node['splunk_otel_collector']['splunk_hec_url'].to_s },
12-
{ name: 'SPLUNK_INGEST_URL', type: :string, data: node['splunk_otel_collector']['splunk_ingest_url'].to_s },
13-
{ name: 'SPLUNK_REALM', type: :string, data: node['splunk_otel_collector']['splunk_realm'].to_s },
14-
{ name: 'SPLUNK_MEMORY_TOTAL_MIB', type: :string, data: node['splunk_otel_collector']['splunk_memory_total_mib'].to_s },
15-
{ name: 'SPLUNK_TRACE_URL', type: :string, data: node['splunk_otel_collector']['splunk_trace_url'].to_s },
16-
]
17-
18-
unless node['splunk_otel_collector']['gomemlimit'].to_s.strip.empty?
19-
collector_env_vars.push({ name: 'GOMEMLIMIT', type: :string, data: node['splunk_otel_collector']['gomemlimit'].to_s })
20-
end
21-
unless node['splunk_otel_collector']['splunk_listen_interface'].to_s.strip.empty?
22-
collector_env_vars.push({ name: 'SPLUNK_LISTEN_INTERFACE', type: :string, data: node['splunk_otel_collector']['splunk_listen_interface'].to_s })
23-
end
24-
25-
node['splunk_otel_collector']['collector_additional_env_vars'].each do |key, value|
26-
collector_env_vars.push({ name: key, type: :string, data: value.to_s })
27-
end
4+
collector_env_vars = node['splunk_otel_collector']['collector_win_env_vars']
285

296
collector_env_vars_strings = []
307
collector_env_vars.each do |item|

deployments/chef/recipes/default.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
end
1010

1111
if platform_family?('windows')
12+
include_recipe 'splunk_otel_collector::collector_win_config_options'
1213
include_recipe 'splunk_otel_collector::collector_win_install'
13-
include_recipe 'splunk_otel_collector::collector_win_registry'
14+
15+
# Older MSI versions can't properly setup the collector configuration
16+
# in this case, we need to use the registry to set the environment variables.
17+
unless node['splunk_otel_collector']['collector_msi_is_configurable']
18+
include_recipe 'splunk_otel_collector::collector_win_registry'
19+
end
1420

1521
directory ::File.dirname(node['splunk_otel_collector']['collector_config_dest']) do
1622
action :create

0 commit comments

Comments
 (0)