From 8375096855d13543d7bf54462f061da512ddb94b Mon Sep 17 00:00:00 2001 From: Noueman Khalikine Date: Wed, 8 Feb 2023 15:27:28 +0100 Subject: [PATCH 1/5] wait for TCP port 8126 of the trace agent --- bin/supply | 2 ++ lib/run-datadog.sh | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/bin/supply b/bin/supply index 5bc8211..7f2c353 100755 --- a/bin/supply +++ b/bin/supply @@ -38,6 +38,7 @@ cp "${ROOT_DIR}/lib/scripts/nc.py" "${DATADOG_DIR}/scripts/nc.py" cp "${ROOT_DIR}/lib/scripts/utils.sh" "${DATADOG_DIR}/scripts/utils.sh" cp "${ROOT_DIR}/lib/scripts/check_datadog.sh" "${DATADOG_DIR}/scripts/check_datadog.sh" + cp -r "${ROOT_DIR}/lib/test-endpoint.sh" "${BUILD_DIR}/.profile.d/00-test-endpoint.sh" # Make sure this is sourced first cp "${ROOT_DIR}/lib/run-datadog.sh" "${BUILD_DIR}/.profile.d/01-run-datadog.sh" cp "${ROOT_DIR}/lib/redirect-logs.sh" "${BUILD_DIR}/.profile.d/02-redirect-logs.sh" @@ -52,6 +53,7 @@ fi chmod +x "${DATADOG_DIR}/scripts/utils.sh" chmod +x "${DATADOG_DIR}/scripts/check_datadog.sh" + chmod +x "${DATADOG_DIR}/trace-agent" chmod +x "${BUILD_DIR}/.profile.d/00-test-endpoint.sh" chmod +x "${BUILD_DIR}/.profile.d/02-redirect-logs.sh" diff --git a/lib/run-datadog.sh b/lib/run-datadog.sh index b6e3a9b..c7e8f18 100644 --- a/lib/run-datadog.sh +++ b/lib/run-datadog.sh @@ -235,3 +235,8 @@ main() { fi } main "$@" + +while ! nc -z localhost 8126; do + echo "Waiting for the trace agent to start on 8126..." + sleep 1 +done From c2404e2ad8052c59592449aa90a99287d5ba3041 Mon Sep 17 00:00:00 2001 From: Noueman Khalikine Date: Wed, 8 Feb 2023 16:35:25 +0100 Subject: [PATCH 2/5] add WAIT_DD_TRACE_AGENT env var to control the new behavior --- lib/run-datadog.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/run-datadog.sh b/lib/run-datadog.sh index c7e8f18..e102555 100644 --- a/lib/run-datadog.sh +++ b/lib/run-datadog.sh @@ -236,7 +236,9 @@ main() { } main "$@" -while ! nc -z localhost 8126; do - echo "Waiting for the trace agent to start on 8126..." - sleep 1 -done +if [ "${WAIT_DD_TRACE_AGENT}" = "true" ]; then + while ! nc -z localhost 8126; do + echo "Waiting for the trace agent to start on 8126..." + sleep 1 + done +fi \ No newline at end of file From 05f5ec11e88b5c076dd592f187767a94f2331f4d Mon Sep 17 00:00:00 2001 From: Noueman Khalikine Date: Mon, 13 Feb 2023 14:51:36 +0100 Subject: [PATCH 3/5] remove extra lines --- bin/supply | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/supply b/bin/supply index 7f2c353..5bc8211 100755 --- a/bin/supply +++ b/bin/supply @@ -38,7 +38,6 @@ cp "${ROOT_DIR}/lib/scripts/nc.py" "${DATADOG_DIR}/scripts/nc.py" cp "${ROOT_DIR}/lib/scripts/utils.sh" "${DATADOG_DIR}/scripts/utils.sh" cp "${ROOT_DIR}/lib/scripts/check_datadog.sh" "${DATADOG_DIR}/scripts/check_datadog.sh" - cp -r "${ROOT_DIR}/lib/test-endpoint.sh" "${BUILD_DIR}/.profile.d/00-test-endpoint.sh" # Make sure this is sourced first cp "${ROOT_DIR}/lib/run-datadog.sh" "${BUILD_DIR}/.profile.d/01-run-datadog.sh" cp "${ROOT_DIR}/lib/redirect-logs.sh" "${BUILD_DIR}/.profile.d/02-redirect-logs.sh" @@ -53,7 +52,6 @@ fi chmod +x "${DATADOG_DIR}/scripts/utils.sh" chmod +x "${DATADOG_DIR}/scripts/check_datadog.sh" - chmod +x "${DATADOG_DIR}/trace-agent" chmod +x "${BUILD_DIR}/.profile.d/00-test-endpoint.sh" chmod +x "${BUILD_DIR}/.profile.d/02-redirect-logs.sh" From c2b2629a91ef0642bf60955b02b446c7a052abe2 Mon Sep 17 00:00:00 2001 From: Noueman Khalikine Date: Mon, 13 Feb 2023 15:00:32 +0100 Subject: [PATCH 4/5] add 2 min timeout --- lib/run-datadog.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/run-datadog.sh b/lib/run-datadog.sh index e102555..0ddddf4 100644 --- a/lib/run-datadog.sh +++ b/lib/run-datadog.sh @@ -236,9 +236,16 @@ main() { } main "$@" +timeout=120 if [ "${WAIT_DD_TRACE_AGENT}" = "true" ]; then - while ! nc -z localhost 8126; do + while ! nc -z localhost 8126 && [ $timeout -ge 0 ]; do echo "Waiting for the trace agent to start on 8126..." sleep 1 + timeout=$((timeout - 1)) done -fi \ No newline at end of file + if [ $timeout -ge 0 ]; then + echo "Trace agent is listening for traces" + else + echo "Timed out waiting for the trace agent" + fi +fi From bd6a0476d0e3a6a39239c5ae4ee4c14859e419bd Mon Sep 17 00:00:00 2001 From: NouemanKHAL Date: Mon, 13 Feb 2023 17:45:21 +0100 Subject: [PATCH 5/5] apply suggestion --- lib/run-datadog.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/run-datadog.sh b/lib/run-datadog.sh index 0ddddf4..2407914 100644 --- a/lib/run-datadog.sh +++ b/lib/run-datadog.sh @@ -233,19 +233,22 @@ main() { exec 9>&- fi fi + + # wait for the trace agent startup + if [ "${WAIT_DD_TRACE_AGENT}" = "true" ]; then + timeout=120 + while ! nc -z localhost 8126 && [ $timeout -ge 0 ]; do + echo "Waiting for the trace agent to start on 8126..." + sleep 1 + timeout=$((timeout - 1)) + done + if [ $timeout -ge 0 ]; then + echo "Trace agent is listening for traces" + else + echo "Timed out waiting for the trace agent" + fi + fi } main "$@" -timeout=120 -if [ "${WAIT_DD_TRACE_AGENT}" = "true" ]; then - while ! nc -z localhost 8126 && [ $timeout -ge 0 ]; do - echo "Waiting for the trace agent to start on 8126..." - sleep 1 - timeout=$((timeout - 1)) - done - if [ $timeout -ge 0 ]; then - echo "Trace agent is listening for traces" - else - echo "Timed out waiting for the trace agent" - fi -fi +