Skip to content

Commit

Permalink
feat: super-agent idempotent updates (NR-277039)
Browse files Browse the repository at this point in the history
feat: super-agent idempotent updates (NR-277039)
  • Loading branch information
Avinash-Sanpala authored Aug 21, 2024
2 parents a8289a1 + 3dd562e commit 327be90
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 230 deletions.
57 changes: 50 additions & 7 deletions recipes/newrelic/infrastructure/super-agent/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ preInstall:
install:
version: "3"
silent: true

vars:
IS_SYSTEMCTL:
sh: command -v systemctl | wc -l
IS_INITCTL:
sh: command -v initctl | wc -l
tasks:
default:
cmds:
- task: write_recipe_metadata
- task: detect_previous_install
- task: assert_pre_req
- task: cleanup
- task: setup_infra_license
Expand All @@ -88,13 +93,22 @@ install:
- task: migrate_newrelic_infra_config
- task: restart_super_agent
- task: assert_super_agent_started
- task: signal_recipe_applied
- task: post_install

write_recipe_metadata:
cmds:
- |
echo '{"Metadata":{"CapturedCliOutput":"true"}}' | tee {{.NR_CLI_OUTPUT}} > /dev/null
detect_previous_install:
cmds:
- |
if [ -f /etc/newrelic-super-agent/.nr-cli ] ; then
echo "A previous execution of this installation was detected. Some installation tasks will be skipped."
echo "If you would like to run all the tasks, please remove the /etc/newrelic-super-agent/.nr-cli file and re-run the installation."
fi
assert_pre_req:
cmds:
- |
Expand Down Expand Up @@ -183,13 +197,18 @@ install:
sh: cat /etc/os-release | grep "VERSION=\"[0-9] " | awk -F " " '{print $2}' | sed 's/[()"]//g'

cleanup:
# skipping this task if .nr-cli exists
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" != "false" ] ; then
rm -rf /var/db/newrelic-infra/data 2>/dev/null
fi
setup_infra_license:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" != "false" ] ; then
Expand Down Expand Up @@ -233,8 +252,9 @@ install:
echo 'license_key: {{`{{NEW_RELIC_LICENSE_KEY}}`}}' >> /etc/newrelic-infra.yml
echo '{{.NRIA_CUSTOM_ATTRIBUTES}}' >> /etc/newrelic-infra.yml
fi
setup_infra_proxy:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" != "false" ] && [ ! -z "$HTTPS_PROXY" ]; then
Expand Down Expand Up @@ -350,6 +370,8 @@ install:

# If configured to do so, migrate the newrelic-infra configuration for usage with the super agent
migrate_newrelic_infra_config:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ -f /etc/newrelic-infra-do-migrate ]; then
Expand All @@ -359,12 +381,16 @@ install:
# Add NR Ingest Key as ENV Var for the Super Agent Systemd service (used by Infra Agent and Otel)
update_otel_license_key:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
sed -i "/^NEW_RELIC_LICENSE_KEY/d" /etc/newrelic-super-agent/newrelic-super-agent.conf
echo 'NEW_RELIC_LICENSE_KEY="{{.NEW_RELIC_LICENSE_KEY}}"' >> /etc/newrelic-super-agent/newrelic-super-agent.conf
update_otel_mem_limit:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_NRDOT}}" != "false" ]; then
Expand All @@ -373,6 +399,8 @@ install:
# Add OTLP Endpoint as ENV Var for the Super Agent Systemd service
update_otel_end_point:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_NRDOT}}" != "false" ]; then
Expand All @@ -386,6 +414,8 @@ install:
fi
config_supervisors:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" = "false" ] && [ "{{.NR_CLI_NRDOT}}" = "false" ]; then
Expand All @@ -411,6 +441,8 @@ install:
fi
config_fleet_id:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ ! -z "{{.NR_CLI_FLEET_ID}}" ] ; then
Expand All @@ -419,6 +451,8 @@ install:
fi
config_opamp:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ]; then
Expand Down Expand Up @@ -450,6 +484,8 @@ install:
fi
config_super_agent_auth:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" != "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
Expand Down Expand Up @@ -543,6 +579,8 @@ install:
fi
config_host_monitoring:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_HOST_MONITORING_SOURCE}}" = "otel" ]; then
Expand All @@ -568,11 +606,6 @@ install:
/etc/init.d/newrelic-super-agent restart
fi
fi
vars:
IS_SYSTEMCTL:
sh: command -v systemctl | wc -l
IS_INITCTL:
sh: command -v initctl | wc -l
assert_super_agent_started:
cmds:
Expand All @@ -582,9 +615,19 @@ install:
IS_AGENT_INSTALLED=$(sudo ps aux | grep newrelic-super-agent | grep -v grep | wc -l)
if [ $IS_AGENT_INSTALLED -eq 0 ] ; then
echo "The newrelic super agent has not started after installing. Please try again later, or see our documentation for installing manually https://docs.newrelic.com/docs/using-new-relic/cross-product-functions/install-configure/install-new-relic" >&2
if [ {{.IS_SYSTEMCTL}} -gt 0 ]; then
journalctl -u newrelic-super-agent --no-pager
fi
exit 31
fi
signal_recipe_applied:
cmds:
- |
touch /etc/newrelic-super-agent/.nr-cli
post_install:
info: |2
⚙️ The New Relic Super Agent configuration file can be found in /etc/newrelic-super-agent/config.yaml
52 changes: 47 additions & 5 deletions recipes/newrelic/infrastructure/super-agent/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ install:
sh: if [ {{.AMAZON_LINUX_VERSION}} = "2" ] || [ {{.AMAZON_LINUX_VERSION}} = "2023" ]; then echo "amazonlinux"; else echo "el"; fi
ARCH:
sh: uname -m
IS_SYSTEMCTL:
sh: command -v systemctl | wc -l
IS_INITCTL:
sh: command -v initctl | wc -l

