Fix ConnectionRefused in TCP publisher

If ceilometer is started before the receiving end of the TCP
publisher, the TCP publisher's constructor ends with
an exception "ConnectionRefusedError". After that
ceilometer doesn't try to reconnect again.

I tested the change without and then with sg-core
running as a receiver. When sg-core wasn't running,
ceilometer would keep logging errors as expected. When I
started sg-core, metrics started to flow from ceilometer to
sg-core (without the need to touch the notification agent)

This change adds another "except" to catch the exception.
I also noticed, that the way the LOG.Error(...) is done
in the publisher doesn't work and it ends with a syntax
error. (_() accepts only one parameter, not two). So
I fixed the LOG.Errors.

Change-Id: Ib231dd0e6762159eeb09c02aed84a80561fbe188
This commit is contained in:
Jaromir Wysoglad 2023-10-13 06:08:01 -04:00
parent eb407792aa
commit 9c96730f15
1 changed files with 11 additions and 6 deletions

View File

@ -42,14 +42,19 @@ class TCPPublisher(publisher.ConfigPublisherBase):
self.socket = socket.create_connection(self.inet_addr)
return True
except socket.gaierror:
LOG.error(_("Unable to resolv the remote %(host)s",
{'host': self.inet_addr[0],
'port': self.inet_addr[1]}))
LOG.error(_("Unable to resolv the remote %(host)s") %
{'host': self.inet_addr[0],
'port': self.inet_addr[1]})
except TimeoutError:
LOG.error(_("Unable to connect to the remote endpoint "
"%(host)s:%(port)d. The connection timed out.",
{'host': self.inet_addr[0],
'port': self.inet_addr[1]}))
"%(host)s:%(port)d. The connection timed out.") %
{'host': self.inet_addr[0],
'port': self.inet_addr[1]})
except ConnectionRefusedError:
LOG.error(_("Unable to connect to the remote endpoint "
"%(host)s:%(port)d. Connection refused.") %
{'host': self.inet_addr[0],
'port': self.inet_addr[1]})
return False
def publish_samples(self, samples):