diff --git a/openedx/core/djangoapps/content/block_structure/store.py b/openedx/core/djangoapps/content/block_structure/store.py index 04a0520a0c..409dae988e 100644 --- a/openedx/core/djangoapps/content/block_structure/store.py +++ b/openedx/core/djangoapps/content/block_structure/store.py @@ -16,6 +16,8 @@ from .factory import BlockStructureFactory from .models import BlockStructureModel from .transformer_registry import TransformerRegistry +from edx_django_utils import monitoring + logger = getLogger(__name__) # pylint: disable=C0103 @@ -135,10 +137,15 @@ class BlockStructureStore: """ cache_key = self._encode_root_cache_key(bs_model) total_bytes_in_one_mb = 1024 * 1024 - if len(serialized_data) < total_bytes_in_one_mb * 2: + data_size_in_mbs = round(len(serialized_data) / total_bytes_in_one_mb, 2) + if data_size_in_mbs < total_bytes_in_one_mb * 2: self._cache.set(cache_key, serialized_data, timeout=config.cache_timeout_in_seconds()) - data_size_in_mbs = round(len(serialized_data) / total_bytes_in_one_mb, 2) - logger.info("BlockStructure: Added to cache; %s, size: %dMB", bs_model, data_size_in_mbs) + logger.info("BlockStructure: Added to cache; %s, size: %.2fMB", bs_model, data_size_in_mbs) + else: + # .. custom_attribute_name: blockstorestructure_size_in_mbs + # .. custom_attribute_description: contains the data chunk size in MBs. The size on which + # the memcached client failed to store value in cache. + monitoring.set_custom_attribute('blockstorestructure_size_in_mbs', data_size_in_mbs) def _get_from_cache(self, bs_model): """