Skip to content

Commit

Permalink
feat: super-agent idempotent updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchezgavier committed Aug 6, 2024
1 parent 5a1eb4b commit 9c8c8c5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
29 changes: 28 additions & 1 deletion recipes/newrelic/infrastructure/super-agent/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ install:
default:
cmds:
- task: write_recipe_metadata
- task: detect_previous_install
- task: assert_pre_req
- task: cleanup
- task: setup_infra_license
Expand All @@ -88,13 +89,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 +193,16 @@ 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 +246,8 @@ 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 +363,7 @@ 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 +373,14 @@ 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 +389,7 @@ 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 +403,7 @@ 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 +429,7 @@ 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 +438,7 @@ 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 +470,7 @@ 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 +564,7 @@ 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 Down Expand Up @@ -585,6 +607,11 @@ install:
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
27 changes: 27 additions & 0 deletions recipes/newrelic/infrastructure/super-agent/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ install:
default:
cmds:
- task: write_recipe_metadata
- task: detect_previous_install
- task: assert_pre_req
- task: cleanup
- task: setup_infra_license
Expand All @@ -108,13 +109,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 +204,16 @@ 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 +304,7 @@ 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 +313,14 @@ 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 +329,7 @@ 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 +343,7 @@ 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 +369,7 @@ 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 +378,7 @@ 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 +410,7 @@ 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 +504,7 @@ 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 Down Expand Up @@ -525,6 +547,11 @@ install:
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 9c8c8c5

Please sign in to comment.