Skip to content

Commit

Permalink
chef: support .NET zero config on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk committed May 6, 2024
1 parent a006288 commit eb80a37
Show file tree
Hide file tree
Showing 30 changed files with 528 additions and 14 deletions.
8 changes: 8 additions & 0 deletions deployments/chef/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## chef-v0.14.0

- Initial support for [Splunk OpenTelemetry for .NET](https://github.com/signalfx/splunk-otel-dotnet) Auto
Instrumentation on Linux (x86_64/amd64 only):
- The .NET SDK is activated by default if the `with_auto_instrumentation` option is set to `true` and
`auto_instrumentation_version` is `latest` or >= `0.99.0`.
- Set the `with_auto_instrumentation_sdks` option to `java` and/or `nodejs` to skip .NET auto instrumentation.

## chef-v0.13.0

- Only copy the collector configuration file to `ProgramData` if the source exists.
Expand Down
6 changes: 4 additions & 2 deletions deployments/chef/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ after installation/configuration in order for any change to take effect.

- `with_auto_instrumentation_sdks`: List of Splunk OpenTelemetry Auto
Instrumentation SDKs to install, configure, and activate. (**default:**
`%w(java nodejs)`)
`%w(java nodejs dotnet)`)

Currently, the following values are supported:
- `java`: [Splunk OpenTelemetry for Java](https://github.com/signalfx/splunk-otel-java)
- `nodejs`: [Splunk OpenTelemetry for Node.js](https://github.com/signalfx/splunk-otel-js)
- `dotnet` [Splunk OpenTelemetry for .NET](https://github.com/signalfx/splunk-otel-dotnet) (x86_64/amd64 only)

**Note:** This recipe does not manage the installation/configuration of
Node.js, `npm`, or Node.js applications. If `nodejs` is included in this
Expand All @@ -203,7 +204,8 @@ after installation/configuration in order for any change to take effect.
- `auto_instrumentation_version`: Version of the
`splunk-otel-auto-instrumentation` package to install, e.g. `0.50.0`. The
minimum supported version is `0.48.0`. The minimum supported version for
Node.js auto instrumentation is `0.87.0`. (**default:** `latest`)
Node.js auto instrumentation is `0.87.0`. The minimum supported version for
.NET auto instrumentation is `0.99.0`. (**default:** `latest`)

- `auto_instrumentation_systemd` (Linux only): By default, the
`/etc/ld.so.preload` file on the node will be configured for the
Expand Down
2 changes: 1 addition & 1 deletion deployments/chef/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@
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 nodejs)
default['splunk_otel_collector']['with_auto_instrumentation_sdks'] = %w(java nodejs dotnet)
default['splunk_otel_collector']['auto_instrumentation_npm_path'] = 'npm'
end
8 changes: 4 additions & 4 deletions deployments/chef/kitchen.windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ suites:
remote_exec: true
command: inspec exec custom_vars/test.rb

- name: with_default_dotnet_instrumentation
- name: with_default_windows_dotnet_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
Expand All @@ -76,9 +76,9 @@ suites:
verifier:
name: shell
remote_exec: true
command: inspec exec with_default_dotnet_instrumentation/test.rb
command: inspec exec with_default_windows_dotnet_instrumentation/test.rb

- name: with_custom_dotnet_instrumentation
- name: with_custom_windows_dotnet_instrumentation
run_list:
- recipe[splunk_otel_collector]
attributes:
Expand All @@ -99,4 +99,4 @@ suites:
verifier:
name: shell
remote_exec: true
command: inspec exec with_custom_dotnet_instrumentation/test.rb
command: inspec exec with_custom_windows_dotnet_instrumentation/test.rb
59 changes: 59 additions & 0 deletions deployments/chef/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,65 @@ suites:
auto_instrumentation_enable_metrics: true
auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317

- name: with_default_preload_dotnet_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:
- dotnet

- name: with_custom_preload_dotnet_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:
- dotnet
auto_instrumentation_ld_so_preload: "# my extra library"
auto_instrumentation_resource_attributes: deployment.environment=test
auto_instrumentation_service_name: test
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_dotnet_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:
- dotnet
auto_instrumentation_systemd: true

- name: with_custom_systemd_dotnet_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:
- dotnet
auto_instrumentation_systemd: true
auto_instrumentation_resource_attributes: deployment.environment=test
auto_instrumentation_service_name: test
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_preload_instrumentation_without_npm
run_list:
- recipe[splunk_otel_collector]
Expand Down
2 changes: 1 addition & 1 deletion deployments/chef/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Install/Configure the Splunk OpenTelemetry Collector'
version '0.13.0'
version '0.14.0'
chef_version '>= 16.0'

supports 'amazon'
Expand Down
26 changes: 21 additions & 5 deletions deployments/chef/recipes/auto_instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
with_systemd = node['splunk_otel_collector']['auto_instrumentation_systemd'].to_s.downcase == 'true'
with_java = node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('java')
with_nodejs = node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('nodejs') && with_new_instrumentation
dotnet_supported = %w(x86_64 amd64).include?(node['cpu']['architecture']) && (node['splunk_otel_collector']['auto_instrumentation_version'] == 'latest' || Gem::Version.new(node['splunk_otel_collector']['auto_instrumentation_version']) >= Gem::Version.new('0.99.0'))
with_dotnet = node['splunk_otel_collector']['with_auto_instrumentation_sdks'].include?('dotnet') && dotnet_supported
npm_path = node['splunk_otel_collector']['auto_instrumentation_npm_path']
lib_dir = '/usr/lib/splunk-instrumentation'
splunk_otel_js_path = "#{lib_dir}/splunk-otel-js.tgz"
Expand All @@ -13,6 +15,7 @@
zc_config_dir = '/etc/splunk/zeroconfig'
java_config_file = "#{zc_config_dir}/java.conf"
nodejs_config_file = "#{zc_config_dir}/node.conf"
dotnet_config_file = "#{zc_config_dir}/dotnet.conf"
old_config_file = "#{lib_dir}/instrumentation.conf"
systemd_config_dir = '/usr/lib/systemd/system.conf.d'
systemd_config_file = "#{systemd_config_dir}/00-splunk-otel-auto-instrumentation.conf"
Expand Down Expand Up @@ -66,7 +69,7 @@
end

if with_systemd
[java_config_file, nodejs_config_file, old_config_file].each do |config_file|
[java_config_file, nodejs_config_file, dotnet_config_file, old_config_file].each do |config_file|
file config_file do
action :delete
end
Expand All @@ -78,11 +81,12 @@
variables(
installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] },
with_java: lazy { with_java },
with_nodejs: lazy { node.run_state[:with_nodejs] }
with_nodejs: lazy { node.run_state[:with_nodejs] },
with_dotnet: lazy { with_dotnet }
)
source '00-splunk-otel-auto-instrumentation.conf.erb'
notifies :run, 'execute[reload systemd]', :delayed
only_if { with_java || node.run_state[:with_nodejs] }
only_if { with_java || node.run_state[:with_nodejs] || with_dotnet }
end
elsif with_new_instrumentation
[old_config_file, systemd_config_file].each do |config_file|
Expand All @@ -98,6 +102,10 @@
action :delete
not_if { node.run_state[:with_nodejs] }
end
file dotnet_config_file do
action :delete
not_if { with_dotnet }
end
directory zc_config_dir do
recursive true
end
Expand All @@ -115,8 +123,15 @@
source 'node.conf.erb'
only_if { node.run_state[:with_nodejs] }
end
template dotnet_config_file do
variables(
installed_version: lazy { node['packages']['splunk-otel-auto-instrumentation']['version'] }
)
source 'dotnet.conf.erb'
only_if { with_dotnet }
end
else
[java_config_file, nodejs_config_file, systemd_config_file].each do |config_file|
[java_config_file, nodejs_config_file, dotnet_config_file, systemd_config_file].each do |config_file|
file config_file do
action :delete
end
Expand All @@ -134,7 +149,8 @@
variables(
with_systemd: lazy { with_systemd },
with_java: lazy { with_java },
with_nodejs: lazy { node.run_state[:with_nodejs] }
with_nodejs: lazy { node.run_state[:with_nodejs] },
with_dotnet: lazy { with_dotnet }
)
source 'ld.so.preload.erb'
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ DefaultEnvironment="JAVA_TOOL_OPTIONS=-javaagent:<%= node['splunk_otel_collector
<% if @with_nodejs -%>
DefaultEnvironment="NODE_OPTIONS=-r /usr/lib/splunk-instrumentation/splunk-otel-js/node_modules/@splunk/otel/instrument"
<% end -%>
<% if @with_dotnet -%>
DefaultEnvironment="CORECLR_ENABLE_PROFILING=1"
DefaultEnvironment="CORECLR_PROFILER={918728DD-259F-4A6A-AC2B-B85E1B658318}"
DefaultEnvironment="CORECLR_PROFILER_PATH=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so"
DefaultEnvironment="DOTNET_ADDITIONAL_DEPS=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/AdditionalDeps"
DefaultEnvironment="DOTNET_SHARED_STORE=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/store"
DefaultEnvironment="DOTNET_STARTUP_HOOKS=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll"
DefaultEnvironment="OTEL_DOTNET_AUTO_HOME=/usr/lib/splunk-instrumentation/splunk-otel-dotnet"
DefaultEnvironment="OTEL_DOTNET_AUTO_PLUGINS=Splunk.OpenTelemetry.AutoInstrumentation.Plugin,Splunk.OpenTelemetry.AutoInstrumentation"
<% 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
20 changes: 20 additions & 0 deletions deployments/chef/templates/dotnet.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CORECLR_ENABLE_PROFILING=1
CORECLR_PROFILER={918728DD-259F-4A6A-AC2B-B85E1B658318}
CORECLR_PROFILER_PATH=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so
DOTNET_ADDITIONAL_DEPS=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/AdditionalDeps
DOTNET_SHARED_STORE=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/store
DOTNET_STARTUP_HOOKS=/usr/lib/splunk-instrumentation/splunk-otel-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll
OTEL_DOTNET_AUTO_HOME=/usr/lib/splunk-instrumentation/splunk-otel-dotnet
OTEL_DOTNET_AUTO_PLUGINS=Splunk.OpenTelemetry.AutoInstrumentation.Plugin,Splunk.OpenTelemetry.AutoInstrumentation
<% 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'] %>
2 changes: 1 addition & 1 deletion deployments/chef/templates/ld.so.preload.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if !@with_systemd && (@with_java || @with_nodejs) -%>
<% if !@with_systemd && (@with_java || @with_nodejs || @with_dotnet) -%>
/usr/lib/splunk-instrumentation/libsplunk.so
<% end -%>
<% if defined?(node['splunk_otel_collector']['auto_instrumentation_ld_so_preload']) && node['splunk_otel_collector']['auto_instrumentation_ld_so_preload'] != "" -%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
libsplunk_path = '/usr/lib/splunk-instrumentation/libsplunk.so'
resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-\d+\.\d+\.\d+,deployment.environment=test'
otlp_endpoint = 'http://0.0.0.0:4317'
ld_preload_line = '# my extra library'
dotnet_home = '/usr/lib/splunk-instrumentation/splunk-otel-dotnet'

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

