Skip to content

Commit

Permalink
Added LWRP for New Relic Dot Net Core Agent install
Browse files Browse the repository at this point in the history
 Changes to be committed:
	modified:   .kitchen.yml
	modified:   attributes/repository.rb
	modified:   libraries/helpers.rb
	modified:   libraries/matchers.rb
	modified:   metadata.rb
	modified:   providers/agent_dotnet.rb
	new file:   providers/agent_dotnetcore.rb
	modified:   recipes/default.rb
	new file:   recipes/dotnetcore_agent.rb
	new file:   resources/agent_dotnetcore.rb
	modified:   spec/unit/agent_dotnet_spec.rb
	new file:   spec/unit/agent_dotnetcore_spec.rb
	modified:   spec/unit/agent_php_spec.rb
	modified:   spec/unit/default_spec.rb
	modified:   spec/unit/repository_spec.rb
	new file:   test/fixtures/cookbooks/newrelic_lwrp_test/recipes/agent_dotnetcore.rb
	modified:   test/fixtures/cookbooks/newrelic_lwrp_test/recipes/agent_php.rb
	new file:   test/integration/dotnetcore-agent/serverspec/default_spec.rb
  • Loading branch information
Chris Norman committed Dec 31, 2018
1 parent cf50a25 commit e69eed2
Show file tree
Hide file tree
Showing 18 changed files with 415 additions and 15 deletions.
14 changes: 12 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ platforms:
php_config: '/etc/php/7.0/mods-available/newrelic.ini'
nodejs:
repo: 'https://deb.nodesource.com/node_6.x'
- name: ubuntu-17.04
- name: ubuntu-18.04
run_list:
- recipe[apt]
attributes:
Expand Down Expand Up @@ -85,6 +85,15 @@ suites:
service_notify_action: nothing
service_actions:
- nothing
- name: dotnetcore-agent
run_list:
- recipe[newrelic_lwrp_test::agent_dotnetcore]
excludes:
- centos-6.8 # dotnet Core 2.0 only supported on Centos 7 or later
attributes:
newrelic:
dotnetcore_agent:
enable_module: true
- name: php-agent
run_list: "recipe[newrelic_lwrp_test::agent_php]"
attributes:
Expand All @@ -103,8 +112,9 @@ suites:
newrelic:
php_agent:
execute_php5enmod: true
# Server Monitor Deprecated
- name: server-monitor
run_list: "recipe[newrelic_lwrp_test::server_monitor]"
git run_list: "recipe[newrelic_lwrp_test::server_monitor]"
- name: infrastructure-agent
run_list: "recipe[newrelic_lwrp_test::agent_infrastructure]"
excludes:
Expand Down
5 changes: 3 additions & 2 deletions attributes/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
# Copyright (c) 2016, David Joos
#

default['newrelic']['repository']['key'] = 'http://download.newrelic.com/548C16BF.gpg'
default['newrelic']['repository']['ssl_verify'] = true
default['newrelic']['repository']['key'] = 'http://download.newrelic.com/548C16BF.gpg'

case node['platform_family']
when 'debian'
default['newrelic']['repository']['uri'] = 'http://download.newrelic.com/debian/'
default['newrelic']['repository']['distribution'] = 'newrelic'
default['newrelic']['repository']['components'] = ['non-free']
when 'rhel', 'fedora', 'amazon'
default['newrelic']['repository']['uri'] = 'http://download.newrelic.com/pub/newrelic/el5/$basearch/'
default['newrelic']['repository']['uri'] = 'http://yum.newrelic.com/pub/newrelic/el7/$basearch'
default['newrelic']['repository']['proxy'] = node['newrelic']['proxy']
default['newrelic']['repository']['proxy_username'] = nil
default['newrelic']['repository']['proxy_password'] = nil
Expand Down
4 changes: 3 additions & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def install_newrelic_repo_debian

