From 668ddb39f85c95c4b8c85976f917072443b26c64 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Tue, 28 Jan 2025 13:12:09 +0100 Subject: [PATCH 01/10] Upgrade datadog agents to the latest versions --- dependencies.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies.yml b/dependencies.yml index eba74943..c586a783 100644 --- a/dependencies.yml +++ b/dependencies.yml @@ -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.2 dynatrace: agent: artifact: "{{ url }}/e/{{ environment }}/api/v1/deployment/installer/agent/unix/paas/latest?include=java&bitness=64&Api-Token={{ token }}" From b8ec04761f4e76b8dd9d4d647a709c8213000fed Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Thu, 30 Jan 2025 14:58:35 +0100 Subject: [PATCH 02/10] Downgrade dd java agent for testing --- dependencies.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.yml b/dependencies.yml index c586a783..b5f987bf 100644 --- a/dependencies.yml +++ b/dependencies.yml @@ -24,7 +24,7 @@ dependencies: version: 4.42.0 trace-agent: artifact: datadog/dd-java-agent-{{ version }}.jar - version: 1.45.2 + 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 }}" From 89f5d4cae9b0a58647236121848f313dcc906e65 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 10:24:59 +0100 Subject: [PATCH 03/10] Temporary commit for debugging --- etc/m2ee/m2ee.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index 26687b2e..ed9a349a 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -23,8 +23,8 @@ m2ee: [ "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=BUILD_PATH/data/tmp", - "-XX:OnError=kill -s USR1 PYTHONPID", - "-XX:OnOutOfMemoryError=kill -s USR2 PYTHONPID", + "-XX:OnError=on_error_script.sh", + "-XX:OnOutOfMemoryError=on_oom.sh", ] jetty: From 0142a2499479def4e614c90face7cf0a29b763b2 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 14:21:19 +0100 Subject: [PATCH 04/10] Temporarily use a writable directory for java io tmp --- etc/m2ee/m2ee.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index ed9a349a..501f2861 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -22,7 +22,7 @@ m2ee: javaopts: [ "-Dfile.encoding=UTF-8", - "-Djava.io.tmpdir=BUILD_PATH/data/tmp", + "-Djava.io.tmpdir=/tmp", "-XX:OnError=on_error_script.sh", "-XX:OnOutOfMemoryError=on_oom.sh", ] From 17d1b6e532a1c7741b5892c6950884d5cb3e5ca3 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 14:49:13 +0100 Subject: [PATCH 05/10] Temporarily use tmp folder for debugging --- etc/m2ee/m2ee.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index 501f2861..953c3a73 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -23,8 +23,8 @@ m2ee: [ "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=/tmp", - "-XX:OnError=on_error_script.sh", - "-XX:OnOutOfMemoryError=on_oom.sh", + "-XX:OnError=/tmp/on_error_script.sh", + "-XX:OnOutOfMemoryError=/tmp/on_oom.sh", ] jetty: From 512ba1f85569de9049bac78bf873f3ffbab714eb Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 15:23:08 +0100 Subject: [PATCH 06/10] Temporarily use home/vcap/app folder for debugging --- etc/m2ee/m2ee.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index 953c3a73..5f00c57c 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -23,8 +23,8 @@ m2ee: [ "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=/tmp", - "-XX:OnError=/tmp/on_error_script.sh", - "-XX:OnOutOfMemoryError=/tmp/on_oom.sh", + "-XX:OnError=/home/vcap/app/on_error_script.sh", + "-XX:OnOutOfMemoryError=/home/vcap/app/on_oom.sh", ] jetty: From 5fbbc51a0735041821ec6a4e9737aac4fd6f6a7e Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 15:44:34 +0100 Subject: [PATCH 07/10] Use scripts instead of direct commands in java opts --- buildpack/core/runtime.py | 9 ++++++++- etc/m2ee/m2ee.yaml | 5 +++-- etc/scripts/on_error.sh | 2 ++ etc/scripts/on_out_of_memory_error.sh | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100755 etc/scripts/on_error.sh create mode 100755 etc/scripts/on_out_of_memory_error.sh diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index a9e79c6a..9e6c332b 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -68,6 +68,13 @@ 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"), ) + shutil.copytree( + os.path.join(buildpack_dir, "etc", "scripts"), + os.path.join(build_path, ".local", "scripts"), + dirs_exist_ok=True, + copy_function=shutil.copy2 + ) + resolve_runtime_dependency(buildpack_dir, build_path, cache_path) @@ -614,7 +621,7 @@ def _pre_process_m2ee_yaml(): 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|PYTHONPID|{os.getpid()}|", # TODO Replace in new scripts ".local/m2ee.yaml", ] ) diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index 5f00c57c..d46378a2 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -23,9 +23,10 @@ m2ee: [ "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=/tmp", - "-XX:OnError=/home/vcap/app/on_error_script.sh", - "-XX:OnOutOfMemoryError=/home/vcap/app/on_oom.sh", + "-XX:OnError=/home/vcap/app/.local/scripts/on_error.sh", + "-XX:OnOutOfMemoryError=/home/vcap/app/.local/scripts/on_out_of_memory_error.sh", ] + # TODO Replace with BUILD_PATH jetty: max_form_content_size: 10485760 diff --git a/etc/scripts/on_error.sh b/etc/scripts/on_error.sh new file mode 100755 index 00000000..8eb9f212 --- /dev/null +++ b/etc/scripts/on_error.sh @@ -0,0 +1,2 @@ +echo "### THIS IS ON ERROR SCRIPT ###" +# TODO Write actual signal command \ No newline at end of file diff --git a/etc/scripts/on_out_of_memory_error.sh b/etc/scripts/on_out_of_memory_error.sh new file mode 100755 index 00000000..e63c53ee --- /dev/null +++ b/etc/scripts/on_out_of_memory_error.sh @@ -0,0 +1,2 @@ +echo "### THIS IS ON OOM SCRIPT ###" +# TODO Write actual signal command \ No newline at end of file From e1e496e7097e5ba329074e2387e5b7609af0d885 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Mon, 3 Feb 2025 16:51:10 +0100 Subject: [PATCH 08/10] Use scripts instead of direct commands in java opts Explicitly set +x permissions --- buildpack/core/runtime.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index 9e6c332b..a7fbf752 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -2,6 +2,7 @@ import json import logging import os +import stat import re import shutil import sqlite3 @@ -68,13 +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( - os.path.join(buildpack_dir, "etc", "scripts"), - os.path.join(build_path, ".local", "scripts"), - dirs_exist_ok=True, - copy_function=shutil.copy2 + 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) From 379771a8d411d98ea374ea39efc54f5b4c5e1589 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Tue, 4 Feb 2025 14:22:45 +0100 Subject: [PATCH 09/10] Update on error scripts --- buildpack/core/runtime.py | 24 ++++++++++++++++++++++-- etc/m2ee/m2ee.yaml | 5 ++--- etc/scripts/on_error.sh | 3 +-- etc/scripts/on_out_of_memory_error.sh | 3 +-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index a7fbf752..381c89b0 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -629,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()}|", # TODO Replace in new scripts + 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( diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index d46378a2..f0ca9077 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -23,10 +23,9 @@ m2ee: [ "-Dfile.encoding=UTF-8", "-Djava.io.tmpdir=/tmp", - "-XX:OnError=/home/vcap/app/.local/scripts/on_error.sh", - "-XX:OnOutOfMemoryError=/home/vcap/app/.local/scripts/on_out_of_memory_error.sh", + "-XX:OnError=BUILD_PATH/.local/scripts/on_error.sh", + "-XX:OnOutOfMemoryError=BUILD_PATH/.local/scripts/on_out_of_memory_error.sh", ] - # TODO Replace with BUILD_PATH jetty: max_form_content_size: 10485760 diff --git a/etc/scripts/on_error.sh b/etc/scripts/on_error.sh index 8eb9f212..2d9ccd7b 100755 --- a/etc/scripts/on_error.sh +++ b/etc/scripts/on_error.sh @@ -1,2 +1 @@ -echo "### THIS IS ON ERROR SCRIPT ###" -# TODO Write actual signal command \ No newline at end of file +kill -s USR1 PYTHONPID \ No newline at end of file diff --git a/etc/scripts/on_out_of_memory_error.sh b/etc/scripts/on_out_of_memory_error.sh index e63c53ee..fcba7c3a 100755 --- a/etc/scripts/on_out_of_memory_error.sh +++ b/etc/scripts/on_out_of_memory_error.sh @@ -1,2 +1 @@ -echo "### THIS IS ON OOM SCRIPT ###" -# TODO Write actual signal command \ No newline at end of file +kill -s USR2 PYTHONPID \ No newline at end of file From b333102ca8b2ddbdba735133111c7891d27e9307 Mon Sep 17 00:00:00 2001 From: ekremsekerci Date: Wed, 5 Feb 2025 14:24:59 +0100 Subject: [PATCH 10/10] Disable custom jmx metrics --- buildpack/telemetry/datadog.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/buildpack/telemetry/datadog.py b/buildpack/telemetry/datadog.py index 026e3cdf..a0104350 100644 --- a/buildpack/telemetry/datadog.py +++ b/buildpack/telemetry/datadog.py @@ -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 @@ -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()}", ], ) @@ -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,