Skip to content

Commit

Permalink
WIP: Move DATADOG_DIR to comply with dd-cf-buildpack
Browse files Browse the repository at this point in the history
DD buildpack assumes /home/vcap/app/.datadog as the DATADOG_DIR. So moving it
    there as default
  • Loading branch information
pappachino committed Jan 12, 2024
1 parent fc699a1 commit 426440e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion buildpack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 28 additions & 10 deletions buildpack/telemetry/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,16 +29,16 @@
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
LOGS_PORT = 9032


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():
Expand Down Expand Up @@ -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"]),
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down

0 comments on commit 426440e

Please sign in to comment.