Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

draft:Upgrade datadog agents to the latest versions #849

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
40 changes: 38 additions & 2 deletions buildpack/core/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import os
import stat
import re
import shutil
import sqlite3
Expand Down Expand Up @@ -68,6 +69,21 @@ def stage(buildpack_dir, build_path, cache_path):
os.path.join(buildpack_dir, "etc", "m2ee", "m2ee.yaml"),
os.path.join(build_path, ".local", "m2ee.yaml"),
)

scripts_path_source = os.path.join(buildpack_dir, "etc", "scripts")
scripts_path_dest = os.path.join(build_path, ".local", "scripts")
shutil.copytree(
scripts_path_source,
scripts_path_dest,
dirs_exist_ok=True
)

# Add +x permission for all sh scripts
for root, _, files in os.walk(scripts_path_dest):
for file in files:
file_path = os.path.join(root, file)
util.set_executable(file_path)

resolve_runtime_dependency(buildpack_dir, build_path, cache_path)


Expand Down Expand Up @@ -613,15 +629,35 @@ def _pre_process_m2ee_yaml():
"-i",
f"s|BUILD_PATH|{os.getcwd()}|g; "
f"s|RUNTIME_PORT|{util.get_runtime_port()}|; "
f"s|ADMIN_PORT|{util.get_admin_port()}|; "
f"s|PYTHONPID|{os.getpid()}|",
f"s|ADMIN_PORT|{util.get_admin_port()}|",
".local/m2ee.yaml",
]
)


def _pre_process_on_error_scripts():
logging.debug("Preprocessing on error scripts...")
subprocess.check_call(
[
"sed",
"-i",
f"s|PYTHONPID|{os.getpid()}|",
".local/scripts/on_error.sh",
]
)
subprocess.check_call(
[
"sed",
"-i",
f"s|PYTHONPID|{os.getpid()}|",
".local/scripts/on_out_of_memory_error.sh",
]
)


def setup(vcap_data):
_pre_process_m2ee_yaml()
_pre_process_on_error_scripts()
_activate_license()

client = m2ee_class(
Expand Down
29 changes: 20 additions & 9 deletions buildpack/telemetry/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from buildpack import util
from buildpack.core import runtime
from buildpack.infrastructure import database
from buildpack.telemetry.metrics import deny_all_apm_metrics
from lib.m2ee.version import MXVersion
from lib.m2ee.util import strtobool

Expand Down Expand Up @@ -250,10 +251,15 @@ def _set_up_dd_java_agent(m2ee, model_version, runtime_version, jmx_config_files
)

# Extend with JMX options
dd_jmxfetch_enabled = "true"
if deny_all_apm_metrics():
logging.error("####### deny all is set, disabling jmx") ## todo: remove this
dd_jmxfetch_enabled = "false" ## todo: update to false

util.upsert_javaopts(
m2ee,
[
"-Ddd.jmxfetch.enabled=true",
f"-Ddd.jmxfetch.enabled={dd_jmxfetch_enabled}",
f"-Ddd.jmxfetch.statsd.port={get_statsd_port()}",
],
)
Expand Down Expand Up @@ -493,18 +499,23 @@ def update_config(
},
)

# Set up runtime JMX configuration
with open(_get_jmx_conf_file(), "w") as file_handler:
file_handler.write(
yaml.safe_dump(
_get_runtime_jmx_config(
extra_jmx_instance_config=extra_jmx_instance_config,
if 1==1:
#if not deny_all_apm_metrics():
#logging.error("####### deny all is NOT set, enabling extra jmx") ## todo: remove this
# Set up runtime JMX configuration
with open(_get_jmx_conf_file(), "w") as file_handler:
file_handler.write(
yaml.safe_dump(
_get_runtime_jmx_config(
extra_jmx_instance_config=extra_jmx_instance_config,
)
)
)
)
jmx_config_files.append(_get_jmx_conf_file())
else:
logging.error("####### deny all is set, disabling extra jmx") ## todo: remove this else block

# Set up Datadog Java Trace Agent
jmx_config_files.append(_get_jmx_conf_file())
_set_up_dd_java_agent(
m2ee,
model_version,
Expand Down
4 changes: 2 additions & 2 deletions dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ dependencies:
buildpack:
alias: cf-datadog-sidecar
artifact: datadog/datadog-cloudfoundry-buildpack-{{ version }}.zip
version: 4.37.0
version: 4.42.0
trace-agent:
artifact: datadog/dd-java-agent-{{ version }}.jar
version: 1.27.0
version: 1.45.0
dynatrace:
agent:
artifact: "{{ url }}/e/{{ environment }}/api/v1/deployment/installer/agent/unix/paas/latest?include=java&bitness=64&Api-Token={{ token }}"
Expand Down
6 changes: 3 additions & 3 deletions etc/m2ee/m2ee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ m2ee:
javaopts:
[
"-Dfile.encoding=UTF-8",
"-Djava.io.tmpdir=BUILD_PATH/data/tmp",
"-XX:OnError=kill -s USR1 PYTHONPID",
"-XX:OnOutOfMemoryError=kill -s USR2 PYTHONPID",
"-Djava.io.tmpdir=/tmp",
"-XX:OnError=BUILD_PATH/.local/scripts/on_error.sh",
"-XX:OnOutOfMemoryError=BUILD_PATH/.local/scripts/on_out_of_memory_error.sh",
]

jetty:
Expand Down
1 change: 1 addition & 0 deletions etc/scripts/on_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kill -s USR1 PYTHONPID
1 change: 1 addition & 0 deletions etc/scripts/on_out_of_memory_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kill -s USR2 PYTHONPID
Loading