Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk committed Nov 30, 2023
1 parent af4f156 commit 9aeec20
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/chef-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- chef-node-zc
paths:
- '.github/workflows/chef-test.yml'
- 'deployments/chef/**'
Expand Down
10 changes: 10 additions & 0 deletions deployments/chef/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,14 @@
default['splunk_otel_collector']['auto_instrumentation_enable_profiler_memory'] = false
default['splunk_otel_collector']['auto_instrumentation_enable_metrics'] = false
default['splunk_otel_collector']['auto_instrumentation_otlp_endpoint'] = 'http://127.0.0.1:4317'
default['splunk_otel_collector']['with_auto_instrumentation_sdks'] = %w(java)
default['splunk_otel_collector']['auto_instrumentation_nodejs_package_path'] = '/usr/lib/splunk-instrumentation/splunk-otel-js.tgz'
default['splunk_otel_collector']['auto_instrumentation_nodejs_install_path'] = nil
default['splunk_otel_collector']['auto_instrumentation_nodejs_install_user'] = nil
default['splunk_otel_collector']['auto_instrumentation_nodejs_install_options'] = []

default['splunk_otel_collector']['nodejs_manage_node'] = false
default['splunk_otel_collector']['nodejs_install_method'] = 'binary'
default['splunk_otel_collector']['nodejs_version'] = nil
default['splunk_otel_collector']['nodejs_node_path'] = nil
end
49 changes: 47 additions & 2 deletions deployments/chef/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ suites:
splunk_realm: test
with_auto_instrumentation: true

- name: with_custom_preload_instrumentation
- name: with_custom_preload_java_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
splunk_otel_collector:
splunk_access_token: testing123
splunk_realm: test
with_auto_instrumentation: true
with_auto_instrumentation_sdks: ["java"]
auto_instrumentation_ld_so_preload: "# my extra library"
auto_instrumentation_resource_attributes: deployment.environment=test
auto_instrumentation_service_name: test
Expand All @@ -188,6 +189,26 @@ suites:
auto_instrumentation_enable_metrics: true
auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317

- name: with_custom_preload_node_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
splunk_otel_collector:
splunk_access_token: testing123
splunk_realm: test
with_auto_instrumentation: true
with_auto_instrumentation_sdks: ["nodejs"]
auto_instrumentation_ld_so_preload: "# my extra library"
auto_instrumentation_resource_attributes: deployment.environment=test
auto_instrumentation_service_name: test
auto_instrumentation_generate_service_name: false
auto_instrumentation_disable_telemetry: true
auto_instrumentation_enable_profiler: true
auto_instrumentation_enable_profiler_memory: true
auto_instrumentation_enable_metrics: true
auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317
nodejs_manage_node: true

- name: with_default_systemd_instrumentation
run_list:
- recipe[splunk_otel_collector]
Expand All @@ -198,14 +219,37 @@ suites:
with_auto_instrumentation: true
auto_instrumentation_systemd: true

- name: with_custom_systemd_instrumentation
- name: with_custom_systemd_java_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
splunk_otel_collector:
splunk_access_token: testing123
splunk_realm: test
with_auto_instrumentation: true
with_auto_instrumentation_sdks: ["java"]
auto_instrumentation_ld_so_preload: "# this should not be added"
auto_instrumentation_systemd: true
auto_instrumentation_resource_attributes: deployment.environment=test
auto_instrumentation_service_name: test
auto_instrumentation_generate_service_name: false
auto_instrumentation_disable_telemetry: true
auto_instrumentation_enable_profiler: true
auto_instrumentation_enable_profiler_memory: true
auto_instrumentation_enable_metrics: true
auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317

- name: with_custom_systemd_node_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
nodejs:
install_method: binary
splunk_otel_collector:
splunk_access_token: testing123
splunk_realm: test
with_auto_instrumentation: true
with_auto_instrumentation_sdks: ["nodejs"]
auto_instrumentation_ld_so_preload: "# this should not be added"
auto_instrumentation_systemd: true
auto_instrumentation_resource_attributes: deployment.environment=test
Expand All @@ -216,3 +260,4 @@ suites:
auto_instrumentation_enable_profiler_memory: true
auto_instrumentation_enable_metrics: true
auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317
nodejs_manage_node: true
2 changes: 2 additions & 0 deletions deployments/chef/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

issues_url 'https://github.com/signalfx/splunk-otel-collector/issues'
source_url 'https://github.com/signalfx/splunk-otel-collector'

depends 'nodejs'
96 changes: 86 additions & 10 deletions deployments/chef/recipes/auto_instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,54 @@
notifies :reload, 'ohai[reload packages]', :immediately
end

