diff --git a/buildpack/core/runtime.py b/buildpack/core/runtime.py index a9e79c6a1..99396f049 100644 --- a/buildpack/core/runtime.py +++ b/buildpack/core/runtime.py @@ -68,6 +68,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) @@ -613,15 +628,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( diff --git a/buildpack/telemetry/datadog.py b/buildpack/telemetry/datadog.py index 026e3cdf6..bf68d359c 100644 --- a/buildpack/telemetry/datadog.py +++ b/buildpack/telemetry/datadog.py @@ -272,6 +272,9 @@ def _get_runtime_jmx_config(extra_jmx_instance_config=None): # and run app/.local/bin/java -jar ~/jmxterm.jar # # The extra attributes are only available from Mendix 7.15.0+ + # Note: aliases are added later to make the metrics available for free on + # Datadog as `mx` is a supported prefix. Before that, all these metrics were + # being indexed as custom metrics by Datadog which are not free. config = { "init_config": {}, "instances": [ @@ -287,9 +290,9 @@ def _get_runtime_jmx_config(extra_jmx_instance_config=None): # NamedUserSessions = 0; # AnonymousSessions = 0; "attribute": { - "NamedUsers": {"metrics_type": "gauge"}, - "NamedUserSessions": {"metrics_type": "gauge"}, - "AnonymousSessions": {"metrics_type": "gauge"}, + "NamedUsers": {"metrics_type": "gauge", "alias": "mx.com.mendix.named_users"}, + "NamedUserSessions": {"metrics_type": "gauge", "alias": "mx.com.mendix.named_user_sessions"}, + "AnonymousSessions": {"metrics_type": "gauge", "alias": "mx.com.mendix.anonymous_sessions"}, }, } }, @@ -302,11 +305,11 @@ def _get_runtime_jmx_config(extra_jmx_instance_config=None): # Deletes = 0; # Transactions = 25; "attribute": { - "Selects": {"metrics_type": "counter"}, - "Updates": {"metrics_type": "counter"}, - "Inserts": {"metrics_type": "counter"}, - "Deletes": {"metrics_type": "counter"}, - "Transactions": {"metrics_type": "counter"}, + "Selects": {"metrics_type": "counter", "alias": "mx.com.mendix.selects"}, + "Updates": {"metrics_type": "counter", "alias": "mx.com.mendix.updates"}, + "Inserts": {"metrics_type": "counter", "alias": "mx.com.mendix.inserts"}, + "Deletes": {"metrics_type": "counter", "alias": "mx.com.mendix.deletes"}, + "Transactions": {"metrics_type": "counter", "alias": "mx.com.mendix.transactions"}, }, } }, @@ -315,7 +318,9 @@ def _get_runtime_jmx_config(extra_jmx_instance_config=None): "bean": "com.mendix:type=General", # Languages = en_US; # Entities = 24; - "attribute": {"Entities": {"metrics_type": "gauge"}}, + "attribute": { + "Entities": {"metrics_type": "gauge", "alias": "mx.com.mendix.entities"}, + }, } }, { @@ -330,23 +335,14 @@ def _get_runtime_jmx_config(extra_jmx_instance_config=None): # ThreadsPriority = 5; # QueueSize = 0; "attribute": { - "Threads": {"metrics_type": "gauge"}, - "MaxThreads": {"metrics_type": "gauge"}, - "IdleThreads": {"metrics_type": "gauge"}, - "QueueSize": {"metrics_type": "gauge"}, + "Threads": {"metrics_type": "gauge", "alias": "mx.com.mendix.threads"}, + "MaxThreads": {"metrics_type": "gauge", "alias": "mx.com.mendix.max_threads"}, + "IdleThreads": {"metrics_type": "gauge", "alias": "mx.com.mendix.idle_threads"}, + "QueueSize": {"metrics_type": "gauge", "alias": "mx.com.mendix.queue_size"}, }, } }, ], - # }, { - # 'include': { - # 'bean': 'com.mendix:type=Jetty', - # # ConnectedEndPoints = 0; - # # IdleTimeout = 30000; - # # RequestsActiveMax = 0; - # 'attribute': { - # } - # }, } ], } diff --git a/dependencies.yml b/dependencies.yml index eba749437..c586a7839 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 }}" diff --git a/etc/m2ee/m2ee.yaml b/etc/m2ee/m2ee.yaml index 26687b2ed..f0ca90770 100644 --- a/etc/m2ee/m2ee.yaml +++ b/etc/m2ee/m2ee.yaml @@ -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: diff --git a/etc/scripts/on_error.sh b/etc/scripts/on_error.sh new file mode 100755 index 000000000..05e111625 --- /dev/null +++ b/etc/scripts/on_error.sh @@ -0,0 +1,2 @@ +#!/bin/bash +kill -s USR1 PYTHONPID 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 000000000..7f6501e32 --- /dev/null +++ b/etc/scripts/on_out_of_memory_error.sh @@ -0,0 +1,2 @@ +#!/bin/bash +kill -s USR2 PYTHONPID