Skip to content

Commit ada63db

Browse files
russellbvishvananda
authored andcommitted
Improve performance of safe_log().
This patch addresses a minor performance regression in a recent change to this function. This change ensures that the deep copy is only done if we really need to. Previously, the deep copy was being done for all messages that included a 'method', not just messages with a method that contain an argument to be sanitized. Change-Id: I190c5963ecaf70b0aea4e12a2fdc19deb5c1fea2
1 parent 785518d commit ada63db

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

nova/rpc/common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ def consume_in_thread(self):
127127

128128
def _safe_log(log_func, msg, msg_data):
129129
"""Sanitizes the msg_data field before logging."""
130-
has_method = 'method' in msg_data
130+
SANITIZE = {
131+
'set_admin_password': ('new_pass',),
132+
'run_instance': ('admin_password',),
133+
}
134+
135+
has_method = 'method' in msg_data and msg_data['method'] in SANITIZE
131136
has_context_token = '_context_auth_token' in msg_data
132137
has_token = 'auth_token' in msg_data
133138

@@ -137,10 +142,6 @@ def _safe_log(log_func, msg, msg_data):
137142
msg_data = copy.deepcopy(msg_data)
138143

139144
if has_method:
140-
SANITIZE = {
141-
'set_admin_password': ('new_pass',),
142-
'run_instance': ('admin_password',),
143-
}
144145
method = msg_data['method']
145146
if method in SANITIZE:
146147
args_to_sanitize = SANITIZE[method]

0 commit comments

Comments
 (0)