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

[2018.3] Fix to utils/dicttrim.py to honor max_event_size with nested dictionaries #50382

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions salt/utils/dicttrim.py
Expand Up @@ -6,6 +6,22 @@
import salt.payload


def _trim_dict_in_dict(data, max_val_size, replace_with):
'''
Takes a dictionary, max_val_size and replace_with
and recursively loops through and replaces any values
that are greater than max_val_size.
'''
for key in data:
if isinstance(data[key], dict):
_trim_dict_in_dict(data[key],
max_val_size,
replace_with)
else:
if sys.getsizeof(data[key]) > max_val_size:
data[key] = replace_with


def trim_dict(
data,
max_dict_bytes,
Expand Down Expand Up @@ -63,8 +79,13 @@ def trim_dict(
max_val_size = float(max_dict_bytes * (percent / 100))
try:
for key in data:
if sys.getsizeof(data[key]) > max_val_size:
data[key] = replace_with
if isinstance(data[key], dict):
_trim_dict_in_dict(data[key],
max_val_size,
replace_with)
else:
if sys.getsizeof(data[key]) > max_val_size:
data[key] = replace_with
percent = percent - stepper_size
max_val_size = float(max_dict_bytes * (percent / 100))
if use_bin_type:
Expand Down