chore: add monitoring on collected_blockstructure_size (#36435)

Co-authored-by: M Umar Khan <umar.khan@A006-01609.local>
This commit is contained in:
Muhammad Umar Khan
2025-03-24 17:01:04 +05:00
committed by GitHub
parent de62ca70ac
commit 43493c79ca

View File

@@ -16,7 +16,7 @@ from django.core.cache import cache
from django.http import Http404, QueryDict
from django.urls import reverse
from django.utils.translation import gettext as _
from edx_django_utils.monitoring import function_trace
from edx_django_utils.monitoring import function_trace, set_custom_attribute
from fs.errors import ResourceNotFound
from opaque_keys.edx.keys import UsageKey
from path import Path as path
@@ -792,7 +792,16 @@ def get_assignments_grades(user, course_id, cache_timeout):
collected_block_structure = cache.get(cache_key)
if not collected_block_structure:
collected_block_structure = get_block_structure_manager(course_id).get_collected()
cache.set(cache_key, collected_block_structure, cache_timeout)
total_bytes_in_one_mb = 1024 * 1024
data_size_in_mbs = round(len(collected_block_structure) / total_bytes_in_one_mb, 2)
if data_size_in_mbs < total_bytes_in_one_mb * 2:
cache.set(cache_key, collected_block_structure, cache_timeout)
else:
# .. custom_attribute_name: collected_block_structure_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.
set_custom_attribute('collected_block_structure_size_in_mbs', data_size_in_mbs)
course_grade = CourseGradeFactory().read(user, collected_block_structure=collected_block_structure)