with_new_instrumentation = node['splunk_otel_collector']['auto_instrumentation_version'] == 'latest' || Gem::Version.new(node['splunk_otel_collector']['auto_instrumentation_version']) >= Gem::Version.new('0.87.0')
with_java = node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('java')
with_nodejs = node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('nodejs')

if with_nodejs && with_new_instrumentation
node.default['nodejs']['manage_node'] = node['splunk_otel_collector']['node_js_manage_node']
node.default['nodejs']['install_method'] = node['splunk_otel_collector']['nodejs_install_method']
node.default['nodejs']['binary']['append_env_path'] = false
unless node['splunk_otel_collector']['nodejs_version'].nil?
node.default['nodejs']['version'] = node['splunk_otel_collector']['nodejs_version']
end
include_recipe 'nodejs::npm'
log 'node_path' do
message "NODE_PATH = #{ENV['NODE_PATH']}"
action :nothing
end
ruby_block 'set NODE_PATH' do
block do
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command = 'npm root --quiet -g'
command_out = shell_out(command)
ENV['NODE_PATH'] = command_out.stdout
unless node['splunk_otel_collector']['auto_instrumentation_nodejs_install_path'].nil?
ENV['NODE_PATH'] = ENV['NODE_PATH'] + ':' + node['splunk_otel_collector']['auto_instrumentation_nodejs_install_path']
end
end
action :nothing
notifies :write, 'log[node_path]', :immediately
end
npm_package '@splunk/otel' do
json node['splunk_otel_collector']['auto_instrumentation_nodejs_package_path']
path node['splunk_otel_collector']['auto_instrumentation_nodejs_install_path']
user node['splunk_otel_collector']['auto_instrumentation_nodejs_install_user']
options node['splunk_otel_collector']['auto_instrumentation_nodejs_install_options']
notifies :run, 'ruby_block[set NODE_PATH]', :before
end
end

template '/etc/ld.so.preload' do
source 'ld.so.preload.erb'
end

execute 'reload systemd' do
command 'systemctl daemon-reload'
action :nothing
end

if node['splunk_otel_collector']['auto_instrumentation_systemd'].to_s.downcase == 'true'
execute 'reload systemd' do
command 'systemctl daemon-reload'
action :nothing
end
directory '/usr/lib/systemd/system.conf.d' do
recursive true
action :create
Expand All @@ -38,16 +77,47 @@
source '00-splunk-otel-auto-instrumentation.conf.erb'
notifies :run, 'execute[reload systemd]', :immediately
end
file '/etc/splunk/zeroconfig/java.conf' do
action :delete
end
file '/etc/splunk/zeroconfig/node.conf' do
action :delete
end
file '/usr/lib/splunk-instrumentation/instrumentation.conf' do
action :delete
end
else
file '/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf' do
action :delete
notifies :run, 'execute[reload systemd]', :immediately
end
if node['splunk_otel_collector']['auto_instrumentation_version'] == 'latest' || Gem::Version.new(node['splunk_otel_collector']['auto_instrumentation_version']) >= Gem::Version.new('0.87.0')
template '/etc/splunk/zeroconfig/java.conf' do
variables(
installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] }
)
source 'java.conf.erb'
if with_new_instrumentation
if with_java
template '/etc/splunk/zeroconfig/java.conf' do
variables(
installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] }
)
source 'java.conf.erb'
end
else
file '/etc/splunk/zeroconfig/java.conf' do
action :delete
end
end
if with_nodejs
template '/etc/splunk/zeroconfig/node.conf' do
variables(
installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] }
)
source 'node.conf.erb'
end
else
file '/etc/splunk/zeroconfig/node.conf' do
action :delete
end
end
file '/usr/lib/splunk-instrumentation/instrumentation.conf' do
action :delete
end
else
template '/usr/lib/splunk-instrumentation/instrumentation.conf' do
Expand All @@ -56,5 +126,11 @@
)
source 'instrumentation.conf.erb'
end
file '/etc/splunk/zeroconfig/java.conf' do
action :delete
end
file '/etc/splunk/zeroconfig/node.conf' do
action :delete
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[Manager]
<% if node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('java') -%>
DefaultEnvironment="JAVA_TOOL_OPTIONS=-javaagent:<%= node['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] %>"
<% end -%>
<% if node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('nodejs') -%>
DefaultEnvironment="NODE_OPTIONS=-r @splunk/otel/instrument"
<% end -%>
<% if defined?(node['splunk_otel_collector']['auto_instrumentation_resource_attributes']) && node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] != "" -%>
DefaultEnvironment="OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-<%= @installed_version %>-systemd,<%= node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] %>"
<% else -%>
Expand Down
13 changes: 13 additions & 0 deletions deployments/chef/templates/node.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
NODE_OPTIONS=-r @splunk/otel/instrument
<% if defined?(node['splunk_otel_collector']['auto_instrumentation_resource_attributes']) && node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] != "" -%>
OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-<%= @installed_version %>,<%= node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] %>
<% else -%>
OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-<%= @installed_version %>
<% end -%>
<% if defined?(node['splunk_otel_collector']['auto_instrumentation_service_name']) && node['splunk_otel_collector']['auto_instrumentation_service_name'] != "" -%>
OTEL_SERVICE_NAME=<%= node['splunk_otel_collector']['auto_instrumentation_service_name'] %>
<% end -%>
SPLUNK_PROFILER_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_profiler'].to_s.downcase %>
SPLUNK_PROFILER_MEMORY_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_profiler_memory'].to_s.downcase %>
SPLUNK_METRICS_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_metrics'].to_s.downcase %>
OTEL_EXPORTER_OTLP_ENDPOINT=<%= node['splunk_otel_collector']['auto_instrumentation_otlp_endpoint'] %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
it { should be_installed }
end

