Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(super-agent): Included Super agent, super agent logs target #17

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 14 additions & 7 deletions resources/newrelic_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ 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 = Set.new(%w(
infrastructure-agent-installer
logs-integration
php-agent-installer
dotnet-agent-installer
super-agent
logs-integration-super-agent
))
allowed_targets_string = allowed_targets.join(', ')
incoming_targets = new_resource.targets.to_set

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

raise ArgumentError, "Targets must only contains valid value(#{allowedTargetsString})" unless incomingTargets.subset?(allowedTargets)
raise ArgumentError, "Targets must only contains valid value(#{allowed_targets_string})" unless incoming_targets.subset?(allowed_targets)

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

Expand Down
60 changes: 60 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,64 @@
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 super-agent' do
expect(subject).to run_execute('newrelic install').with(command: include('super-agent'))
end

it 'run powershell newrelic install command without super-agent' do
expect(subject).not_to run_powershell_script('newrelic install').with(code: include('super-agent'))
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'] = %w(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 super-agent' do
expect(subject).to run_execute('newrelic install').with(command: include('super-agent'))
end

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
end
context 'when targets only contains super agent 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'] = ['logs-integration-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 logs-integration-super-agent' do
expect(subject).to run_execute('newrelic install').with(command: include('logs-integration-super-agent'))
end

it 'run powershell newrelic install command without logs-integration-super-agent' do
expect(subject).not_to run_powershell_script('newrelic install').with(code: include('logs-integration-super-agent'))
end
end
end
Loading