From 8134acaee98b6b831262053e48054889806901b2 Mon Sep 17 00:00:00 2001 From: Nandu-pns Date: Wed, 7 Jun 2023 16:22:06 +0530 Subject: [PATCH] feat: Add Dotnet support. --- README.md | 36 ++++---- attributes/default.rb | 5 +- resources/newrelic_install.rb | 4 +- spec/unit/resources/newrelic_install_spec.rb | 92 ++++++++++++++++++-- 4 files changed, 111 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 1263b3c..8511b71 100644 --- a/README.md +++ b/README.md @@ -60,27 +60,33 @@ end #### Required -| Name | Default value | Description | -|:-----|:--------------|:------------| -| `default['newrelic_install']['NEW_RELIC_API_KEY']` | `nil` | new relic api key | -| `default['newrelic_install']['NEW_RELIC_ACCOUNT_ID']` | `nil` | new relic account id | -| `default['newrelic_install']['targets']` | [] | agents to be installed, possible values are (`infrastructure-agent-installer`, `logs-integration`, `php-agent-installer`) | +| Name | Default value | Description | +|:------------------------------------------------------|:--------------|:----------------------------------------------------------------------------------------------------------------------------------------------------| +| `default['newrelic_install']['NEW_RELIC_API_KEY']` | `nil` | new relic api key | +| `default['newrelic_install']['NEW_RELIC_ACCOUNT_ID']` | `nil` | new relic account id | +| `default['newrelic_install']['targets']` | [] | agents to be installed, possible values are (`infrastructure-agent-installer`, `logs-integration`, `php-agent-installer`, `dotnet-agent-installer`) | #### Optional -| Name | Default value | Description | -|:-----|:--------------|:------------| -| `default['newrelic_install']['NEW_RELIC_REGION']` | `US` | new relic regions for your account (`US` or `EU`) | -| `default['newrelic_install']['env']['HTTPS_PROXY']` | `nil` | proxy url if you are behind a firewall | -| `default['newrelic_install']['verbosity']` | `nil` | Verbosity options for the installation (`debug` or `trace`). Writes verbose output to a log file on the host. | -| `default['newrelic_install']['tags']` | `{}` | key value pair tags added through custom attributes | -| `default['newrelic_install']['timeout_seconds']` | `600` | Sets timeout for installation task. | +| Name | Default value | Description | +|:----------------------------------------------------|:--------------|:--------------------------------------------------------------------------------------------------------------| +| `default['newrelic_install']['NEW_RELIC_REGION']` | `US` | new relic regions for your account (`US` or `EU`) | +| `default['newrelic_install']['env']['HTTPS_PROXY']` | `nil` | proxy url if you are behind a firewall | +| `default['newrelic_install']['verbosity']` | `nil` | Verbosity options for the installation (`debug` or `trace`). Writes verbose output to a log file on the host. | +| `default['newrelic_install']['tags']` | `{}` | key value pair tags added through custom attributes | +| `default['newrelic_install']['timeout_seconds']` | `600` | Sets timeout for installation task. | #### PHP Agent -| Name | Default value | Description | -|:-----|:--------------|:------------| -| `default['newrelic_install']['env']['NEW_RELIC_APPLICATION_NAME']` | `nil` | optional name for your php application | +| Name | Default value | Description | +|:-------------------------------------------------------------------|:--------------|:---------------------------------------| +| `default['newrelic_install']['env']['NEW_RELIC_APPLICATION_NAME']` | `nil` | optional name for your php application | + +#### DOTNET Agent + +| Name | Default value | Description | +|:-------------------------------------------------------------------|:--------------|:------------------------------------------| +| `default['newrelic_install']['env']['NEW_RELIC_APPLICATION_NAME']` | `nil` | optional name for your dotnet application | ### Testing diff --git a/attributes/default.rb b/attributes/default.rb index f1df709..e624539 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -23,6 +23,7 @@ # infrastructure-agent-installer # logs-integration # php-agent-installer +# dotnet-agent-installer default['newrelic_install']['targets'] = [] ######## @@ -38,8 +39,8 @@ default['newrelic_install']['timeout_seconds'] = '600' ############# -# PHP AGENT # +# PHP, DOTNET # ############# -# optional name for your php application +# optional name for your application default['newrelic_install']['env']['NEW_RELIC_APPLICATION_NAME'] = '' diff --git a/resources/newrelic_install.rb b/resources/newrelic_install.rb index 3fe1147..0403a55 100644 --- a/resources/newrelic_install.rb +++ b/resources/newrelic_install.rb @@ -65,8 +65,8 @@ def check_license end def check_targets - allowedTargets = Set['infrastructure-agent-installer', 'logs-integration', 'php-agent-installer'] - allowedTargetsString = 'infrastructure-agent-installer, logs-integration, php-agent-installer' + allowedTargets = Set['infrastructure-agent-installer', 'logs-integration', 'php-agent-installer', 'dotnet-agent-installer'] + allowedTargetsString = 'infrastructure-agent-installer, logs-integration, php-agent-installer, dotnet-agent-installer' incomingTargets = new_resource.targets.to_set if incomingTargets.nil? || incomingTargets.empty? diff --git a/spec/unit/resources/newrelic_install_spec.rb b/spec/unit/resources/newrelic_install_spec.rb index 679f61e..da77e4f 100644 --- a/spec/unit/resources/newrelic_install_spec.rb +++ b/spec/unit/resources/newrelic_install_spec.rb @@ -94,7 +94,7 @@ expect(subject).to run_execute('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) end - it 'run bash newrlic install command with infra' do + it 'run bash newrelic install command with infra' do expect(subject).to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) end end @@ -105,15 +105,15 @@ default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' default_attributes['newrelic_install']['targets'] = %w(infrastructure-agent-installer logs-integration php-agent-installer) - it 'run bash newrlic install command with infra' do + it 'run bash newrelic install command with infra' do expect(subject).to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) end - it 'run bash newrlic install command with logs' do + it 'run bash newrelic install command with logs' do expect(subject).to run_execute('newrelic install').with(command: include('logs-integration')) end - it 'run bash newrlic install command with php' do + it 'run bash newrelic install command with php' do expect(subject).to run_execute('newrelic install').with(command: include('php-agent-installer')) end end @@ -128,15 +128,53 @@ expect(subject).to run_execute('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) end - it 'run bash newrlic install command without infra' do + it 'run bash newrelic install command without infra' do expect(subject).not_to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) end - it 'run bash newrlic install command with php' do + it 'run bash newrelic install command with php' do expect(subject).to run_execute('newrelic install').with(command: include('-n php-agent-installer')) end end + context 'when targets only contains infra, logs and dotnet' do + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = %w(infrastructure-agent-installer logs-integration dotnet-agent-installer) + + it 'run bash newrelic install command with infra' do + expect(subject).to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) + end + + it 'run bash newrelic install command with logs' do + expect(subject).to run_execute('newrelic install').with(command: include('logs-integration')) + end + + it 'run bash newrelic install command with dotnet' do + expect(subject).to run_execute('newrelic install').with(command: include('dotnet-agent-installer')) + end + end + + context 'when targets only contains dotnet' do + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = ['dotnet-agent-installer'] + + it 'should execute with target infra and skip core' do + expect(subject).to run_execute('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) + end + + it 'run bash newrelic install command without infra' do + expect(subject).not_to run_execute('newrelic install').with(command: include('infrastructure-agent-installer')) + end + + it 'run bash newrelic install command with dotnet' do + expect(subject).to run_execute('newrelic install').with(command: include('-n dotnet-agent-installer')) + end + end + context 'when execute on windows' do platform 'windows' default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' @@ -148,8 +186,48 @@ expect(subject).to run_powershell_script('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) end - it 'run powershell newrlic install command' do + it 'run powershell newrelic install command' do expect(subject).to run_powershell_script('newrelic install').with(code: include('infrastructure-agent-installer')) end end + + context 'when execute on windows and targets only contains infra, logs and dotnet' do + platform 'windows' + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = %w(infrastructure-agent-installer logs-integration dotnet-agent-installer) + + it 'run powershell newrelic install command' do + expect(subject).to run_powershell_script('newrelic install').with(code: include('infrastructure-agent-installer')) + end + + it 'run powershell newrelic install command with logs' do + expect(subject).to run_powershell_script('newrelic install').with(code: include('logs-integration')) + end + + it 'run powershell newrelic install command with dotnet' do + expect(subject).to run_powershell_script('newrelic install').with(code: include('dotnet-agent-installer')) + end + end + + context 'when execute on windows and targets only contains dotnet' do + platform 'windows' + default_attributes['newrelic_install']['NEW_RELIC_API_KEY'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_ACCOUNT_ID'] = 'xxx' + default_attributes['newrelic_install']['NEW_RELIC_REGION'] = 'xxx' + default_attributes['newrelic_install']['targets'] = ['dotnet-agent-installer'] + + it 'should execute with target infra and skip core' do + expect(subject).to run_powershell_script('newrelic install').with(env: have_key('NEW_RELIC_CLI_SKIP_CORE')) + end + + it 'run powershell newrelic install command without infra' do + expect(subject).not_to run_powershell_script('newrelic install').with(code: include('infrastructure-agent-installer')) + end + + it 'run powershell newrelic install command with dotnet' do + expect(subject).to run_powershell_script('newrelic install').with(code: include('-n dotnet-agent-installer')) + end + end end