describe npm('@splunk/otel') do
it { should_not be_installed }
end

describe file('/etc/ld.so.preload') do
its('content') { should match /^#{libsplunk_path}$/ }
its('content') { should match /^#{ld_preload_line}$/ }
Expand All @@ -17,6 +21,14 @@
it { should_not exist }
end

describe file('/etc/splunk/zeroconfig/node.conf') do
it { should_not exist }
end

describe file('/usr/lib/splunk-instrumentation/instrumentation.conf') do
it { should_not exist }
end

describe file('/etc/splunk/zeroconfig/java.conf') do
its('content') { should match /^JAVA_TOOL_OPTIONS=#{java_tool_options}$/ }
its('content') { should match /^OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}$/ }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so'
node_options = '-r @splunk/otel/instrument'
otlp_endpoint = 'http://0.0.0.0:4317'
ld_preload_line = '# my extra library'

describe package('splunk-otel-auto-instrumentation') do
it { should be_installed }
end

describe npm('@splunk/otel') do
it { should be_installed }
end

describe file('/etc/ld.so.preload') do
its('content') { should match /^#{libsplunk_path}$/ }
its('content') { should match /^#{ld_preload_line}$/ }
end

describe file('/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf') do
it { should_not exist }
end

describe file('/etc/splunk/zeroconfig/java.conf') do
it { should_not exist }
end

describe file('/usr/lib/splunk-instrumentation/instrumentation.conf') do
it { should_not exist }
end

describe file('/etc/splunk/zeroconfig/node.conf') do
its('content') { should match /^NODE_OPTIONS=#{node_options}$/ }
its('content') { should match /^OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}$/ }
its('content') { should match /^OTEL_SERVICE_NAME=test$/ }
its('content') { should match /^SPLUNK_PROFILER_ENABLED=true$/ }
its('content') { should match /^SPLUNK_PROFILER_MEMORY_ENABLED=true$/ }
its('content') { should match /^SPLUNK_METRICS_ENABLED=true$/ }
its('content') { should match /^OTEL_EXPORTER_OTLP_ENDPOINT=#{otlp_endpoint}$/ }
end

describe service('splunk-otel-collector') do
it { should be_enabled }
it { should be_running }
end

describe service('td-agent') do
it { should_not be_enabled }
it { should_not be_running }
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@
it { should be_installed }
end

describe npm('@splunk/otel') do
it { should_not be_installed }
end

describe file('/etc/ld.so.preload') do
its('content') { should_not match /^#{libsplunk_path}$/ }
end

describe file('/etc/splunk/zeroconfig/java.conf') do
it { should_not exist }
end

describe file('/etc/splunk/zeroconfig/node.conf') do
it { should_not exist }
end

describe file('/usr/lib/splunk-instrumentation/instrumentation.conf') do
it { should_not exist }
end

describe file('/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf') do
its('content') { should_not match /.*NODE_OPTIONS.*/ }
its('content') { should match /^DefaultEnvironment="JAVA_TOOL_OPTIONS=#{java_tool_options}"$/ }
its('content') { should match /^DefaultEnvironment="OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}"$/ }
its('content') { should match /^DefaultEnvironment="OTEL_SERVICE_NAME=test"$/ }
Expand Down
Loading

0 comments on commit 9aeec20

Please sign in to comment.