Add support for healthchecks "log" feature #628

Signed-off-by: Soumik Dutta <shalearkane@gmail.com>
This commit is contained in:
Soumik Dutta 2023-03-05 19:27:32 +05:30
parent a7c055264d
commit 69f6695253
7 changed files with 25 additions and 1 deletions

View file

@ -152,6 +152,24 @@ def run_configuration(config_filename, config, arguments):
encountered_error = error encountered_error = error
error_repository = repository_path error_repository = repository_path
try:
# send logs irrespective of error
dispatch.call_hooks(
'ping_monitor',
hooks,
config_filename,
monitor.MONITOR_HOOK_NAMES,
monitor.State.LOG,
monitoring_log_level,
global_arguments.dry_run,
)
except (OSError, CalledProcessError) as error:
if command.considered_soft_failure(config_filename, error):
return
encountered_error = error
yield from log_error_records('{}: Error pinging monitor'.format(config_filename), error)
if not encountered_error: if not encountered_error:
try: try:
if using_primary_action: if using_primary_action:

View file

@ -1199,6 +1199,7 @@ properties:
- start - start
- finish - finish
- fail - fail
- log
uniqueItems: true uniqueItems: true
description: | description: |
List of one or more monitoring states to ping for: List of one or more monitoring states to ping for:

View file

@ -10,6 +10,7 @@ MONITOR_STATE_TO_CRONHUB = {
monitor.State.START: 'start', monitor.State.START: 'start',
monitor.State.FINISH: 'finish', monitor.State.FINISH: 'finish',
monitor.State.FAIL: 'fail', monitor.State.FAIL: 'fail',
monitor.State.LOG: 'log',
} }

View file

@ -10,6 +10,7 @@ MONITOR_STATE_TO_CRONITOR = {
monitor.State.START: 'run', monitor.State.START: 'run',
monitor.State.FINISH: 'complete', monitor.State.FINISH: 'complete',
monitor.State.FAIL: 'fail', monitor.State.FAIL: 'fail',
monitor.State.LOG: 'log',
} }

View file

@ -10,6 +10,7 @@ MONITOR_STATE_TO_HEALTHCHECKS = {
monitor.State.START: 'start', monitor.State.START: 'start',
monitor.State.FINISH: None, # Healthchecks doesn't append to the URL for the finished state. monitor.State.FINISH: None, # Healthchecks doesn't append to the URL for the finished state.
monitor.State.FAIL: 'fail', monitor.State.FAIL: 'fail',
monitor.State.LOG: 'log',
} }
PAYLOAD_TRUNCATION_INDICATOR = '...\n' PAYLOAD_TRUNCATION_INDICATOR = '...\n'
@ -117,7 +118,7 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
) )
logger.debug('{}: Using Healthchecks ping URL {}'.format(config_filename, ping_url)) logger.debug('{}: Using Healthchecks ping URL {}'.format(config_filename, ping_url))
if state in (monitor.State.FINISH, monitor.State.FAIL): if state in (monitor.State.FINISH, monitor.State.FAIL, monitor.State.LOG):
payload = format_buffered_logs_for_payload() payload = format_buffered_logs_for_payload()
else: else:
payload = '' payload = ''

View file

@ -7,3 +7,4 @@ class State(Enum):
START = 1 START = 1
FINISH = 2 FINISH = 2
FAIL = 3 FAIL = 3
LOG = 4

View file

@ -10,6 +10,7 @@ MONITOR_STATE_TO_NTFY = {
monitor.State.START: None, monitor.State.START: None,
monitor.State.FINISH: None, monitor.State.FINISH: None,
monitor.State.FAIL: None, monitor.State.FAIL: None,
monitor.State.LOG: None,
} }