Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mongodb_store] Throttle noisy error log #271

Open
wants to merge 3 commits into
base: melodic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mongodb_store/launch/mongodb_store_inc.launch
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<arg name="repl_set" default="rs0" />
<arg name="queue_size" default="100" />
<arg name="bind_to_host" default="false" />
<arg name="logerr_period" default="0" />

<arg name="use_localdatacenter" default="true" />

Expand Down Expand Up @@ -66,6 +67,7 @@
<group if="$(arg launch_replicator)">
<node name="replicator_node" pkg="mongodb_store" type="replicator_node.py" machine="$(arg machine)">
<param name="replicator_dump_path" value="$(arg replicator_dump_path)"/>
<param name="logerr_period" value="$(arg logerr_period)"/>
</node>
</group>

Expand Down
19 changes: 11 additions & 8 deletions mongodb_store/scripts/replicator_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@


class Process(object):
def __init__(self, cmd):
def __init__(self, cmd, logerr_period):
self.lock = Lock()
self.cmd = cmd
self.process = None
self.threads = []
self.logerr_period = logerr_period

def _message_callback(self, stream, callback):
buf = str()
Expand Down Expand Up @@ -126,7 +127,7 @@ def on_stdout(self, msg):
rospy.loginfo('[{}] {}'.format(self.cmd[0], msg))

def on_stderr(self, msg):
rospy.logerr('[{}] {}'.format(self.cmd[0], msg))
rospy.logerr_throttle(self.logerr_period, '[{}] {}'.format(self.cmd[0], msg))


class MongoProcess(Process):
Expand All @@ -151,7 +152,7 @@ def progress(self):


class MongoDumpProcess(MongoProcess):
def __init__(self, host, port, db, collection, dump_path, less_time=None, query=None):
def __init__(self, host, port, db, collection, dump_path, less_time=None, query=None, logerr_period=0):
cmd = [
'mongodump', '--verbose', '-o', dump_path,
'--host', host, '--port', str(port),
Expand All @@ -169,11 +170,11 @@ def __init__(self, host, port, db, collection, dump_path, less_time=None, query=
query = json_util.dumps(query)
cmd += ['--query', query]

super(MongoDumpProcess, self).__init__(cmd=cmd)
super(MongoDumpProcess, self).__init__(cmd=cmd, logerr_period=logerr_period)


class MongoRestoreProcess(MongoProcess):
def __init__(self, host, port, dump_path, db=None, collection=None):
def __init__(self, host, port, dump_path, db=None, collection=None, logerr_period=0):
cmd = [
'mongorestore', '--verbose', '--host', host, '--port', str(port),
]
Expand All @@ -182,7 +183,7 @@ def __init__(self, host, port, dump_path, db=None, collection=None):
if collection is not None:
cmd += [ '--collection', collection]
cmd += [dump_path]
super(MongoRestoreProcess, self).__init__(cmd=cmd)
super(MongoRestoreProcess, self).__init__(cmd=cmd, logerr_period=logerr_period)


class Replicator(object):
Expand All @@ -195,6 +196,7 @@ def __init__(self):
if use_connection_string:
use_daemon = True
rospy.loginfo('Using connection string: %s', connection_string)
self.logerr_period = rospy.get_param('~logerr_period', 0)

self.connection_string = ''

Expand Down Expand Up @@ -315,7 +317,7 @@ def do_restore(self, extras, db='message_store'):
except pymongo.errors.ServerSelectionTimeoutError:
rospy.logerr('Failed to connect to the extra server {}'.format(extra))
continue
self.restore_process = MongoRestoreProcess(host=host, port=port, dump_path=self.dump_path)
self.restore_process = MongoRestoreProcess(host=host, port=port, dump_path=self.dump_path, logerr_period=self.logerr_period)
self.restore_process.start()
self.restore_process.wait()
self.restore_process = None
Expand Down Expand Up @@ -343,7 +345,8 @@ def do_dump(self, collection, master, less_time_time=None, db='message_store', q

self.dump_process = MongoDumpProcess(host=host, port=port, db=db, collection=collection,
dump_path=self.dump_path,
less_time=less_time_time, query=query)
less_time=less_time_time, query=query,
logerr_period=self.logerr_period)
self.dump_process.start()
self.dump_process.wait()
self.dump_process = None
Expand Down