Skip to content

Commit b598fd5

Browse files
committed
More comments in Mongo queries when tracing I/Os
1 parent d7c0f1f commit b598fd5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

mrq/monkey.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .context import get_current_job
1+
from .context import get_current_job, get_current_worker
22
import time
33
import random
44
import re
@@ -46,6 +46,9 @@ def gen_monkey_patch(base_object, method):
4646
def mrq_monkey_patched(self, *args, **kwargs):
4747

4848
if config["trace_io"]:
49+
comment = "mrq"
50+
51+
worker = get_current_worker()
4952
job = get_current_job()
5053
if job:
5154
job.set_current_io({
@@ -56,13 +59,16 @@ def mrq_monkey_patched(self, *args, **kwargs):
5659
# Perf issue? All MongoDB data will get jsonified!
5760
# "data": json.dumps(args)[0:300]
5861
})
59-
60-
# Tag potentially expensive queries with their job id for easier debugging
61-
if method in ["find", "find_and_modify", "count", "update_many", "update", "delete_many"]:
62-
if len(args) > 0 and type(args[0]) == dict and "$comment" not in args[0]:
63-
query = copy.copy(args[0])
64-
query["$comment"] = {"job": job.id}
65-
args = (query, ) + args[1:]
62+
comment = {"job": job.id}
63+
elif worker:
64+
comment = {"worker": worker.id}
65+
66+
# Tag potentially expensive queries with their job id for easier debugging
67+
if method in ["find", "find_and_modify", "count", "update_many", "update", "delete_many"]:
68+
if len(args) > 0 and isinstance(args[0], dict) and "$comment" not in args[0]:
69+
query = copy.copy(args[0])
70+
query["$comment"] = comment
71+
args = (query, ) + args[1:]
6672

6773
if config["print_mongodb"]:
6874
if self.full_name in config.get("print_mongodb_hidden_collections", []):

0 commit comments

Comments
 (0)