Repository navigation
Figures sites and pipeline fixes - #314
Conversation
Fixed Figures sites - Some functions would not work in standalone Fixed date/datetime type in site and course daily metrics pipeline loaders. The problem was that the loaders would filter for existing records using a datetime where the 'date_for' field is a date field. Using a datetime caused the date to check the previous day in the queryset filter Fixed logic in the enrollment metrics pipeline. The enrollment metrics pipeline code was causing massive noise in the logs. The key change is in working with the StudentModule records. Records are filtered now per enrollment instead of per course and if there are no StudentModule records then the call returns back to the caller without running a query for the LearnerCourseGradeMetrics records for th enrollment Reworked the logging in enrollment_metrics so that if an LCGM record is found for the enrollment without any StudentModule records, then a warning is logged with the specific prefix 'FIGURES:PIPELINE:LCGM' and the LCGM record id as well as the user id and course id. This will help with easily grepping the log files to aid in safe cleanup of LCGM records without deleting history. While reworking the logging, also changed code to only log to the Python logger instead of Figures 'PipelineError' model as we overhaul logging Added some light test coverage for the changes, but still needs more
melvinsoft
left a comment
There was a problem hiding this comment.
@johnbaldwin I cannot do an extensive review now, but since Omar is out, I don't want to block you for testing this on staging, so I'm approving it. Thanks!
OmarIthawi
left a comment
There was a problem hiding this comment.
I've had a first pass on this. It's indeed complicated and needs another review. I've wrote some notes and will review later today.
| # Figures works in UTC | ||
| date_for = prev_day( | ||
| datetime.datetime.utcnow().replace(tzinfo=utc).date()) | ||
| datetime.datetime.utcnow().replace(tzinfo=utc)) |
There was a problem hiding this comment.
what does this change mean?
There was a problem hiding this comment.
Arg! I need to fix this. I first had removed the conditional after:
if not date_for:
# Figures works in UTC
date_for = prev_day(
datetime.datetime.utcnow().replace(tzinfo=utc))
else:
# Needs to be a date object and not a datetime
# TODO: Add timezone test coverage
date_for = as_date(date_for)
with this:
if not date_for:
# Figures works in UTC
date_for = prev_day(
datetime.datetime.utcnow().replace(tzinfo=utc))
# Needs to be a date object and not a datetime
# TODO: Add timezone test coverage
date_for = as_date(date_for)
Which makes sure date_for is a date object regardless. Will fix this now
| @@ -345,10 +345,13 @@ def load(self, date_for=None, force_update=False, **_kwargs): | |||
| course daily metrics model instance | |||
| """ | |||
| if not date_for: | |||
There was a problem hiding this comment.
so date_for defaults to "yesterday"?
There was a problem hiding this comment.
Yes, because we need to make sure the data collected for a calendar date are complete, so when it is "today" we collect for "yesterday"
I'm strongly thinking of mandating that the course_daily_metrics and site_daily_metrics collectors take in a date_for parameter that the caller assigns and doesn't automatically assign to 'yesterday' if the date_for is not provided. This puts a bit more work on the caller, but might remove some confusion. But it might not, so I need to think about it
| else: | ||
| # Log this for troubleshooting | ||
| error_data = dict( | ||
| msg=('Unable to create or retrieve enrollment metrics ' + |
There was a problem hiding this comment.
this is the noisy logs removal, correct?
There was a problem hiding this comment.
Yes, these messages were not really adding value by including in figures.models.PipelineError. My plan is to rework figures.models.PipelineError to log only at the site and course levels and aggregate errors at the learner level so the pipeline error records show problems at a higher level which shows then that we need to run diagnostics on a particular course. The diagnostics can then drill down to specific learner level for issues
| if not student_modules: | ||
| student_modules = student_modules_for_course_enrollment( | ||
| site=site, | ||
| course_enrollment=course_enrollment).order_by('-modified') |
There was a problem hiding this comment.
what's the change here? it sounds like mostly just refactoring and renaming.
There was a problem hiding this comment.
This is part of deciding which approach to take, so I implemented both
A. The caller has to provide the student module (SM) records for the learner. This is more efficient because the caller function only needs to call collect_metrics_for_enrollment. However, collect_metrics_for_enrollment must have the correct filter called (query only for the SM for this specific enrollment and reverse ordered by the modified date of the SM). It's a bit brittle
B. The caller does the check if any SM records for the enrollment, then does not pass this queryset to collect_metrics_for_enrollment. This is less efficient because two calls to query SM are made, but only when there are SM records
At the core, if there are no SM records it means that the learner has not started any course activity = no progress made ever in the course, so we skip creating an LCGM record because it will contain no data
What I really need to do revisit the whole logic and streamline it. RIGHT NOW, the SM record is only for checking if the enrollment has any progress activity since the last time an LCGM record was written. We don't actually use the SM for data.
This also gets to the core of how progress is calculated at the course level. Is it supposed to track all learners or only those who have actually started work on the course?
| ) | ||
| sm = student_modules_for_course_enrollment( | ||
| site=site, | ||
| course_enrollment=ce).order_by('-modified') |
There was a problem hiding this comment.
I need to decide if it makes sense to filter out any SM records created after 'date_for'. At this point in the evolution of this code, SM is there only to check if there's been learner activity since the last LCGM record collected
Refactored functionality - pipeline rule for date handling * Added function, 'pipeline_date_for_rule' in the new module: figures.pipeline.helpers * This refactoring extracts 'date for' logic out of the daily metrics modules into a common helper module and function. Read the docs in `figures.pipeline.helpers`. The logic isn't hard but a bit brittle as this refactoring addresses a bug where using a datetime to query the daily metrics models' 'date_for' field caused the previous day's record to be retrieved. Because getting the date handling correct is critical to accurate metrics, we've given it some special attention here by pulling the duplicate code out of both the site and course daily metrics data loaders into a common library function * Added code coverage for the new pipeline helper function. Even though the functionality is pretty mundane, it is a key piece to pulling correct data, so the tests should cover testing correctness and type handling
| datetime.datetime.utcnow().replace(tzinfo=utc).date()) | ||
| else: | ||
| date_for = as_datetime(date_for).replace(tzinfo=utc) | ||
| date_for = pipeline_date_for_rule(date_for) |
There was a problem hiding this comment.
@OmarIthawi I pulled the common code out of course_daily_metrics and site_daily_metrics into a new module function, figures.pipeline.helpers.pipeline_date_for_rule. Yeah, so the name is kinda crappy, but I didn't want to spend a bunch of time on it. It at least isolates this logic rom the daily metrics loaders
|
Sorry for the delay @johnbaldwin. you owe me another review here. I'll do it soon. |
OmarIthawi
left a comment
There was a problem hiding this comment.
I haven't spotted anything unusual. So it should be good to go.
I still wish that someday I could give faster and better reviews but I don't fully understand Figures yet.
@OmarIthawi Very understandable. I need to get some architecture docs out on Figures. That would help. I'm trying to keep the complexity down, but forces such as architectural constraints coupled with schedule constraints makes that a bit of a challenge |
Fixed Figures sites - Some functions would not work in standalone
Fixed date/datetime type in site and course daily metrics pipeline
loaders. The problem was that the loaders would filter for existing
records using a datetime where the 'date_for' field is a date field.
Using a datetime caused the date to check the previous day in the
queryset filter
Fixed logic in the enrollment metrics pipeline. The enrollment metrics
pipeline code was causing massive noise in the logs. The key change is
in working with the StudentModule records. Records are filtered now per
enrollment instead of per course and if there are no StudentModule
records then the call returns back to the caller without running a query
for the LearnerCourseGradeMetrics records for th enrollment
Reworked the logging in enrollment_metrics so that if an LCGM record is
found for the enrollment without any StudentModule records, then a
warning is logged with the specific prefix 'FIGURES:PIPELINE:LCGM' and
the LCGM record id as well as the user id and course id. This will help
with easily grepping the log files to aid in safe cleanup of LCGM
records without deleting history.
While reworking the logging, also changed code to only log to the Python
logger instead of Figures 'PipelineError' model as we overhaul logging
Added some light test coverage for the changes, but still needs more