From a81adcbea8840baa011786670b3de6ce4b2de056 Mon Sep 17 00:00:00 2001 From: Sandhya1874 <39799075+Sandhya1874@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:36:00 +0100 Subject: [PATCH] Added debug for build_image_tag (#33) --- health_ping.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/health_ping.py b/health_ping.py index 445a2e9..2ae15cc 100755 --- a/health_ping.py +++ b/health_ping.py @@ -86,7 +86,6 @@ def update_app_version(app_version, c_name, e_name, github_repo): version_data.update({'git_compare': json.dumps(commits)}) redis.xadd(version_key, version_data, maxlen=200, approximate=False) log.info(f'Updating redis stream with new version. {version_key} = {version_data}') - else: # Must be first time entry to version redis stream redis.xadd(version_key, version_data, maxlen=200, approximate=False) @@ -96,21 +95,6 @@ def update_app_version(app_version, c_name, e_name, github_repo): # Always update the latest version key redis.json().set('latest:versions', f'$.{version_key}', version_data) log.info(f'Updating redis key with latest version. {version_key} = {version_data}') - if (endpoint_type == 'info'): - env_data = [] - update_sc = False - for e in component["attributes"]["environments"]: - if e_name == e["name"]: - if e["build_image_tag"] is None: - e["build_image_tag"] = [] - if app_version != e["build_image_tag"]: - env_data.append({"id": e["id"], "build_image_tag": app_version }) - update_sc = True - else: - env_data.append({"id": e["id"]}) - if update_sc: - data = {"environments": env_data} - update_sc_component(c_id, data) except Exception as e: log.error(e) @@ -146,7 +130,6 @@ def process_env(c_name, e_name, endpoint, endpoint_type, component): stream_data.update({'error': str(e)}) log.error(e) - # Try to get app version. try: version_locations = ( @@ -154,12 +137,29 @@ def process_env(c_name, e_name, endpoint, endpoint_type, component): "output['components']['healthInfo']['details']['version']", # Java/Kotlin springboot apps "output['build']['buildNumber']" # Node/Typscript apps ) + c_id = component["id"] for loc in version_locations: try: app_version = eval(loc) log.debug(f"Found app version: {c_name}:{e_name}:{app_version}") github_repo = component["attributes"]["github_repo"] update_app_version(app_version, c_name, e_name, github_repo) + if (endpoint_type == 'info'): + env_data = [] + update_sc = False + for e in component["attributes"]["environments"]: + if e_name == e["name"]: # and c_id == component["id"]: + if e["build_image_tag"] is None: + e["build_image_tag"] = [] + if app_version != e["build_image_tag"]: + env_data.append({"id": e["id"], "build_image_tag": app_version }) + update_sc = True + else: + env_data.append({"id": e["id"]}) + log.info(f'Updating build_image_tag for component {c_id} {c_name} {env_data}') + if update_sc: + data = {"environments": env_data} + update_sc_component(c_id, data) break except (KeyError, TypeError): pass @@ -169,6 +169,9 @@ def process_env(c_name, e_name, endpoint, endpoint_type, component): except Exception as e: log.error(e) + # Get component id + c_id = component["id"] + # Try to get active agencies try: if ('activeAgencies' in output) and (endpoint_type == 'info'): @@ -304,8 +307,6 @@ def startHttpServer(): for env in component["attributes"]["environments"]: c_name = component["attributes"]["name"] e_name = env["name"] - # Current component ID needed for strapi api call - c_id = component["id"] if (env["url"]) and (env["monitor"] == True): if env["health_path"]: endpoint = f'{env["url"]}{env["health_path"]}'