ZMQ: Minor matchmaker improvement

Added more information to logs and prefix to key in matchmaker_redis

Change-Id: I5d718c4a84dedc6654e13f9ca740a2deba5a7e43
This commit is contained in:
Victor Sergeyev 2015-08-04 15:13:14 +03:00
parent 2aa35bb6d9
commit 64831f29ee
2 changed files with 11 additions and 6 deletions

View File

@ -67,12 +67,15 @@ class MatchMakerBase(object):
raise oslo_messaging.InvalidTarget(err_msg, target) raise oslo_messaging.InvalidTarget(err_msg, target)
if len(hosts) == 1: if len(hosts) == 1:
LOG.info(_LI("A single host found for target %s.") % target) host = hosts[0]
return hosts[0] LOG.info(_LI("A single host %(host)s found for target %(target)s.")
% {"host": host, "target": target})
else: else:
LOG.warning(_LW("Multiple hosts were found for target %s. Using " host = random.choice(hosts)
"the random one.") % target) LOG.warning(_LW("Multiple hosts %(hosts)s were found for target "
return random.choice(hosts) " %(target)s. Using the random one - %(host)s.")
% {"hosts": hosts, "target": target, "host": host})
return host
class DummyMatchMaker(MatchMakerBase): class DummyMatchMaker(MatchMakerBase):

View File

@ -50,7 +50,9 @@ class RedisMatchMaker(base.MatchMakerBase):
def _target_to_key(self, target): def _target_to_key(self, target):
attributes = ['topic', 'exchange', 'server'] attributes = ['topic', 'exchange', 'server']
return ':'.join((getattr(target, attr) or "*") for attr in attributes) prefix = "ZMQ-target"
key = ":".join((getattr(target, attr) or "*") for attr in attributes)
return "%s-%s" % (prefix, key)
def _get_keys_by_pattern(self, pattern): def _get_keys_by_pattern(self, pattern):
return self._redis.keys(pattern) return self._redis.keys(pattern)