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

Install New Relic infrastructure agent #900

Merged
merged 2 commits into from
Oct 10, 2023
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
18 changes: 13 additions & 5 deletions inventory/host_vars/_example.com/secrets.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ smtp_password:
#geocoder_service: mapbox
#geocoder_timeout: 7

# New relic settings
# see: https://one.eu.newrelic.com/admin-portal/, Administration > API keys to get the license key
# new_relic_agent_enabled: true
# new_relic_app_name: "Open Food Network"
# new_relic_license_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
## New Relic settings
#
# See: https://one.eu.newrelic.com/admin-portal/ > API keys
#
# Infrastructure agent:
#new_relic_api_key: "NRAK-XXXXXXXXXXXXXXXXXXXXXXXXXXX"
#new_relic_account_id: "0000000"
#new_relic_region: "EU"
#
# Rails APM:
#new_relic_agent_enabled: true
#new_relic_app_name: "Open Food Network"
#new_relic_license_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
5 changes: 5 additions & 0 deletions playbooks/provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
become: yes
tags: logrotate

- role: newrelic
become: yes
when: new_relic_api_key is defined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This role also depends on new_relic_account_id and new_relic_region, so I was wondering if we should check for those here too.
But then if you forgot to set any of those, it would just silently fail.
👍 So I think this way is best: if you intended to switch it on, but left out a detail, then it would be better to get an error message which shows what's missing.

tags: newrelic

tasks:
- name: Fix Ruby # noqa 301
command:
Expand Down
4 changes: 4 additions & 0 deletions roles/newrelic/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: restart newrelic_infra
service:
name: "newrelic-infra.service"
state: restarted
29 changes: 29 additions & 0 deletions roles/newrelic/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---

- name: Download installer
ansible.builtin.get_url:
url: "https://download.newrelic.com/install/newrelic-cli/scripts/install.sh"
dest: "/tmp/new-relic-install.sh"
mode: "777"

- name: Install New Relic command
ansible.builtin.command: "/tmp/new-relic-install.sh"
args:
creates: /usr/local/bin/newrelic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see some validation of the result.
I can think of a couple of other ways to validate:

  1. check for a non-error return code, or
  2. grep the output for the success message.

But I don't think it's worth spending more effort on figuring one of those out.


- name: Install New Relic agent
command: /usr/local/bin/newrelic install -y
environment:
NEW_RELIC_API_KEY: "{{ new_relic_api_key }}"
NEW_RELIC_ACCOUNT_ID: "{{ new_relic_account_id }}"
NEW_RELIC_REGION: "{{ new_relic_region }}"
args:
creates: /usr/bin/newrelic-infra

- name: Use our standard names in dashboard
lineinfile:
name: "/etc/newrelic-infra.yml"
line: "display_name: {{ host_id }}"
regex: "^display_name:"
state: present
notify: restart newrelic_infra
Comment on lines +23 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!