From f41dc6127edf189c0da0aa4c15ad49164f384b9e Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Thu, 29 Jun 2023 13:02:54 +0200 Subject: [PATCH 01/12] fix: support mx10 mpk builds --- buildpack/core/mono.py | 4 ++-- buildpack/core/mxbuild.py | 16 +++++++++++++--- buildpack/stage.py | 3 +++ buildpack/util.py | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/buildpack/core/mono.py b/buildpack/core/mono.py index 15077092c..13193fee5 100644 --- a/buildpack/core/mono.py +++ b/buildpack/core/mono.py @@ -65,7 +65,7 @@ def ensure_and_get_mono(mx_version, buildpack_dir, cache_dir): major_version = _detect_mono_version(mx_version) dependency_name = _compose_mono_dependency_name(major_version) fallback_location = "/tmp/opt" - + logging.debug('BUILDPACK_DIR: ensure_and_get_mono : [%s]', buildpack_dir) if major_version == "3" and distro.codename().lower() == "bionic": dependency = util.resolve_dependency( dependency_name, @@ -88,7 +88,7 @@ def ensure_and_get_mono(mx_version, buildpack_dir, cache_dir): ) return mono_location else: - version = get_dependency(dependency_name, buildpack_dir)["version"] + version = get_dependency(dependency_name, buildpack_dir=buildpack_dir)["version"] try: mono_location = _get_mono_path("/tmp/opt", version) except NotFoundException: diff --git a/buildpack/core/mxbuild.py b/buildpack/core/mxbuild.py index 646f63aad..c8e6aa24a 100644 --- a/buildpack/core/mxbuild.py +++ b/buildpack/core/mxbuild.py @@ -21,7 +21,7 @@ def build_from_source( java_version, ): logging.info("Building from source...") - + logging.debug('BUILDPACK_DIR: build_from_source : [%s]', buildpack_path) mono_location = mono.ensure_and_get_mono( runtime_version, buildpack_path, cache_path ) @@ -42,17 +42,27 @@ def build_from_source( util.lazy_remove_file(BUILD_ERRORS_JSON) - args = [ + build_command = [ os.path.join(mono_location, "bin/mono"), "--config", os.path.join(mono_location, "etc/mono/config"), - os.path.join(mxbuild_location, "modeler/mxbuild.exe"), + os.path.join(mxbuild_location, "modeler/mxbuild.exe") + ] + + if runtime_version >= 10: # mx10 support + build_command = [ + os.path.join(mxbuild_location, "modeler/mxbuild") + ] + + parameters = [ "--target=package", "--output=/tmp/model.mda", f"--java-home={jdk_location}", f"--java-exe-path={os.path.join(jdk_location, 'bin/java')}", ] + args = build_command + parameters + if runtime_version >= 6.4 or os.environ.get("FORCE_WRITE_BUILD_ERRORS"): args.append(f"--write-errors={BUILD_ERRORS_JSON}") logging.debug("Will write build errors to %s", BUILD_ERRORS_JSON) diff --git a/buildpack/stage.py b/buildpack/stage.py index 232d390b8..e277aea1d 100755 --- a/buildpack/stage.py +++ b/buildpack/stage.py @@ -123,6 +123,8 @@ def copy_buildpack_resources(): def copy_dependency_file(): + logging.debug("Copy dependency file from: %s ", os.path.join(BUILDPACK_DIR, util.DEPENDENCY_FILE)) + logging.debug("Copy dependency file to: %s ", os.path.join(BUILD_DIR, util.DEPENDENCY_FILE)) shutil.copy( os.path.join(BUILDPACK_DIR, util.DEPENDENCY_FILE), os.path.join(BUILD_DIR, util.DEPENDENCY_FILE), @@ -174,6 +176,7 @@ def cleanup_dependency_cache(cached_dir, dependency_list): copy_dependency_file() if is_source_push(): + logging.debug('BUILDPACK_DIR: [%s]', BUILDPACK_DIR) try: mxbuild.build_from_source( BUILDPACK_DIR, diff --git a/buildpack/util.py b/buildpack/util.py index 7aec764fc..1af83892d 100644 --- a/buildpack/util.py +++ b/buildpack/util.py @@ -184,6 +184,7 @@ def _get_dependency_file_contents(file): # Returns a dict of dependencies from the dependency configuration file # The dict key is composed of the key names of the YAML file, separated by a "." def _get_dependencies(buildpack_dir): + logging.debug('BUILDPACK_DIR: get_dep: [%s]', buildpack_dir) dependencies = _get_dependency_file_contents( os.path.join(buildpack_dir, DEPENDENCY_FILE) ) @@ -195,6 +196,7 @@ def _get_dependencies(buildpack_dir): # Gets a single dependency and renders def get_dependency(dependency, overrides=None, buildpack_dir=os.getcwd()): + logging.debug('BUILDPACK_DIR: get_dependency : [%s]', buildpack_dir) if overrides is None: overrides = {} result = None From 7aef007a86c3c22cdbfcae54c93b4cd713482cfa Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Wed, 28 Jun 2023 15:33:49 +0200 Subject: [PATCH 02/12] doc: add jvm garbage collector var and warning for mx10 --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6e332b2ef..7115c3073 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ This document contains general information on the Mendix Cloud Foundry Buildpack The buildpack is heavily tied to the Mendix Public Cloud, but can be used independently. Release notes are available for the [buildpack](https://github.com/mendix/cf-mendix-buildpack/releases/), [Mendix itself](https://docs.mendix.com/releasenotes/studio-pro/) and the [Mendix Public Cloud](https://docs.mendix.com/releasenotes/developer-portal/deployment). +**⚠️ Warning** At this time, CF Buildpack doesn't support building Mendix 10 MPK files. To deploy a Mendix 10 app with CF Buildpack, you will need to build the MDA file first (using Studio Pro 10 or [MxBuild](https://docs.mendix.com/refguide/mxbuild/)), and deploy the MDA file using CF Buildpack. + * [Requirements](#requirements) * [Supported Mendix Versions](#supported-mendix-versions) * [Buildpack Releases and Version Pinning](#buildpack-releases-and-version-pinning) @@ -449,6 +451,14 @@ The Java Max Metaspace Size is configured automatically based on best practices. cf set-env MAX_METASPACE_SIZE 512M ``` +### Java Garbage Collector + +The Java garbage collector is configured automatically based on best practices. You can tweak this to your needs by using another environment variable, the accepted values are Serial or G1. + +```shell +cf set-env JVM_GARBAGE_COLLECTOR Serial +``` + ### Java Virtual Machine (JVM) Settings You can configure the Java properties by providing the `JAVA_OPTS` enviroment variable to the application. From 2b53187de9d16616b78a7ec25bca819627cd7068 Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Wed, 14 Jun 2023 14:06:37 +0200 Subject: [PATCH 03/12] send dependencies.json in client-config request --- buildpack/databroker/business_events.py | 29 ++++++++++++++----- tests/unit/test_databroker_business_events.py | 8 +++-- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index e8f7a39b5..28807f47f 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -3,11 +3,15 @@ Extract Business Events configuration from vcap services and create mx constants """ +import os import logging import requests +import json from buildpack import util +BASE_PATH = os.getcwd() + CONSTANTS_PREFIX = "BusinessEvents" BE_CONSTANTS_TO_INJECT = [ @@ -30,16 +34,16 @@ def update_config(m2ee, vcap_services_data): logging.debug("Business Events config added to MicroflowConstants") -def _get_client_config(url, auth_token, version): +def _put_client_config(url, auth_token, dependencies_json): headers = { - "Authorization": f"Bearer {auth_token}", - "X-Version": version, + "Authorization": f"Bearer {auth_token}" } - resp = requests.get( + resp = requests.put( url=url, headers=headers, - timeout=30, + json=dependencies_json, + timeout=30 ) resp.raise_for_status() return resp.text @@ -55,6 +59,17 @@ def _configure_business_events_metrics(be_config, existing_constants): be_config[f"{CONSTANTS_PREFIX}.EnableHeartbeat"] = "true" +def _read_dependencies_json(): + file_path = os.path.join(BASE_PATH, "model", "dependencies.json") + try: + with open(file_path) as f: + return json.load(f) + except FileNotFoundError: + logging.error( + "Business Events: dependencies.json not found %s", file_path + ) + raise + def _get_config(vcap_services, existing_constants): be_config = {} try: @@ -76,10 +91,10 @@ def _get_config(vcap_services, existing_constants): be_config[ f"{CONSTANTS_PREFIX}.{constant}" ] = kafka_creds.get(constant, "") - client_config = _get_client_config( + client_config = _put_client_config( kafka_creds.get(CLIENT_CONFIG_URL_KEY, ""), auth_token, - "1", + _read_dependencies_json(), ) be_config[ f"{CONSTANTS_PREFIX}.ClientConfiguration" diff --git a/tests/unit/test_databroker_business_events.py b/tests/unit/test_databroker_business_events.py index 02fa2765e..473a35553 100644 --- a/tests/unit/test_databroker_business_events.py +++ b/tests/unit/test_databroker_business_events.py @@ -166,13 +166,17 @@ class TestDataBrokerBusinessEvents(unittest.TestCase): def _verify_vcap_info(self, is_apply_limits_present=True): with mock.patch( - "buildpack.databroker.business_events._get_client_config", + "buildpack.databroker.business_events._put_client_config", mock.MagicMock(return_value=self.expected_client_config), - ): + ), mock.patch( + "buildpack.databroker.business_events._read_dependencies_json", + mock.MagicMock(return_value={})) as mock_read_dependencies_json: business_events_cfg = business_events._get_config( util.get_vcap_services_data(), self.module_constants_with_metrics, ) + mock_read_dependencies_json.assert_called_once() + prefix = business_events.CONSTANTS_PREFIX assert business_events_cfg[f"{prefix}.ServerUrl"] == self.server_url From f7ec85b63d3a1445f9714940012df9ff1e0c4432 Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Wed, 21 Jun 2023 17:31:11 +0200 Subject: [PATCH 04/12] slight change in api call request to databroker client-config --- buildpack/databroker/business_events.py | 17 ++++++++++------- tests/unit/test_databroker_business_events.py | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 28807f47f..922c909da 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -6,7 +6,6 @@ import os import logging import requests -import json from buildpack import util @@ -34,15 +33,18 @@ def update_config(m2ee, vcap_services_data): logging.debug("Business Events config added to MicroflowConstants") -def _put_client_config(url, auth_token, dependencies_json): +def _put_client_config(url, auth_token, version, dependencies_json_str): headers = { - "Authorization": f"Bearer {auth_token}" + "Authorization": f"Bearer {auth_token}", + "X-Version": version, } resp = requests.put( url=url, headers=headers, - json=dependencies_json, + json={ + "dependencies": dependencies_json_str + }, timeout=30 ) resp.raise_for_status() @@ -59,11 +61,11 @@ def _configure_business_events_metrics(be_config, existing_constants): be_config[f"{CONSTANTS_PREFIX}.EnableHeartbeat"] = "true" -def _read_dependencies_json(): +def _read_dependencies_json_as_str(): file_path = os.path.join(BASE_PATH, "model", "dependencies.json") try: with open(file_path) as f: - return json.load(f) + return f.read() except FileNotFoundError: logging.error( "Business Events: dependencies.json not found %s", file_path @@ -94,7 +96,8 @@ def _get_config(vcap_services, existing_constants): client_config = _put_client_config( kafka_creds.get(CLIENT_CONFIG_URL_KEY, ""), auth_token, - _read_dependencies_json(), + "2", + _read_dependencies_json_as_str(), ) be_config[ f"{CONSTANTS_PREFIX}.ClientConfiguration" diff --git a/tests/unit/test_databroker_business_events.py b/tests/unit/test_databroker_business_events.py index 473a35553..d11d15681 100644 --- a/tests/unit/test_databroker_business_events.py +++ b/tests/unit/test_databroker_business_events.py @@ -169,13 +169,13 @@ def _verify_vcap_info(self, is_apply_limits_present=True): "buildpack.databroker.business_events._put_client_config", mock.MagicMock(return_value=self.expected_client_config), ), mock.patch( - "buildpack.databroker.business_events._read_dependencies_json", - mock.MagicMock(return_value={})) as mock_read_dependencies_json: + "buildpack.databroker.business_events._read_dependencies_json_as_str", + mock.MagicMock(return_value="")) as mock_read_dependencies_json_as_str: business_events_cfg = business_events._get_config( util.get_vcap_services_data(), self.module_constants_with_metrics, ) - mock_read_dependencies_json.assert_called_once() + mock_read_dependencies_json_as_str.assert_called_once() prefix = business_events.CONSTANTS_PREFIX From f58ee30367e07992758d3bb0431af9948a01d49e Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Thu, 22 Jun 2023 11:24:40 +0200 Subject: [PATCH 05/12] add retries to clientconfig call --- buildpack/databroker/business_events.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 922c909da..72ac7838d 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -6,6 +6,7 @@ import os import logging import requests +from requests.adapters import HTTPAdapter, Retry from buildpack import util @@ -39,7 +40,15 @@ def _put_client_config(url, auth_token, version, dependencies_json_str): "X-Version": version, } - resp = requests.put( + session = requests.Session() + retries = Retry(total=2, + backoff_factor=0.1, + status_forcelist=[ 500, 502, 503, 504 ]) + adapter = HTTPAdapter(max_retries=retries) + session.mount('http://', adapter) + session.mount('https://', adapter) + + resp = session.put( url=url, headers=headers, json={ From 723320515663cad7b6aee1d14dae3dce5745c671 Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Mon, 26 Jun 2023 09:56:34 +0200 Subject: [PATCH 06/12] change version 2 to version 1 --- buildpack/databroker/business_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 72ac7838d..73e6bbbf9 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -105,7 +105,7 @@ def _get_config(vcap_services, existing_constants): client_config = _put_client_config( kafka_creds.get(CLIENT_CONFIG_URL_KEY, ""), auth_token, - "2", + "1", _read_dependencies_json_as_str(), ) be_config[ From a8f97144c5f503cd76da8529b01e14602b294882 Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Mon, 26 Jun 2023 16:27:50 +0200 Subject: [PATCH 07/12] remove redundant http filter for request creation --- buildpack/databroker/business_events.py | 1 - 1 file changed, 1 deletion(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 73e6bbbf9..33d69da67 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -45,7 +45,6 @@ def _put_client_config(url, auth_token, version, dependencies_json_str): backoff_factor=0.1, status_forcelist=[ 500, 502, 503, 504 ]) adapter = HTTPAdapter(max_retries=retries) - session.mount('http://', adapter) session.mount('https://', adapter) resp = session.put( From 8a7b60d9e9ad1c49a5028977319576dd081fd7af Mon Sep 17 00:00:00 2001 From: Albert de Vries Date: Tue, 27 Jun 2023 10:51:08 +0200 Subject: [PATCH 08/12] formatting --- buildpack/databroker/business_events.py | 17 ++++++----------- tests/unit/test_databroker_business_events.py | 3 ++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 33d69da67..67c8342e9 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -41,19 +41,15 @@ def _put_client_config(url, auth_token, version, dependencies_json_str): } session = requests.Session() - retries = Retry(total=2, - backoff_factor=0.1, - status_forcelist=[ 500, 502, 503, 504 ]) + retries = Retry(total=2, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) adapter = HTTPAdapter(max_retries=retries) - session.mount('https://', adapter) + session.mount("https://", adapter) resp = session.put( url=url, headers=headers, - json={ - "dependencies": dependencies_json_str - }, - timeout=30 + json={"dependencies": dependencies_json_str}, + timeout=30, ) resp.raise_for_status() return resp.text @@ -75,11 +71,10 @@ def _read_dependencies_json_as_str(): with open(file_path) as f: return f.read() except FileNotFoundError: - logging.error( - "Business Events: dependencies.json not found %s", file_path - ) + logging.error("Business Events: dependencies.json not found %s", file_path) raise + def _get_config(vcap_services, existing_constants): be_config = {} try: diff --git a/tests/unit/test_databroker_business_events.py b/tests/unit/test_databroker_business_events.py index d11d15681..d3c1e6e23 100644 --- a/tests/unit/test_databroker_business_events.py +++ b/tests/unit/test_databroker_business_events.py @@ -170,7 +170,8 @@ def _verify_vcap_info(self, is_apply_limits_present=True): mock.MagicMock(return_value=self.expected_client_config), ), mock.patch( "buildpack.databroker.business_events._read_dependencies_json_as_str", - mock.MagicMock(return_value="")) as mock_read_dependencies_json_as_str: + mock.MagicMock(return_value=""), + ) as mock_read_dependencies_json_as_str: business_events_cfg = business_events._get_config( util.get_vcap_services_data(), self.module_constants_with_metrics, From bc95837045b6718d65f9cc311e45751c1cbaa100 Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Thu, 29 Jun 2023 15:57:52 +0200 Subject: [PATCH 09/12] fix: support mx10 mpk builds --- buildpack/core/mono.py | 6 ++++-- buildpack/core/mxbuild.py | 8 +++----- buildpack/stage.py | 4 +--- buildpack/util.py | 2 -- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/buildpack/core/mono.py b/buildpack/core/mono.py index 13193fee5..ab2fc79f0 100644 --- a/buildpack/core/mono.py +++ b/buildpack/core/mono.py @@ -65,7 +65,7 @@ def ensure_and_get_mono(mx_version, buildpack_dir, cache_dir): major_version = _detect_mono_version(mx_version) dependency_name = _compose_mono_dependency_name(major_version) fallback_location = "/tmp/opt" - logging.debug('BUILDPACK_DIR: ensure_and_get_mono : [%s]', buildpack_dir) + if major_version == "3" and distro.codename().lower() == "bionic": dependency = util.resolve_dependency( dependency_name, @@ -88,7 +88,9 @@ def ensure_and_get_mono(mx_version, buildpack_dir, cache_dir): ) return mono_location else: - version = get_dependency(dependency_name, buildpack_dir=buildpack_dir)["version"] + version = get_dependency(dependency_name, buildpack_dir=buildpack_dir)[ + "version" + ] try: mono_location = _get_mono_path("/tmp/opt", version) except NotFoundException: diff --git a/buildpack/core/mxbuild.py b/buildpack/core/mxbuild.py index c8e6aa24a..6bbcc9677 100644 --- a/buildpack/core/mxbuild.py +++ b/buildpack/core/mxbuild.py @@ -21,7 +21,7 @@ def build_from_source( java_version, ): logging.info("Building from source...") - logging.debug('BUILDPACK_DIR: build_from_source : [%s]', buildpack_path) + mono_location = mono.ensure_and_get_mono( runtime_version, buildpack_path, cache_path ) @@ -46,13 +46,11 @@ def build_from_source( os.path.join(mono_location, "bin/mono"), "--config", os.path.join(mono_location, "etc/mono/config"), - os.path.join(mxbuild_location, "modeler/mxbuild.exe") + os.path.join(mxbuild_location, "modeler/mxbuild.exe"), ] if runtime_version >= 10: # mx10 support - build_command = [ - os.path.join(mxbuild_location, "modeler/mxbuild") - ] + build_command = [os.path.join(mxbuild_location, "modeler/mxbuild")] parameters = [ "--target=package", diff --git a/buildpack/stage.py b/buildpack/stage.py index e277aea1d..e89100de4 100755 --- a/buildpack/stage.py +++ b/buildpack/stage.py @@ -123,8 +123,6 @@ def copy_buildpack_resources(): def copy_dependency_file(): - logging.debug("Copy dependency file from: %s ", os.path.join(BUILDPACK_DIR, util.DEPENDENCY_FILE)) - logging.debug("Copy dependency file to: %s ", os.path.join(BUILD_DIR, util.DEPENDENCY_FILE)) shutil.copy( os.path.join(BUILDPACK_DIR, util.DEPENDENCY_FILE), os.path.join(BUILD_DIR, util.DEPENDENCY_FILE), @@ -176,7 +174,6 @@ def cleanup_dependency_cache(cached_dir, dependency_list): copy_dependency_file() if is_source_push(): - logging.debug('BUILDPACK_DIR: [%s]', BUILDPACK_DIR) try: mxbuild.build_from_source( BUILDPACK_DIR, @@ -186,6 +183,7 @@ def cleanup_dependency_cache(cached_dir, dependency_list): runtime_version, JAVA_VERSION, ) + copy_dependency_file() # dependency file was deleted after mpk build process except RuntimeError as error: logging.error(error) sys.exit(1) diff --git a/buildpack/util.py b/buildpack/util.py index 1af83892d..7aec764fc 100644 --- a/buildpack/util.py +++ b/buildpack/util.py @@ -184,7 +184,6 @@ def _get_dependency_file_contents(file): # Returns a dict of dependencies from the dependency configuration file # The dict key is composed of the key names of the YAML file, separated by a "." def _get_dependencies(buildpack_dir): - logging.debug('BUILDPACK_DIR: get_dep: [%s]', buildpack_dir) dependencies = _get_dependency_file_contents( os.path.join(buildpack_dir, DEPENDENCY_FILE) ) @@ -196,7 +195,6 @@ def _get_dependencies(buildpack_dir): # Gets a single dependency and renders def get_dependency(dependency, overrides=None, buildpack_dir=os.getcwd()): - logging.debug('BUILDPACK_DIR: get_dependency : [%s]', buildpack_dir) if overrides is None: overrides = {} result = None From 6e9203b87e7b3130304147f4f2e8b8d9d0f52bdf Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Thu, 29 Jun 2023 19:25:54 +0200 Subject: [PATCH 10/12] rollback business events changes 4x --- buildpack/databroker/business_events.py | 35 +++---------------- tests/unit/test_databroker_business_events.py | 9 ++--- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 67c8342e9..318538c52 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -3,15 +3,11 @@ Extract Business Events configuration from vcap services and create mx constants """ -import os import logging import requests -from requests.adapters import HTTPAdapter, Retry from buildpack import util -BASE_PATH = os.getcwd() - CONSTANTS_PREFIX = "BusinessEvents" BE_CONSTANTS_TO_INJECT = [ @@ -20,9 +16,7 @@ "Password", "ClientConfiguration", ] - OPTIONAL_CONSTANT_APPLY_LIMITS = "ApplyLimits" - CLIENT_CONFIG_URL_KEY = "ClientConfigUrl" @@ -34,27 +28,19 @@ def update_config(m2ee, vcap_services_data): logging.debug("Business Events config added to MicroflowConstants") -def _put_client_config(url, auth_token, version, dependencies_json_str): +def _get_client_config(url, auth_token, version): headers = { "Authorization": f"Bearer {auth_token}", "X-Version": version, } - session = requests.Session() - retries = Retry(total=2, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) - adapter = HTTPAdapter(max_retries=retries) - session.mount("https://", adapter) - - resp = session.put( + resp = requests.get( url=url, headers=headers, - json={"dependencies": dependencies_json_str}, timeout=30, ) resp.raise_for_status() return resp.text - - def _configure_business_events_metrics(be_config, existing_constants): if f"{CONSTANTS_PREFIX}.GenerateMetrics" in existing_constants: if util.is_free_app(): @@ -65,16 +51,6 @@ def _configure_business_events_metrics(be_config, existing_constants): be_config[f"{CONSTANTS_PREFIX}.EnableHeartbeat"] = "true" -def _read_dependencies_json_as_str(): - file_path = os.path.join(BASE_PATH, "model", "dependencies.json") - try: - with open(file_path) as f: - return f.read() - except FileNotFoundError: - logging.error("Business Events: dependencies.json not found %s", file_path) - raise - - def _get_config(vcap_services, existing_constants): be_config = {} try: @@ -96,11 +72,10 @@ def _get_config(vcap_services, existing_constants): be_config[ f"{CONSTANTS_PREFIX}.{constant}" ] = kafka_creds.get(constant, "") - client_config = _put_client_config( + client_config = _get_client_config( kafka_creds.get(CLIENT_CONFIG_URL_KEY, ""), auth_token, "1", - _read_dependencies_json_as_str(), ) be_config[ f"{CONSTANTS_PREFIX}.ClientConfiguration" @@ -116,12 +91,10 @@ def _get_config(vcap_services, existing_constants): ) else: logging.error("Business Events: configuration is empty") - # Update Business Events constants for metrics _configure_business_events_metrics(be_config, existing_constants) except Exception as ex: logging.error( "Business Events: error reading deployment configuration %s", str(ex) ) - - return be_config + return be_config \ No newline at end of file diff --git a/tests/unit/test_databroker_business_events.py b/tests/unit/test_databroker_business_events.py index d3c1e6e23..02fa2765e 100644 --- a/tests/unit/test_databroker_business_events.py +++ b/tests/unit/test_databroker_business_events.py @@ -166,18 +166,13 @@ class TestDataBrokerBusinessEvents(unittest.TestCase): def _verify_vcap_info(self, is_apply_limits_present=True): with mock.patch( - "buildpack.databroker.business_events._put_client_config", + "buildpack.databroker.business_events._get_client_config", mock.MagicMock(return_value=self.expected_client_config), - ), mock.patch( - "buildpack.databroker.business_events._read_dependencies_json_as_str", - mock.MagicMock(return_value=""), - ) as mock_read_dependencies_json_as_str: + ): business_events_cfg = business_events._get_config( util.get_vcap_services_data(), self.module_constants_with_metrics, ) - mock_read_dependencies_json_as_str.assert_called_once() - prefix = business_events.CONSTANTS_PREFIX assert business_events_cfg[f"{prefix}.ServerUrl"] == self.server_url From 547d5d34e43fb2ba30b28da9f737dceea9518649 Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Thu, 29 Jun 2023 19:27:47 +0200 Subject: [PATCH 11/12] rollback business events changes 4x --- buildpack/databroker/business_events.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index 318538c52..bb0109a2d 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -41,6 +41,8 @@ def _get_client_config(url, auth_token, version): ) resp.raise_for_status() return resp.text + + def _configure_business_events_metrics(be_config, existing_constants): if f"{CONSTANTS_PREFIX}.GenerateMetrics" in existing_constants: if util.is_free_app(): From 376bcd75bb04d202537d625a14ff9877c3889900 Mon Sep 17 00:00:00 2001 From: Sanny Ramirez Date: Thu, 29 Jun 2023 19:31:56 +0200 Subject: [PATCH 12/12] rollback business events changes 4x --- buildpack/databroker/business_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildpack/databroker/business_events.py b/buildpack/databroker/business_events.py index bb0109a2d..c58fdad02 100644 --- a/buildpack/databroker/business_events.py +++ b/buildpack/databroker/business_events.py @@ -99,4 +99,4 @@ def _get_config(vcap_services, existing_constants): logging.error( "Business Events: error reading deployment configuration %s", str(ex) ) - return be_config \ No newline at end of file + return be_config