connection too much when large scale failure

When large scale failure, there would be too many host or instance
failure notifications in a very short time. Each time when one
notification to be sent to masakari, it needs to make client, which
brings great pressure to keystone.

This patch keep the client reusable when it is made. Until exception
it will be made again.

Change-Id: I39795bc796d3e2402881b8116cdc241aa2d60a9f
This commit is contained in:
sue 2022-01-26 15:04:43 +08:00
parent 339218d0af
commit 4ecfb34a09
1 changed files with 11 additions and 4 deletions

View File

@ -26,6 +26,15 @@ CONF = masakarimonitors.conf.CONF
class SendNotification(object):
def __init__(self):
self._masakari_client = None
@property
def masakari_client(self):
if not self._masakari_client:
self._masakari_client = self._make_client()
return self._masakari_client
def _make_client(self):
auth = ks_loading.load_auth_from_conf_options(CONF, 'api')
session = ks_loading.load_session_from_conf_options(CONF, 'api',
@ -50,14 +59,11 @@ class SendNotification(object):
LOG.info("Send a notification. %s", event)
# Get client.
client = self._make_client()
# Send a notification.
retry_count = 0
while True:
try:
response = client.create_notification(
response = self.masakari_client.create_notification(
type=event['notification']['type'],
hostname=event['notification']['hostname'],
generated_time=event['notification']['generated_time'],
@ -89,4 +95,5 @@ class SendNotification(object):
eventlet.greenthread.sleep(api_retry_interval)
else:
LOG.exception("Exception caught: %s", e)
self._masakari_client = None
break