tasks:
default:
cmds:
- task: write_recipe_metadata
- task: detect_previous_install
- task: assert_pre_req
- task: cleanup
- task: setup_infra_license
Expand All @@ -108,13 +113,22 @@ install:
- task: migrate_newrelic_infra_config
- task: restart_super_agent
- task: assert_super_agent_started
- task: signal_recipe_applied
- task: post_install

write_recipe_metadata:
cmds:
- |
echo '{"Metadata":{"CapturedCliOutput":"true"}}' | tee {{.NR_CLI_OUTPUT}} > /dev/null
detect_previous_install:
cmds:
- |
if [ -f /etc/newrelic-super-agent/.nr-cli ] ; then
echo "A previous execution of this installation was detected. Some installation tasks will be skipped."
echo "If you would like to run all the tasks, please remove the /etc/newrelic-super-agent/.nr-cli file and re-run the installation."
fi
assert_pre_req:
cmds:
- |
Expand Down Expand Up @@ -194,13 +208,18 @@ install:
rpm -E %{rhel}
cleanup:
# skipping this task if .nr-cli exists
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" != "false" ] ; then
rm -rf /var/db/newrelic-infra/data 2>/dev/null
fi
setup_infra_license:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" != "false" ] ; then
Expand Down Expand Up @@ -291,6 +310,8 @@ install:

# If configured to do so, migrate the newrelic-infra configuration for usage with the super agent
migrate_newrelic_infra_config:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ -f /etc/newrelic-infra-do-migrate ]; then
Expand All @@ -299,12 +320,16 @@ install:
fi
update_otel_license_key:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
sed -i "/^NEW_RELIC_LICENSE_KEY/d" /etc/newrelic-super-agent/newrelic-super-agent.conf
echo 'NEW_RELIC_LICENSE_KEY="{{.NEW_RELIC_LICENSE_KEY}}"' >> /etc/newrelic-super-agent/newrelic-super-agent.conf
update_otel_mem_limit:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_NRDOT}}" != "false" ]; then
Expand All @@ -313,6 +338,8 @@ install:
# Add OTLP Endpoint as ENV Var for the Super Agent Systemd service
update_otel_end_point:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_NRDOT}}" != "false" ]; then
Expand All @@ -326,6 +353,8 @@ install:
fi
config_supervisors:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NR_CLI_INFRA_AGENT}}" = "false" ] && [ "{{.NR_CLI_NRDOT}}" = "false" ]; then
Expand All @@ -351,6 +380,8 @@ install:
fi
config_fleet_id:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ ! -z "{{.NR_CLI_FLEET_ID}}" ] ; then
Expand All @@ -359,6 +390,8 @@ install:
fi
config_opamp:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" = "false" ]; then
Expand Down Expand Up @@ -390,6 +423,8 @@ install:
fi
config_super_agent_auth:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_FLEET_ENABLED}}" != "false" ] && [ "{{ .NEW_RELIC_ORGANIZATION }}" != "" ]; then
Expand Down Expand Up @@ -483,6 +518,8 @@ install:
fi
config_host_monitoring:
status:
- test -f /etc/newrelic-super-agent/.nr-cli
cmds:
- |
if [ "{{.NEW_RELIC_SUPER_AGENT_HOST_MONITORING_SOURCE}}" = "otel" ]; then
Expand All @@ -508,11 +545,6 @@ install:
/etc/init.d/newrelic-super-agent restart
fi
fi
vars:
IS_SYSTEMCTL:
sh: command -v systemctl | wc -l
IS_INITCTL:
sh: command -v initctl | wc -l
assert_super_agent_started:
cmds:
Expand All @@ -522,9 +554,19 @@ install:
IS_AGENT_INSTALLED=$(sudo ps aux | grep newrelic-super-agent | grep -v grep | wc -l)
if [ $IS_AGENT_INSTALLED -eq 0 ] ; then
echo "The newrelic super agent has not started after installing. Please try again later, or see our documentation for installing manually https://docs.newrelic.com/docs/using-new-relic/cross-product-functions/install-configure/install-new-relic" >&2
if [ {{.IS_SYSTEMCTL}} -gt 0 ]; then
journalctl -u newrelic-super-agent --no-pager
fi
exit 31
fi
signal_recipe_applied:
cmds:
- |
touch /etc/newrelic-super-agent/.nr-cli
post_install:
info: |2
⚙️ The New Relic Super Agent configuration file can be found in /etc/newrelic-super-agent/config.yaml
Loading

0 comments on commit 327be90

Please sign in to comment.