describe npm('@splunk/otel', path: '/usr/lib/splunk-instrumentation/splunk-otel-js') 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}$/ }
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
it { should_not exist }
end

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

describe file('/etc/splunk/zeroconfig/dotnet.conf') do
its('content') { should match /^CORECLR_ENABLE_PROFILING=1$/ }
its('content') { should match /^CORECLR_PROFILER=\{918728DD-259F-4A6A-AC2B-B85E1B658318\}$/ }
its('content') { should match %r{^CORECLR_PROFILER_PATH=#{dotnet_home}/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so$} }
its('content') { should match %r{^DOTNET_ADDITIONAL_DEPS=#{dotnet_home}/AdditionalDeps$} }
its('content') { should match %r{^DOTNET_SHARED_STORE=#{dotnet_home}/store$} }
its('content') { should match %r{^DOTNET_STARTUP_HOOKS=#{dotnet_home}/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll$} }
its('content') { should match /^OTEL_DOTNET_AUTO_HOME=#{dotnet_home}$/ }
its('content') { should match /^OTEL_DOTNET_AUTO_PLUGINS=Splunk.OpenTelemetry.AutoInstrumentation.Plugin,Splunk.OpenTelemetry.AutoInstrumentation$/ }
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 @@ -4,6 +4,7 @@
resource_attributes = 'splunk.zc.method=splunk-otel-auto-instrumentation-\d+\.\d+\.\d+,deployment.environment=test'
otlp_endpoint = 'http://0.0.0.0:4317'
ld_preload_line = '# my extra library'
dotnet_home = '/usr/lib/splunk-instrumentation/splunk-otel-dotnet'

describe package('splunk-otel-auto-instrumentation') do
it { should be_installed }
Expand Down Expand Up @@ -46,6 +47,23 @@
its('content') { should match /^OTEL_EXPORTER_OTLP_ENDPOINT=#{otlp_endpoint}$/ }
end

describe file('/etc/splunk/zeroconfig/dotnet.conf') do
its('content') { should match /^CORECLR_ENABLE_PROFILING=1$/ }
its('content') { should match /^CORECLR_PROFILER=\{918728DD-259F-4A6A-AC2B-B85E1B658318\}$/ }
its('content') { should match %r{^CORECLR_PROFILER_PATH=#{dotnet_home}/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so$} }
its('content') { should match %r{^DOTNET_ADDITIONAL_DEPS=#{dotnet_home}/AdditionalDeps$} }
its('content') { should match %r{^DOTNET_SHARED_STORE=#{dotnet_home}/store$} }
its('content') { should match %r{^DOTNET_STARTUP_HOOKS=#{dotnet_home}/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll$} }
its('content') { should match /^OTEL_DOTNET_AUTO_HOME=#{dotnet_home}$/ }
its('content') { should match /^OTEL_DOTNET_AUTO_PLUGINS=Splunk.OpenTelemetry.AutoInstrumentation.Plugin,Splunk.OpenTelemetry.AutoInstrumentation$/ }
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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
it { should_not exist }
end

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

describe file('/usr/lib/splunk-instrumentation/instrumentation.conf') do
it { should_not exist }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
it { should_not exist }
end

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

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

0 comments on commit eb80a37

Please sign in to comment.