Skip to content

Figures sites and pipeline fixes - #314

Merged
johnbaldwin merged 3 commits into
masterfrom
john/0.4-pipeline-and-site-fixes
Dec 29, 2020
Merged

johnbaldwin merged 3 commits into
masterfrom
john/0.4-pipeline-and-site-fixes

Conversation

@johnbaldwin

Copy link
Copy Markdown
Contributor

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

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 melvinsoft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 OmarIthawi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this change mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this

@@ -345,10 +345,13 @@ def load(self, date_for=None, force_update=False, **_kwargs):
course daily metrics model instance
"""
if not date_for:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so date_for defaults to "yesterday"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines -98 to -101
else:
# Log this for troubleshooting
error_data = dict(
msg=('Unable to create or retrieve enrollment metrics ' +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the noisy logs removal, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +166 to +169
if not student_modules:
student_modules = student_modules_for_course_enrollment(
site=site,
course_enrollment=course_enrollment).order_by('-modified')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the change here? it sounds like mostly just refactoring and renaming.

@johnbaldwin johnbaldwin Dec 23, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

@OmarIthawi

Copy link
Copy Markdown
Contributor

Sorry for the delay @johnbaldwin. you owe me another review here. I'll do it soon.

@OmarIthawi OmarIthawi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@johnbaldwin

johnbaldwin commented Dec 29, 2020 •

Copy link
Copy Markdown
Contributor Author

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

@johnbaldwin
johnbaldwin merged commit ed94255 into master Dec 29, 2020
@johnbaldwin
johnbaldwin deleted the john/0.4-pipeline-and-site-fixes branch December 29, 2020 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants