Skip to content

Commit

Permalink
feat(super-agent): Included Super agent, super agent logs target
Browse files Browse the repository at this point in the history
  • Loading branch information
NSSPKrishna committed May 20, 2024
1 parent e262bd5 commit 53e1e10
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# logs-integration
# php-agent-installer
# dotnet-agent-installer
# super-agent
# logs-integration-super-agent
default['newrelic_install']['targets'] = []

########
Expand Down
23 changes: 14 additions & 9 deletions resources/newrelic_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,24 @@ def check_license
end

def check_targets
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
allowed_targets = {
'infrastructure-agent-installer' => true,
'logs-integration' => true,
'php-agent-installer' => true,
'dotnet-agent-installer' => true,
'super-agent' => true,
'logs-integration-super-agent' => true
}

if incomingTargets.nil? || incomingTargets.empty?
raise ArgumentError, 'Targets must contain at least one installation target'
end
incoming_targets = new_resource.targets.to_set

raise ArgumentError, "Targets must only contains valid value(#{allowedTargetsString})" unless incomingTargets.subset?(allowedTargets)
raise ArgumentError, 'Targets must contain at least one installation target' if incoming_targets.empty?

if incomingTargets.include?('logs-integration')
raise ArgumentError, 'Targets must include infrastructure-agent-installer if log is included' unless incomingTargets.include?('infrastructure-agent-installer')
unless incoming_targets.subset?(allowed_targets.keys)
raise ArgumentError, "Targets must only contain valid values (#{allowed_targets.keys.join(', ')})"
end

raise ArgumentError, 'Targets must include infrastructure-agent-installer if log is included' unless incoming_targets.include?('logs-integration') && !incoming_targets.include?('infrastructure-agent-installer')
end

def stringify_targets(targets)
Expand Down
42 changes: 42 additions & 0 deletions spec/unit/resources/newrelic_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,46 @@
expect(subject).to run_powershell_script('newrelic install').with(code: include('-n dotnet-agent-installer'))
end
end

context 'when targets only contains super agent' 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'] = ['super-agent']

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 with infra' do
expect(subject).to run_execute('newrelic install').with(command: include('super-agent'))
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
end

context 'when targets contains super agent infra agent and logs' 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'] = ['super-agent','infrastructure-agent-installer', 'logs-integration']

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 with infra' do
expect(subject).to run_execute('newrelic install').with(command: include('super-agent'))
end

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
end
end

0 comments on commit 53e1e10

Please sign in to comment.