`MetricsSender` does not handle zmq socket in a thread-safe manner
A simple sender script like this:
#!/usr/bin/env python3
import time
from constellation.core.cmdp import MetricsType
from constellation.core.satellite import Satellite
from constellation.core.monitoring import schedule_metric
class MyStatProducer(Satellite):
@schedule_metric(MetricsType.LAST_VALUE, 0.5)
def get_answer(self):
"""The answer to the Ultimate Question"""
self.log.info("Got the answer!")
print("sending data")
return 42, "Answer"
m = MyStatProducer("mock_sender", group="constellation", cmd_port=12345, mon_port=16542, hb_port=32123, interface='*')
m._add_com_thread()
m._start_com_threads()
time.sleep(0.3)
i = 0
while True:
print(f"producing data for {i} s")
i += 1
time.sleep(1)
print("done")
will at some point (within a few seconds) produce a packet like this:
[b'STATS/GET_ANSWER', b'\xa5CMDP\x01\xabmock_sender\xd7\xffbb?\xb4fLv\xb8\x80', b'LOG/INFO/MOCK_SENDER', b'\xa5CMDP\x01\xabmock_sender\xd7\xffbj\xd10fLv\xb8\xde\x00\x14\xa4name\xabmock_sender\xa3msg\xafGot the answer!\xa4args\xc0\xa9levelname\xa4INFO\xa7levelno\x14\xa8pathname\xd9K/home/hperrey/src/constellation/python/myscripts/simple_monitoringsender.py\xa8filename\xbasimple_monitoringsender.py\xa6module\xb7simple_monitoringsender\xa8exc_info\xc0\xa8exc_text\xc0\xaastack_info\xc0\xa6lineno\x10\xa8funcName\xaaget_answer\xa7created\xcbA\xd9\x93\x1d\xae\x1ad\x88\xa5msecs\xcb@y\xc0\x00\x00\x00\x00\x00\xafrelativeCreated\xcbA\x16\x95V\xd3C\x00\x00\xa6thread\xcf\x00\x00p\xc6W/\xc6\xc0\xaathreadName\xb8Thread-2 (_send_metrics)\xabprocessName\xabMainProcess\xa7process\xcdf\x1f', b'Got the answer!']
which will trigger a msgpack.exceptions.ExtraData
exception. Likely cause: Sending logs messages and stats close to each other in time leads to a combined packet as the corresponding sending routines run in different threads.