Skip to content

Commit

Permalink
Super agent recipe final step check status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarocabanas committed Aug 20, 2024
1 parent 5a1eb4b commit c4aa6ce
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 23 deletions.
41 changes: 32 additions & 9 deletions recipes/newrelic/infrastructure/super-agent/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ install:
- task: update_otel_end_point
- task: migrate_newrelic_infra_config
- task: restart_super_agent
- task: assert_super_agent_started
- task: assert_super_agent_status_ok
- task: post_install

write_recipe_metadata:
Expand Down Expand Up @@ -574,16 +574,39 @@ install:
IS_INITCTL:
sh: command -v initctl | wc -l

assert_super_agent_started:
assert_super_agent_status_ok:
cmds:
- |
# Ensure super agent has enough time to start
sleep 10
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
exit 31
fi
MAX_RETRIES=150
TRIES=0
echo "Running agent status check attempt..."
# wait for status endpoint to be ready
while [ $TRIES -lt $MAX_RETRIES ]; do
((TRIES++))
statusCheckOutput=$(curl -s http://localhost:51200/status)
if [ -z "$statusCheckOutput" ]; then
# so jq doesn't fail if empty
statusCheckOutput="{}"
fi
STATUS=$(echo $statusCheckOutput | /usr/local/bin/newrelic utils jq '.super_agent.healthy')
if [ "$STATUS" == "true" ]; then
echo "Agent status check ok."
break
else
if [ "$TRIES" -eq "$MAX_RETRIES" ]; then
# Process-based validation attempt
IS_AGENT_INSTALLED=$(ps aux | grep newrelic-super-agent | grep -v grep | wc -l)
if [ $IS_AGENT_INSTALLED -gt 0 ] ; then
echo "detected newrelic-super-agent process running"
exit 0
fi
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
exit 31
fi
fi
sleep 2
done
post_install:
info: |2
Expand Down
37 changes: 30 additions & 7 deletions recipes/newrelic/infrastructure/super-agent/rhel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,36 @@ install:
assert_super_agent_started:
cmds:
- |
# Ensure super agent has enough time to start
sleep 10
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
exit 31
fi
MAX_RETRIES=150
TRIES=0
echo "Running agent status check attempt..."
# wait for status endpoint to be ready
while [ $TRIES -lt $MAX_RETRIES ]; do
((TRIES++))
statusCheckOutput=$(curl -s http://localhost:51200/status)
if [ -z "$statusCheckOutput" ]; then
# so jq doesn't fail if empty
statusCheckOutput="{}"
fi
STATUS=$(echo $statusCheckOutput | /usr/local/bin/newrelic utils jq '.super_agent.healthy')
if [ "$STATUS" == "true" ]; then
echo "Agent status check ok."
break
else
if [ "$TRIES" -eq "$MAX_RETRIES" ]; then
# Process-based validation attempt
IS_AGENT_INSTALLED=$(ps aux | grep newrelic-super-agent | grep -v grep | wc -l)
if [ $IS_AGENT_INSTALLED -gt 0 ] ; then
echo "detected newrelic-super-agent process running"
exit 0
fi
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
exit 31
fi
fi
sleep 2
done
post_install:
info: |2
Expand Down
37 changes: 30 additions & 7 deletions recipes/newrelic/infrastructure/super-agent/suse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,36 @@ install:
assert_super_agent_started:
cmds:
- |
# Ensure super agent has enough time to start
sleep 10
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
exit 31
fi
MAX_RETRIES=150
TRIES=0
echo "Running agent status check attempt..."
# wait for status endpoint to be ready
while [ $TRIES -lt $MAX_RETRIES ]; do
((TRIES++))
statusCheckOutput=$(curl -s http://localhost:51200/status)
if [ -z "$statusCheckOutput" ]; then
# so jq doesn't fail if empty
statusCheckOutput="{}"
fi
STATUS=$(echo $statusCheckOutput | /usr/local/bin/newrelic utils jq '.super_agent.healthy')
if [ "$STATUS" == "true" ]; then
echo "Agent status check ok."
break
else
if [ "$TRIES" -eq "$MAX_RETRIES" ]; then
# Process-based validation attempt
IS_AGENT_INSTALLED=$(ps aux | grep newrelic-super-agent | grep -v grep | wc -l)
if [ $IS_AGENT_INSTALLED -gt 0 ] ; then
echo "detected newrelic-super-agent process running"
exit 0
fi
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
exit 31
fi
fi
sleep 2
done
post_install:
info: |2
Expand Down

0 comments on commit c4aa6ce

Please sign in to comment.