diff --git a/buildpack/stage.py b/buildpack/stage.py index e29b0d5fa..94b603a57 100755 --- a/buildpack/stage.py +++ b/buildpack/stage.py @@ -204,7 +204,7 @@ def cleanup_dependency_cache(cached_dir, dependency_list): fluentbit.stage(BUILDPACK_DIR, DOT_LOCAL_LOCATION, CACHE_DIR) mx_java_agent.stage(BUILDPACK_DIR, DOT_LOCAL_LOCATION, CACHE_DIR, runtime_version) telegraf.stage(BUILDPACK_DIR, DOT_LOCAL_LOCATION, CACHE_DIR, runtime_version) - datadog.stage(BUILDPACK_DIR, DOT_LOCAL_LOCATION, CACHE_DIR) + datadog.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) metering.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) database.stage(BUILDPACK_DIR, BUILD_DIR) runtime.stage(BUILDPACK_DIR, BUILD_DIR, CACHE_DIR) diff --git a/buildpack/telemetry/datadog.py b/buildpack/telemetry/datadog.py index 2ee3c258b..90364f2fc 100644 --- a/buildpack/telemetry/datadog.py +++ b/buildpack/telemetry/datadog.py @@ -9,9 +9,11 @@ # - Telegraf: PostgreSQL metrics, replicating the Datadog metric names # - Telegraf: Database diskstorage size metric +import glob import json import logging import os +import shutil import socket import subprocess from collections import OrderedDict @@ -27,8 +29,7 @@ NAMESPACE = "datadog" TRACE_AGENT_DEPENDENCY = f"{NAMESPACE}.trace-agent" -ROOT_DIR = os.path.abspath(".local") -SIDECAR_ROOT_DIR = os.path.join(ROOT_DIR, NAMESPACE) +ROOT_DIR = os.path.abspath(".datadog") AGENT_USER_CHECKS_DIR = os.path.abspath("/home/vcap/app/datadog_integrations") STATSD_PORT = 8125 @@ -36,7 +37,8 @@ def _get_agent_dir(root=ROOT_DIR): - return os.path.join(root, NAMESPACE, "lib") + # This would be something like /home/vcap/app/.datadog + return os.path.join(root) def _get_user_checks_dir(): @@ -194,7 +196,7 @@ def get_statsd_port(): def _set_up_dd_java_agent(m2ee, model_version, runtime_version, jmx_config_files): jar = os.path.join( - SIDECAR_ROOT_DIR, + ROOT_DIR, os.path.basename(util.get_dependency(TRACE_AGENT_DEPENDENCY)["artifact"]), ) @@ -517,13 +519,13 @@ def _download(buildpack_dir, build_path, cache_dir): util.resolve_dependency( f"{NAMESPACE}.buildpack", - os.path.join(build_path, NAMESPACE), + os.path.join(build_path, ".datadog"), buildpack_dir=buildpack_dir, cache_dir=cache_dir, ) util.resolve_dependency( TRACE_AGENT_DEPENDENCY, - os.path.join(build_path, NAMESPACE), + os.path.join(build_path, ".datadog"), buildpack_dir=buildpack_dir, cache_dir=cache_dir, unpack=False, @@ -554,6 +556,20 @@ def _patch_run_datadog_script(script_dir): file_handler.write(line) file_handler.truncate() +def _prep_datadog_dir(datadog_install_path): + # Tries to replicate what the datadog-cloudfoundry-buildpack + # supply script does before running the datadog startup script. + # The DD buildpack assumes /home/vcap/app/.datadog to be the default + # directory for all configs and binaries though it provides DATADOG_DIR + # as an environment variable. So here we try to move all files under lib/ + # to /home/vcap/app/.datadog/ + datadog_lib_path = os.path.join(datadog_install_path, "lib") + files = glob.glob(datadog_lib_path) + for f in files: + shutil.move(f, datadog_install_path) + # finally cleanup up the lib/ dir + shutil.rmtree(datadog_lib_path) + def stage(buildpack_path, build_path, cache_path): if not is_enabled(): @@ -562,12 +578,14 @@ def stage(buildpack_path, build_path, cache_path): logging.debug("Staging Datadog...") _download(buildpack_path, build_path, cache_path) - logging.debug("Setting Datadog Agent script permissions if required...") - util.set_executable(f"{_get_agent_dir(build_path)}/*.sh") + logging.debug("Prepping the DATADOG_DIR ...") + _prep_datadog_dir(_get_agent_dir()) - logging.debug("Patching run-datadog.sh...") - _patch_run_datadog_script(_get_agent_dir(build_path)) + #logging.debug("Setting Datadog Agent script permissions if required...") + #util.set_executable(f"{_get_agent_dir(build_path)}/*.sh") + logging.debug("Patching run-datadog.sh...") + _patch_run_datadog_script(_get_agent_dir()) def run(model_version, runtime_version): if not is_enabled():