From 31f29763fd0f13750dd1cbd618952ccb5a4481f7 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 13 Aug 2015 16:31:33 -0400 Subject: [PATCH 1/3] Increase sample rate when measuring DjangoXBlockUserStateClient metrics --- lms/djangoapps/courseware/user_state_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py index bcc65b6d05..1038c4a8f8 100644 --- a/lms/djangoapps/courseware/user_state_client.py +++ b/lms/djangoapps/courseware/user_state_client.py @@ -40,7 +40,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient): """ # Use this sample rate for DataDog events. - API_DATADOG_SAMPLE_RATE = 0.01 + API_DATADOG_SAMPLE_RATE = 0.1 class ServiceUnavailable(XBlockUserStateClient.ServiceUnavailable): """ From 448356ed3ec66249d0ed6d89a83f56488d92c5c1 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 13 Aug 2015 16:32:05 -0400 Subject: [PATCH 2/3] Log the size of block state and the number of blocks missing state when retrieved with get_many --- lms/djangoapps/courseware/user_state_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py index 1038c4a8f8..790d110077 100644 --- a/lms/djangoapps/courseware/user_state_client.py +++ b/lms/djangoapps/courseware/user_state_client.py @@ -139,11 +139,14 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient): modules = self._get_student_modules(username, block_keys) for module, usage_key in modules: if module.state is None: + self._ddog_increment(evt_time, 'get_many.empty_state') continue state = json.loads(module.state) state_length += len(module.state) + self._ddog_histogram(evt_time, 'get_many.block_size', len(module.state)) + # If the state is the empty dict, then it has been deleted, and so # conformant UserStateClients should treat it as if it doesn't exist. if state == {}: @@ -161,7 +164,6 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient): # The rest of this method exists only to submit DataDog events. # Remove it once we're no longer interested in the data. self._ddog_histogram(evt_time, 'get_many.blks_out', block_count) - self._ddog_histogram(evt_time, 'get_many.blks_size', state_length) def set_many(self, username, block_keys_to_state, scope=Scope.user_state): """ From 3f9027d05e9b29a299964a62e4699ae99907ff3d Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 13 Aug 2015 16:32:24 -0400 Subject: [PATCH 3/3] Log delete_many calls and metrics --- lms/djangoapps/courseware/user_state_client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py index 790d110077..5827f658e5 100644 --- a/lms/djangoapps/courseware/user_state_client.py +++ b/lms/djangoapps/courseware/user_state_client.py @@ -245,13 +245,21 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient): Arguments: username: The name of the user whose state should be deleted - block_key (UsageKey): The UsageKey identifying which xblock state to delete. + block_keys (list): The UsageKey identifying which xblock state to delete. scope (Scope): The scope to delete data from fields: A list of fields to delete. If None, delete all stored fields. """ if scope != Scope.user_state: raise ValueError("Only Scope.user_state is supported") + evt_time = time() + if fields is None: + self._ddog_increment(evt_time, 'delete_many.empty_state') + else: + self._ddog_histogram(evt_time, 'delete_many.field_count', len(fields)) + + self._ddog_histogram(evt_time, 'delete_many.block_count', len(block_keys)) + student_modules = self._get_student_modules(username, block_keys) for student_module, _ in student_modules: if fields is None: