Skip to content

Commit

Permalink
Added debug for build_image_tag (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandhya1874 authored Oct 16, 2024
1 parent faeaa79 commit a81adcb
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions health_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -146,20 +130,36 @@ 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 = (
"output['build']['version']", # all apps should have version here
"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
Expand All @@ -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'):
Expand Down Expand Up @@ -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"]}'
Expand Down

0 comments on commit a81adcb

Please sign in to comment.