Send api.fault notification on API service faults.
Exceptions caught by the API middleware will now send "api.fault" notifications indicating the offending URL and the underlying exception. The allows the billing/usage systems to track requests end-to-end without having to monitor log files. Disabled by default. Enable with --notify_api_faults Change-Id: Ied2783259413ba12d686b44b33e0707645e51afb
This commit is contained in:
@@ -45,9 +45,29 @@ notify_any_opt = cfg.BoolOpt('notify_on_any_change', default=False,
|
|||||||
'state changes. Valid values are False for no notifications, '
|
'state changes. Valid values are False for no notifications, '
|
||||||
'True for notifications on any instance changes.')
|
'True for notifications on any instance changes.')
|
||||||
|
|
||||||
|
notify_api_faults = cfg.BoolOpt('notify_api_faults', default=False,
|
||||||
|
help='If set, send api.fault notifications on caught exceptions '
|
||||||
|
'in the API service.')
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
FLAGS.register_opt(notify_state_opt)
|
FLAGS.register_opt(notify_state_opt)
|
||||||
FLAGS.register_opt(notify_any_opt)
|
FLAGS.register_opt(notify_any_opt)
|
||||||
|
FLAGS.register_opt(notify_api_faults)
|
||||||
|
|
||||||
|
|
||||||
|
def send_api_fault(url, status, exception):
|
||||||
|
"""Send an api.fault notification."""
|
||||||
|
|
||||||
|
if not FLAGS.notify_api_faults:
|
||||||
|
return
|
||||||
|
|
||||||
|
payload = {'url': url, 'exception': str(exception), 'status': status}
|
||||||
|
|
||||||
|
publisher_id = notifier_api.publisher_id("api")
|
||||||
|
|
||||||
|
notifier_api.notify(None, publisher_id, 'api.fault', notifier_api.ERROR,
|
||||||
|
payload)
|
||||||
|
|
||||||
|
|
||||||
def send_update(context, old_instance, new_instance, service=None, host=None):
|
def send_update(context, old_instance, new_instance, service=None, host=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user