From 7ad2ee62801df6d54cf2305ad4a2727f30ebfe47 Mon Sep 17 00:00:00 2001 From: jeffreyc-splunk Date: Wed, 8 Nov 2023 15:21:49 -0500 Subject: [PATCH] test --- .github/workflows/chef-test.yml | 1 + deployments/chef/attributes/default.rb | 2 + deployments/chef/kitchen.yml | 57 +++++++++++++++++++ .../chef/recipes/auto_instrumentation.rb | 47 +++++++++++++-- ...-splunk-otel-auto-instrumentation.conf.erb | 14 +++++ .../chef/templates/instrumentation.conf.erb | 4 +- deployments/chef/templates/java.conf.erb | 13 +++++ ...ith_custom_preload_instrumentation_spec.rb | 36 ++++++++++++ ...ith_custom_systemd_instrumentation_spec.rb | 35 ++++++++++++ ...th_default_preload_instrumentation_spec.rb | 36 ++++++++++++ ...th_default_systemd_instrumentation_spec.rb | 35 ++++++++++++ .../inspec/with_instrumentation_spec.rb | 4 +- 12 files changed, 275 insertions(+), 9 deletions(-) create mode 100644 deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb create mode 100644 deployments/chef/templates/java.conf.erb create mode 100644 deployments/chef/test/integration/with_custom_preload_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb create mode 100644 deployments/chef/test/integration/with_custom_systemd_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb create mode 100644 deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb create mode 100644 deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb diff --git a/.github/workflows/chef-test.yml b/.github/workflows/chef-test.yml index 977d49b110..78f30be4f1 100644 --- a/.github/workflows/chef-test.yml +++ b/.github/workflows/chef-test.yml @@ -5,6 +5,7 @@ on: push: branches: - main + - chef-new-zeroconfig paths: - '.github/workflows/chef-test.yml' - 'deployments/chef/**' diff --git a/deployments/chef/attributes/default.rb b/deployments/chef/attributes/default.rb index 32d84db401..1b064c66ed 100644 --- a/deployments/chef/attributes/default.rb +++ b/deployments/chef/attributes/default.rb @@ -89,6 +89,7 @@ default['splunk_otel_collector']['with_auto_instrumentation'] = false default['splunk_otel_collector']['auto_instrumentation_version'] = 'latest' + default['splunk_otel_collector']['auto_instrumentation_systemd'] = false default['splunk_otel_collector']['auto_instrumentation_ld_so_preload'] = '' default['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] = '/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' default['splunk_otel_collector']['auto_instrumentation_resource_attributes'] = '' @@ -98,4 +99,5 @@ default['splunk_otel_collector']['auto_instrumentation_enable_profiler'] = false 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' end diff --git a/deployments/chef/kitchen.yml b/deployments/chef/kitchen.yml index 0811c02a4c..07538c78f0 100644 --- a/deployments/chef/kitchen.yml +++ b/deployments/chef/kitchen.yml @@ -169,6 +169,7 @@ suites: splunk_access_token: testing123 splunk_realm: test with_auto_instrumentation: true + auto_instrumentation_version: 0.86.0 auto_instrumentation_resource_attributes: deployment.environment=test auto_instrumentation_service_name: test auto_instrumentation_generate_service_name: false @@ -176,3 +177,59 @@ suites: auto_instrumentation_enable_profiler: true auto_instrumentation_enable_profiler_memory: true auto_instrumentation_enable_metrics: true + + - name: with_default_preload_instrumentation + run_list: + - recipe[splunk_otel_collector] + attributes: + splunk_otel_collector: + splunk_access_token: testing123 + splunk_realm: test + with_auto_instrumentation: true + + - name: with_custom_preload_instrumentation + run_list: + - recipe[splunk_otel_collector] + attributes: + splunk_otel_collector: + splunk_access_token: testing123 + splunk_realm: test + with_auto_instrumentation: true + auto_instrumentation_version: 0.87.0 + 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_default_systemd_instrumentation + run_list: + - recipe[splunk_otel_collector] + attributes: + splunk_otel_collector: + splunk_access_token: testing123 + splunk_realm: test + with_auto_instrumentation: true + auto_instrumentation_systemd: true + + - name: with_custom_systemd_instrumentation + run_list: + - recipe[splunk_otel_collector] + attributes: + splunk_otel_collector: + splunk_access_token: testing123 + splunk_realm: test + with_auto_instrumentation: true + auto_instrumentation_version: 0.87.0 + 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 diff --git a/deployments/chef/recipes/auto_instrumentation.rb b/deployments/chef/recipes/auto_instrumentation.rb index 499f5e51c4..cb29b9f535 100644 --- a/deployments/chef/recipes/auto_instrumentation.rb +++ b/deployments/chef/recipes/auto_instrumentation.rb @@ -1,6 +1,11 @@ # Cookbook:: splunk_otel_collector # Recipe:: auto_instrumentation +ohai 'reload packages' do + plugin 'packages' + action :nothing +end + package 'splunk-otel-auto-instrumentation' do action :install version node['splunk_otel_collector']['auto_instrumentation_version'] if node['splunk_otel_collector']['auto_instrumentation_version'] != 'latest' @@ -10,12 +15,42 @@ && node['packages']['apt'] \ && Gem::Version.new(node['packages']['apt']['version'].split('~')[0]) >= Gem::Version.new('1.1.0') allow_downgrade true if platform_family?('amazon', 'rhel', 'suse') + notifies :reload, 'ohai[reload packages]', :immediately end -template '/etc/ld.so.preload' do - source 'ld.so.preload.erb' -end - -template '/usr/lib/splunk-instrumentation/instrumentation.conf' do - source 'instrumentation.conf.erb' +if node['splunk_otel_collector']['auto_instrumentation_systemd'].to_s.downcase == 'true' + directory '/usr/lib/systemd/system.conf.d' do + recursive true + action :create + end + template '/usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf' do + variables( + installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] } + ) + source '00-splunk-otel-auto-instrumentation.conf.erb' + notifies :run, 'execute[reload systemd]', :immediately + end + execute 'reload systemd' do + command 'systemctl daemon-reload' + action :nothing + end +else + template '/etc/ld.so.preload' do + source 'ld.so.preload.erb' + 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' + end + else + template '/usr/lib/splunk-instrumentation/instrumentation.conf' do + variables( + installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] } + ) + source 'instrumentation.conf.erb' + end + end end diff --git a/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb b/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb new file mode 100644 index 0000000000..ba031595f5 --- /dev/null +++ b/deployments/chef/templates/00-splunk-otel-auto-instrumentation.conf.erb @@ -0,0 +1,14 @@ +[Manager] +DefaultEnvironment="JAVA_TOOL_OPTIONS=-javaagent:<%= node['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] %>" +<% 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 -%> +DefaultEnvironment="OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-<%= @installed_version %>-systemd +<% end -%> +<% if defined?(node['splunk_otel_collector']['auto_instrumentation_service_name']) && node['splunk_otel_collector']['auto_instrumentation_service_name'] != "" -%> +DefaultEnvironment="OTEL_SERVICE_NAME=<%= node['splunk_otel_collector']['auto_instrumentation_service_name'] %>" +<% end -%> +DefaultEnvironment="SPLUNK_PROFILER_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_profiler'].to_s.downcase %>" +DefaultEnvironment="SPLUNK_PROFILER_MEMORY_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_profiler_memory'].to_s.downcase %>" +DefaultEnvironment="SPLUNK_METRICS_ENABLED=<%= node['splunk_otel_collector']['auto_instrumentation_enable_metrics'].to_s.downcase %>" +DefaultEnvironment="OTEL_EXPORTER_OTLP_ENDPOINT=<%= node['splunk_otel_collector']['auto_instrumentation_otlp_endpoint'] %>" diff --git a/deployments/chef/templates/instrumentation.conf.erb b/deployments/chef/templates/instrumentation.conf.erb index cd38158e97..998c7613f6 100644 --- a/deployments/chef/templates/instrumentation.conf.erb +++ b/deployments/chef/templates/instrumentation.conf.erb @@ -1,6 +1,8 @@ java_agent_jar=<%= node['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] %> <% if defined?(node['splunk_otel_collector']['auto_instrumentation_resource_attributes']) && node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] != "" -%> -resource_attributes=<%= node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] %> +resource_attributes=splunk.zc.method=splunk-otel-auto-instrumentation-<%= @installed_version %>,<%= node['splunk_otel_collector']['auto_instrumentation_resource_attributes'] %> +<% else -%> +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'] != "" -%> service_name=<%= node['splunk_otel_collector']['auto_instrumentation_service_name'] %> diff --git a/deployments/chef/templates/java.conf.erb b/deployments/chef/templates/java.conf.erb new file mode 100644 index 0000000000..8f468bd585 --- /dev/null +++ b/deployments/chef/templates/java.conf.erb @@ -0,0 +1,13 @@ +JAVA_TOOL_OPTIONS=-javaagent:<%= node['splunk_otel_collector']['auto_instrumentation_java_agent_jar'] %> +<% 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_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb new file mode 100644 index 0000000000..3ecdb115c0 --- /dev/null +++ b/deployments/chef/test/integration/with_custom_preload_instrumentation/inspec/with_custom_preload_instrumentation_spec.rb @@ -0,0 +1,36 @@ +libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' +java_agent_path = '/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-0.87.0,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 match /^#{libsplunk_path}$/ } +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 + its('content') { should match /^JAVA_TOOL_OPTIONS=-javaagent:#{java_agent_path}$/ } + 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_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb new file mode 100644 index 0000000000..50b0e051ea --- /dev/null +++ b/deployments/chef/test/integration/with_custom_systemd_instrumentation/inspec/with_custom_systemd_instrumentation_spec.rb @@ -0,0 +1,35 @@ +java_tool_options = 'JAVA_TOOL_OPTIONS=-javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +resource_attributes = 'OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-0.87.0-systemd' +otlp_endpoint = 'http://0.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 match /^#{libsplunk_path}$/ } +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 + its('content') { should match /^DefaultEnvironment="#{java_tool_options}"$/ } + its('content') { should match /^DefaultEnvironment="#{resource_attributes},deployment.environment=test"$/ } + 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 new file mode 100644 index 0000000000..80c76dfade --- /dev/null +++ b/deployments/chef/test/integration/with_default_preload_instrumentation/inspec/with_default_preload_instrumentation_spec.rb @@ -0,0 +1,36 @@ +libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' +java_agent_path = '/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation' +otlp_endpoint = 'http://127.0.0.1:4317' + +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}$/ } +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 + its('content') { should match /^JAVA_TOOL_OPTIONS=-javaagent:#{java_agent_path}$/ } + its('content') { should match /^OTEL_RESOURCE_ATTRIBUTES=#{resource_attributes}-\d+\.\d+\.\d+$/ } + 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 } +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_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 new file mode 100644 index 0000000000..ed86e08c95 --- /dev/null +++ b/deployments/chef/test/integration/with_default_systemd_instrumentation/inspec/with_default_systemd_instrumentation_spec.rb @@ -0,0 +1,35 @@ +java_tool_options = 'JAVA_TOOL_OPTIONS=-javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' +resource_attributes = 'OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation' +otlp_endpoint = 'http://127.0.0.1:4317' + +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}$/ } +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 + its('content') { should match /^DefaultEnvironment="#{java_tool_options}"$/ } + its('content') { should match /^DefaultEnvironment="#{resource_attributes}-\d+\.\d+\.\d+-systemd"$/ } + its('content') { should_not match /.*OTEL_SERVICE_NAME.*/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_PROFILER_ENABLED=false"$/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_PROFILER_MEMORY_ENABLED=false"$/ } + its('content') { should match /^DefaultEnvironment="SPLUNK_METRICS_ENABLED=false"$/ } + 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_instrumentation/inspec/with_instrumentation_spec.rb b/deployments/chef/test/integration/with_instrumentation/inspec/with_instrumentation_spec.rb index 5201022aff..872c1186a4 100644 --- a/deployments/chef/test/integration/with_instrumentation/inspec/with_instrumentation_spec.rb +++ b/deployments/chef/test/integration/with_instrumentation/inspec/with_instrumentation_spec.rb @@ -1,6 +1,6 @@ libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so' java_agent_path = '/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar' -resource_attribute = 'deployment.environment=test' +resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-0.86.0,deployment.environment=test' service_name = 'test' describe package('splunk-otel-auto-instrumentation') do @@ -13,7 +13,7 @@ describe file('/usr/lib/splunk-instrumentation/instrumentation.conf') do its('content') { should match /^java_agent_jar=#{java_agent_path}$/ } - its('content') { should match /^resource_attributes=#{resource_attribute}$/ } + its('content') { should match /^resource_attributes=#{resource_attributes}$/ } its('content') { should match /^service_name=#{service_name}$/ } its('content') { should match /^generate_service_name=false$/ } its('content') { should match /^disable_telemetry=true$/ }