Skip to content

Commit 4c9695a

Browse files
authored
Fix/downgrade http errors (#73)
* downgrade http check errors to warnings * bump to hmpps-sre-python-lib v0.1.14
1 parent 9f65994 commit 4c9695a

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

health_ping.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
2-
"""Health ping - fetches all /health and /info endpoints
3-
and stores the results in Redis"""
2+
"""Health ping - fetches all /health and /info endpoints
3+
and stores the results in Redis"""
44

55
from datetime import datetime, timezone
66
import os
@@ -28,6 +28,7 @@
2828
class HealthPing:
2929
def __init__(self, services):
3030
self.services = services
31+
3132
def _get_build_image_tag(self, output):
3233
version = ''
3334
version_locations = (
@@ -84,6 +85,7 @@ def _get_http_endpoint(self, endpoint):
8485
stream_data.update({'json': str(json.dumps(output))})
8586
# log_info(app_version)
8687
except Exception as e:
88+
# Legitimate error, because Redis is exhibiting a fault
8789
log_error(
8890
f'{endpoint}: Unable to update stream_data with json - exception: {e}'
8991
)
@@ -96,9 +98,9 @@ def _get_http_endpoint(self, endpoint):
9698
stream_data.update({'http_s': 0})
9799
# Log error in stream for easier diagnosis of problems
98100
stream_data.update({'error': str(e)})
99-
log_error(f'Failed to get data from {endpoint} - exception: {e}')
101+
log_warning(f'Failed to get data from {endpoint} - exception: {e}')
100102
except Exception as e:
101-
log_error(f'Failed to parse response from {endpoint} - exception: {e}')
103+
log_warning(f'Failed to parse response from {endpoint} - exception: {e}')
102104
return output, stream_data
103105

104106
def _get_active_agencies(self, env, output, endpoint_type):
@@ -120,7 +122,7 @@ def _get_active_agencies(self, env, output, endpoint_type):
120122
except (KeyError, TypeError):
121123
pass
122124
except Exception as e:
123-
log_error(f'failed to process active_agencies: {e}')
125+
log_warning(f'failed to process active_agencies: {e}')
124126
return active_agencies_dict
125127

126128
def _update_app_version(
@@ -223,7 +225,7 @@ def _process_env(self, c_name, component, env_id, env, endpoints_list, services)
223225
if stream_updated_data:
224226
stream_data.update(stream_updated_data)
225227

226-
# Try to get app version (HEAT-567 -
228+
# Try to get app version (HEAT-567 -
227229
# get app version from build image tag on health or info)
228230
env_data = {}
229231
update_sc = False
@@ -301,17 +303,15 @@ def start_health_ping(self):
301303
main_threads = list()
302304

303305
while True:
304-
log_info(
305-
'Starting a new run.'
306-
)
306+
log_info('Starting a new run.')
307307
components = self.services.sc.get_all_records(self.services.sc.components_get)
308308
for component in components:
309309
c_name = component.get('name')
310310
for env in component.get('envs', []):
311311
env_id = env.get('documentId', '')
312312
if env.get('url') and env.get('monitor'):
313313
# moving the endpoint_tuple loop inside the process_env
314-
# to avoid duplication of build_image_tag
314+
# to avoid duplication of build_image_tag
315315
# if it's present in both health and info
316316
thread = threading.Thread(
317317
target=self._process_env,
@@ -338,10 +338,8 @@ def start_health_ping(self):
338338
# Allow the threads to finish before sleeping
339339
for thread in main_threads:
340340
thread.join()
341-
log_info(
342-
f'Completed all threads. Sleeping for {refresh_interval} seconds.'
343-
)
344-
# Even if job had errors , error will be recorded in SC
341+
log_info(f'Completed all threads. Sleeping for {refresh_interval} seconds.')
342+
# Even if job had errors , error will be recorded in SC
345343
# and job will be marked successful
346344
# as few services are expected to fail.
347345
if job.error_messages:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ dependencies = [
1010
]
1111

1212
[tool.uv.sources]
13-
hmpps-sre-python-lib = { url = "https://github.com/ministryofjustice/hmpps-sre-python-lib/releases/download/v0.1.13/hmpps_sre_python_lib-0.1.13-py3-none-any.whl" }
13+
hmpps-sre-python-lib = { url = "https://github.com/ministryofjustice/hmpps-sre-python-lib/releases/download/v0.1.14/hmpps_sre_python_lib-0.1.14-py3-none-any.whl" }

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)