Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pappachino committed Jan 13, 2024
1 parent fc699a1 commit 9d4c3e5
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions buildpack/telemetry/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
import logging
import os
import shutil
import socket
import subprocess
from collections import OrderedDict
Expand All @@ -36,7 +37,16 @@


def _get_agent_dir(root=ROOT_DIR):
return os.path.join(root, NAMESPACE, "lib")
# DD-CF-buildpack assumes the root DATADOG_DIR to be
# /home/vcap/app/.datadog
# So once we've downloaded and installed the binaries
# return the path with ".datadog/"
path_with_lib = os.path.join(root, NAMESPACE, "lib")
if os.path.exists(path_with_lib):
return os.path.join(root, NAMESPACE, "lib")
else:
dot_datadog_path = os.path.join(root, ".datadog")
return dot_datadog_path


def _get_user_checks_dir():
Expand Down Expand Up @@ -555,6 +565,24 @@ def _patch_run_datadog_script(script_dir):
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")
shutil.copytree(
datadog_lib_path,
datadog_install_path,
copy_function=shutil.move,
dirs_exist_ok=True,
)
# finally cleanup up the lib/ dir
# shutil.rmtree(datadog_lib_path)


def stage(buildpack_path, build_path, cache_path):
if not is_enabled():
return
Expand All @@ -568,7 +596,6 @@ def stage(buildpack_path, build_path, cache_path):
logging.debug("Patching run-datadog.sh...")
_patch_run_datadog_script(_get_agent_dir(build_path))


def run(model_version, runtime_version):
if not is_enabled():
return
Expand All @@ -580,6 +607,9 @@ def run(model_version, runtime_version):
)
return

logging.debug("Prep DATADOG_DIR ... %s", _get_agent_dir())
_prep_datadog_dir(_get_agent_dir())

logging.debug("Setting Datadog Agent script permissions if required...")
util.set_executable(f"{_get_agent_dir()}/*.sh")

Expand Down

0 comments on commit 9d4c3e5

Please sign in to comment.