diff --git a/.github/workflows/chef-test.yml b/.github/workflows/chef-test.yml index 977d49b110..d997d3a0b8 100644 --- a/.github/workflows/chef-test.yml +++ b/.github/workflows/chef-test.yml @@ -5,6 +5,7 @@ on: push: branches: - main + - chef-node-zc paths: - '.github/workflows/chef-test.yml' - 'deployments/chef/**' diff --git a/deployments/chef/attributes/default.rb b/deployments/chef/attributes/default.rb index 1b064c66ed..92e4ee7cc4 100644 --- a/deployments/chef/attributes/default.rb +++ b/deployments/chef/attributes/default.rb @@ -100,4 +100,9 @@ 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 node) + default['splunk_otel_collector']['auto_instrumentation_node_package_path'] = '/usr/lib/splunk-instrumentation/splunk-otel-js.tgz' + default['splunk_otel_collector']['auto_instrumentation_node_install_path'] = nil + default['splunk_otel_collector']['auto_instrumentation_node_install_user'] = nil + default['splunk_otel_collector']['auto_instrumentation_node_install_options'] = [] end diff --git a/deployments/chef/kitchen.yml b/deployments/chef/kitchen.yml index c0eff7a99f..265a413044 100644 --- a/deployments/chef/kitchen.yml +++ b/deployments/chef/kitchen.yml @@ -170,7 +170,7 @@ 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: @@ -178,6 +178,26 @@ suites: 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 + 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_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: ["node"] auto_instrumentation_ld_so_preload: "# my extra library" auto_instrumentation_resource_attributes: deployment.environment=test auto_instrumentation_service_name: test @@ -198,7 +218,27 @@ 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: @@ -206,6 +246,7 @@ suites: splunk_access_token: testing123 splunk_realm: test with_auto_instrumentation: true + with_auto_instrumentation_sdks: ["node"] auto_instrumentation_ld_so_preload: "# this should not be added" auto_instrumentation_systemd: true auto_instrumentation_resource_attributes: deployment.environment=test diff --git a/deployments/chef/recipes/auto_instrumentation.rb b/deployments/chef/recipes/auto_instrumentation.rb index 15da34f8cf..c5947705bc 100644 --- a/deployments/chef/recipes/auto_instrumentation.rb +++ b/deployments/chef/recipes/auto_instrumentation.rb @@ -18,15 +18,26 @@ notifies :reload, 'ohai[reload packages]', :immediately end +if node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('node') && (node['splunk_otel_collector']['auto_instrumentation_version'] == 'latest' || Gem::Version.new(node['splunk_otel_collector']['auto_instrumentation_version']) >= Gem::Version.new('0.87.0')) + include_recipe 'nodejs::npm' + npm_package 'splunk/otel' do + json node['splunk_otel_collector']['auto_instrumentation_node_package_path'] + path node['splunk_otel_collector']['auto_instrumentation_node_install_path'] + user node['splunk_otel_collector']['auto_instrumentation_node_install_user'] + options node['splunk_otel_collector']['auto_instrumentation_node_install_options'] + 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 @@ -41,13 +52,32 @@ 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 node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('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 node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('node') + 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 else template '/usr/lib/splunk-instrumentation/instrumentation.conf' do diff --git a/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb b/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb index 55e63cf9d8..aee2f1c87e 100644 --- a/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb +++ b/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb @@ -1,5 +1,10 @@ [Manager] + DefaultEnvironment="JAVA_TOOL_OPTIONS=-javaagent:<%= node['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] %>" +<% end -%> + +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 -%> diff --git a/deployments/chef/templates/node.conf.erb b/deployments/chef/templates/node.conf.erb new file mode 100644 index 0000000000..fd071c7a44 --- /dev/null +++ b/deployments/chef/templates/node.conf.erb @@ -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'] %> diff --git a/deployments/chef/test/integration/with_custom_preload_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb b/deployments/chef/test/integration/with_custom_preload_java_instrumentation/inspec/with_custom_preload_java_instrumentation_spec.rb similarity index 94% rename from deployments/chef/test/integration/with_custom_preload_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb rename to deployments/chef/test/integration/with_custom_preload_java_instrumentation/inspec/with_custom_preload_java_instrumentation_spec.rb index 0ad6401e9c..ce54dc09d5 100644 --- a/deployments/chef/test/integration/with_custom_preload_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb +++ b/deployments/chef/test/integration/with_custom_preload_java_instrumentation/inspec/with_custom_preload_java_instrumentation_spec.rb @@ -17,6 +17,10 @@ it { should_not exist } end +describe file('/etc/splunk/zeroconfig/node.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}$/ } diff --git a/deployments/chef/test/integration/with_custom_preload_node_instrumentation/inspec/with_custom_preload_node_instrumentation_spec.rb b/deployments/chef/test/integration/with_custom_preload_node_instrumentation/inspec/with_custom_preload_node_instrumentation_spec.rb new file mode 100644 index 0000000000..a7c90a0b69 --- /dev/null +++ b/deployments/chef/test/integration/with_custom_preload_node_instrumentation/inspec/with_custom_preload_node_instrumentation_spec.rb @@ -0,0 +1,41 @@ +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 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('/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 diff --git a/deployments/chef/test/integration/with_custom_systemd_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb b/deployments/chef/test/integration/with_custom_systemd_java_instrumentation/inspec/with_custom_systemd_java_instrumentation_spec.rb similarity index 96% rename from deployments/chef/test/integration/with_custom_systemd_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb rename to deployments/chef/test/integration/with_custom_systemd_java_instrumentation/inspec/with_custom_systemd_java_instrumentation_spec.rb index 05c3a75930..dd508f6c69 100644 --- a/deployments/chef/test/integration/with_custom_systemd_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb +++ b/deployments/chef/test/integration/with_custom_systemd_java_instrumentation/inspec/with_custom_systemd_java_instrumentation_spec.rb @@ -12,6 +12,7 @@ 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"$/ } diff --git a/deployments/chef/test/integration/with_custom_systemd_node_instrumentation/inspec/with_custom_systemd_node_instrumentation_spec.rb b/deployments/chef/test/integration/with_custom_systemd_node_instrumentation/inspec/with_custom_systemd_node_instrumentation_spec.rb new file mode 100644 index 0000000000..d71b527f7b --- /dev/null +++ b/deployments/chef/test/integration/with_custom_systemd_node_instrumentation/inspec/with_custom_systemd_node_instrumentation_spec.rb @@ -0,0 +1,33 @@ +libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' +node_options = '-r @splunk/otel/instrument' +resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-\d+\.\d+\.\d+-systemd,deployment.environment=test' +otlp_endpoint = 'http://0.0.0.0:4317' + +describe package('splunk-otel-auto-instrumentation') do + it { should be_installed } +end + +describe file('/etc/ld.so.preload') do + its('content') { should_not match /^#{libsplunk_path}$/ } +end + +describe file('/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf') do + its('content') { should_not match /.*JAVA_TOOL_OPTIONS.*/ } + its('content') { should match /^DefaultEnvironment="NODE_OPTIONS=#{node_options}"$/ } + its('content') { should match /^DefaultEnvironment="OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}"$/ } + its('content') { should match /^DefaultEnvironment="OTEL_SERVICE_NAME=test"$/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_PROFILER_ENABLED=true"$/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_PROFILER_MEMORY_ENABLED=true"$/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_METRICS_ENABLED=true"$/ } + its('content') { should match /^DefaultEnvironment="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 diff --git a/deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb b/deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb index a751d39ecc..b8920f4700 100644 --- a/deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb +++ b/deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb @@ -1,5 +1,6 @@ libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' java_tool_options = '-javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +node_options = '-r @splunk/otel/instrument' resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-\d+\.\d+\.\d+' otlp_endpoint = 'http://127.0.0.1:4317' @@ -25,6 +26,16 @@ its('content') { should match /^OTEL_EXPORTER_OTLP_ENDPOINT=#{otlp_endpoint}$/ } 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_not match /.*OTEL_SERVICE_NAME.*/ } + its('content') { should match /^SPLUNK_PROFILER_ENABLED=false$/ } + its('content') { should match /^SPLUNK_PROFILER_MEMORY_ENABLED=false$/ } + its('content') { should match /^SPLUNK_METRICS_ENABLED=false$/ } + 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 } diff --git a/deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb b/deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb index 2356f4ce22..b4fa9a2558 100644 --- a/deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb +++ b/deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb @@ -1,5 +1,6 @@ libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' java_tool_options = '-javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +node_options = '-r @splunk/otel/instrument' resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-\d+\.\d+\.\d+-systemd' otlp_endpoint = 'http://127.0.0.1:4317' @@ -13,6 +14,7 @@ describe file('/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf') do its('content') { should match /^DefaultEnvironment="JAVA_TOOL_OPTIONS=#{java_tool_options}"$/ } + its('content') { should match /^DefaultEnvironment="NODE_OPTIONS=#{node_options}"$/ } its('content') { should match /^DefaultEnvironment="OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}"$/ } its('content') { should_not match /.*OTEL_SERVICE_NAME.*/ } its('content') { should match /^DefaultEnvironment="SPLUNK_PROFILER_ENABLED=false"$/ }