def install_newrelic_repo_rhel
yum_repository 'newrelic' do
description 'New Relic packages for Enterprise Linux 5 - $basearch'
description 'New Relic packages for Enterprise Linux 5'
baseurl node['newrelic']['repository']['uri']
gpgkey node['newrelic']['repository']['key']
enabled true
gpgcheck true
sslverify node['newrelic']['repository']['ssl_verify']
proxy node['newrelic']['repository']['proxy'] unless node['newrelic']['repository']['proxy'].nil?
proxy_username node['newrelic']['repository']['proxy_username'] unless node['newrelic']['repository']['proxy_username'].nil?
Expand Down
17 changes: 17 additions & 0 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ChefSpec.define_matcher :newrelic_agent_java
ChefSpec.define_matcher :newrelic_agent_ruby
ChefSpec.define_matcher :newrelic_agent_dotnet
ChefSpec.define_matcher :newrelic_agent_dotnetcore
ChefSpec.define_matcher :newrelic_agent_python
ChefSpec.define_matcher :newrelic_agent_nodejs

Expand Down Expand Up @@ -32,6 +33,22 @@ def install_newrelic_agent_dotnet(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:newrelic_agent_dotnet, :install, resource_name)
end

def install_newrelic_agent_dotnetcore(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:newrelic_agent_dotnetcore, :install, resource_name)
end

def unzip_newrelic_agent(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:zipfile, :extract, resource_name)
end

def create_coreclr_newrelic_home(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:magic_shell_environment, :add, resource_name)
end

def create_windows_envriomental_variable(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:env, :create, resource_name)
end

def install_newrelic_agent_python(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:newrelic_agent_python, :install, resource_name)
end
Expand Down
4 changes: 4 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
depends 'apt'
depends 'yum'

depends 'zipfile', '~> 0.2.0'
depends 'magic_shell', '~> 1.0.0'

recipe 'newrelic', 'Adds the New Relic repository, installs & configures the New Relic server monitor agent.'
recipe 'newrelic::repository', 'Adds the New Relic repository.'
recipe 'newrelic::server_monitor_agent', 'Installs & configures the New Relic server monitor agent.'
recipe 'newrelic::dotnet_agent', 'Installs New Relic .NET agent.'
recipe 'newrelic::dotnetcore_agent', 'Installs the New Relic .Net Core 2.0 agent'
recipe 'newrelic::infrastructure_agent', 'Installs New Relic Infrastructure agent.'
recipe 'newrelic::java_agent', 'Installs the New Relic Java agent.'
recipe 'newrelic::nodejs_agent', 'Installs New Relic Node.js agent.'
Expand Down
2 changes: 1 addition & 1 deletion providers/agent_dotnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def install_newrelic
not_if { ::File.exist?('C:\\Program Files\\New Relic\\.NET Agent') }
end

template "#{new_resource.config_dir}/newrelic.config" do
template "#{new_resource.config_dir}\\newrelic.config" do
cookbook new_resource.cookbook
source new_resource.source
variables(
Expand Down
104 changes: 104 additions & 0 deletions providers/agent_dotnetcore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#
# Cookbook Name:: newrelic
# Recipe:: agent_dotnetcore
#
#

# include helper methods
include NewRelic::Helpers

use_inline_resources if defined?(use_inline_resources)

action :install do
check_license
newrelic_repository
newrelic_install
end

action :remove do
remove_newrelic
end

def newrelic_install
# run newrelic-install dependent on execution platform_family
case node['platform_family']
when 'debian', 'rhel', 'amazon'
install_newrelic_dotnetcore_linux
when 'windows'
install_newrelic_dotnetcore_windows
end
end

def install_newrelic_dotnetcore_linux
case node['platform_family']
when 'debian'
install_newrelic_apt
when 'rhel', 'amazon'
install_newrelic_yum
end

magic_shell_environment 'CORECLR_NEWRELIC_HOME' do
action :add
value new_resource.CoreCLR_NewRelic_home
end

template "#{new_resource.CoreCLR_NewRelic_home}/newrelic.config" do
cookbook new_resource.cookbook
source new_resource.source
variables(
:resource => new_resource
)
sensitive true
end
end

def install_newrelic_apt
apt_update 'update' do
action :update
end
apt_package 'Install New Relic .Net Core Agent using apt' do
package_name 'newrelic-netcore20-agent'
action :upgrade
end
end

def install_newrelic_yum
yum_package 'newrelic-netcore20-agent' do
flush_cache [:before]
allow_downgrade true
package_name 'newrelic-netcore20-agent'
action :install
end
end

def install_newrelic_dotnetcore_windows
zipfile 'unzip source to NewRelic directory' do
from new_resource.https_download
into new_resource.config_dir
not_if { ::File.exist?('#{new_resource.config_dir}\NewRelic.Profiler.dll') }
end

env 'CORECLR_NEWRELIC_HOME' do
action :create
value new_resource.config_dir
end

env 'CORECLR_PROFILER' do
action :create
value '{36032161-FFC0-4B61-B559-F6C5D41BAE5A}'
end

env 'CORECLR_PROFILER_PATH' do
action :create
value '%CORECLR_NEWRELIC_HOME%\NewRelic.Profiler.dll'
end

template "#{new_resource.config_dir}\\newrelic.config" do
cookbook new_resource.cookbook
source new_resource.source
variables(
:resource => new_resource
)
sensitive true
end
end
3 changes: 3 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
# Copyright (c) 2016, David Joos
#

# Deprecated July 2018 when NEw RElic shut down the Server Monitor listener
# infavor of the infrastructure agent

include_recipe 'newrelic::server_monitor_agent'
12 changes: 12 additions & 0 deletions recipes/dotnetcore_agent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Cookbook Name:: newrelic
# Recipe:: dotnet_agent
#
#
#

newrelic_agent_dotnetcore 'Install' do
https_download node['newrelic']['dotnetcore_agent']['https_download'] unless node['newrelic']['dotnetcore_agent']['https_download'].nil?
# install_level node['newrelic']['dotnet_agent']['install_level'] unless node['newrelic']['dotnet_agent']['install_level'].nil?
license lazy { NewRelic.application_monitoring_license(node) }
end
101 changes: 101 additions & 0 deletions resources/agent_dotnetcore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#
# Cookbook Name:: newrelic
# Resource:: agent_dotnetcore
#
#

actions :install, :remove
default_action :install

attribute :CoreCLR_NewRelic_home, :kind_of => String, :default => '/usr/local/newrelic-netcore20-agent'
attribute :https_download, :kind_of => String, :default => 'http://download.newrelic.com/dot_net_agent/latest_release/newrelic-netcore20-agent-win-x64-8.5.186.0.zip'
attribute :install_level, :kind_of => String, :default => '1'
attribute :config_dir, :kind_of => String, :default => 'C:\New Relic\newrelic-netcore20-agent'
attribute :cookbook, :kind_of => String, :default => 'newrelic'
attribute :source, :kind_of => String, :default => 'agent/dotnet/newrelic.config.erb'

attribute :enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :max_stack_trace_lines, :kind_of => Integer, :default => 80
attribute :timing_precision, :kind_of => String, :default => 'low'

attribute :license, :kind_of => String, :default => lazy { NewRelic.application_monitoring_license(node) }
attribute :daemon_ssl, :kind_of => [TrueClass, FalseClass], :default => true
attribute :svc_send_env_info, :kind_of => [TrueClass, FalseClass], :default => true
attribute :svc_sync_startup, :kind_of => [TrueClass, FalseClass], :default => false
attribute :svc_send_data_on_exit, :kind_of => [TrueClass, FalseClass], :default => false
attribute :svc_send_data_on_exit_threshold, :kind_of => Integer, :default => 60_000
attribute :svc_auto_start, :kind_of => [TrueClass, FalseClass], :default => true

attribute :use_proxy, :kind_of => [TrueClass, FalseClass], :default => false
attribute :proxy_host, :kind_of => String, :default => ''
attribute :proxy_port, :kind_of => Integer, :default => 8080
attribute :proxy_domain, :kind_of => String, :default => ''
attribute :proxy_user, :kind_of => String, :default => ''
attribute :proxy_password, :kind_of => String, :default => ''

attribute :app_log_level, :kind_of => String, :default => 'info'
attribute :audit_log_enabled, :kind_of => [TrueClass, FalseClass], :default => false
attribute :log_to_console, :kind_of => [TrueClass, FalseClass], :default => false
attribute :log_directory, :kind_of => String, :default => 'C:\ProgramData\New Relic\.NETCore Agent\Logs'
attribute :log_file_name, :kind_of => String, :default => 'newrelic.log'

attribute :app_name, :kind_of => String, :default => 'Default Application'
attribute :app_disable_samplers, :kind_of => [TrueClass, FalseClass], :default => false

attribute :instrumentation_applications, :kind_of => Array, :default => []
attribute :instrumentation_log_enable, :kind_of => [TrueClass, FalseClass], :default => false

attribute :attributes_collection_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :attributes_exclude, :kind_of => Array, :default => []
attribute :attributes_include, :kind_of => Array, :default => []

attribute :app_pools, :kind_of => Array, :default => [] # [{name: '', instrument: true|false}]
attribute :app_pools_instrument_default_behavior, :kind_of => [TrueClass, FalseClass], :default => false

attribute :cross_application_tracer_enabled, :kind_of => [TrueClass, FalseClass], :default => true

attribute :error_collector_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :ignored_exceptions, :kind_of => Array, :default => [
'System.IO.FileNotFoundException',
'System.Threading.ThreadAbortException'
]
attribute :ignored_status_codes, :kind_of => Array, :default => [401, 404]

attribute :high_security_enabled, :kind_of => [TrueClass, FalseClass], :default => false

attribute :tx_events_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :tx_events_max_samples_per_minute, :kind_of => Integer, :default => 10_000
attribute :tx_events_max_samples_stored, :kind_of => Integer, :default => 10_000
attribute :tx_events_attributes_collection_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :tx_events_attributes_exclude, :kind_of => Array, :default => []
attribute :tx_events_attributes_include, :kind_of => Array, :default => []

attribute :custom_events_enabled, :kind_of => [TrueClass, FalseClass], :default => true

attribute :labels, :kind_of => String, :default => ''

attribute :browser_monitoring_auto_instrument, :kind_of => [TrueClass, FalseClass], :default => true
attribute :browser_monitoring_req_paths_excluded, :kind_of => Array, :default => []
attribute :browser_monitoring_attributes_collection_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :browser_monitoring_attributes_exclude, :kind_of => Array, :default => []
attribute :browser_monitoring_attributes_include, :kind_of => Array, :default => []

attribute :slow_queries_enabled, :kind_of => [TrueClass, FalseClass], :default => true

attribute :tx_tracer_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :tx_tracer_transaction_threshold, :kind_of => String, :default => 'apdex_f'
attribute :tx_tracer_stack_trace_threshold, :kind_of => Integer, :default => 500
attribute :tx_tracer_record_sql, :kind_of => String, :default => 'obfuscated'
attribute :tx_tracer_explain_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :tx_tracer_explain_threshold, :kind_of => Integer, :default => 500
attribute :tx_tracer_max_segments, :kind_of => Integer, :default => 3_000
attribute :tx_tracer_max_stack_trace, :kind_of => Integer, :default => 30
attribute :tx_tracer_max_explain_plans, :kind_of => Integer, :default => 20
attribute :tx_tracer_attributes_collection_enabled, :kind_of => [TrueClass, FalseClass], :default => true
attribute :tx_tracer_attributes_exclude, :kind_of => Array, :default => []
attribute :tx_tracer_attributes_include, :kind_of => Array, :default => []

attribute :ignored_thread_profiling_methods, :kind_of => Array, :default => [
'System.Threading.WaitHandle:InternalWaitOne',
'System.Threading.WaitHandle:WaitAny'
]
4 changes: 4 additions & 0 deletions spec/unit/agent_dotnet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
it 'Install New Relic .NET Agent (windows_package)' do
expect(chef_run).to install_windows_package('Install New Relic .NET Agent')
end

it 'Create newrelic.config file' do
expect(chef_run).to render_file('C:\ProgramData\New Relic\.NET Agent\newrelic.config').with_content('0000ffff0000ffff0000ffff0000ffff0000ffff')
end
end
end
Loading

0 comments on commit e69eed2

Please sign in to comment.