Skip to content

feat!: replace username and user_id with actor_id in the course_enrollment sink - #287

Open
felipemontoya wants to merge 2 commits into
openedx:mainfrom
eduNEXT:fmo/course_enrollment_actor_id
Open

felipemontoya wants to merge 2 commits into
openedx:mainfrom
eduNEXT:fmo/course_enrollment_actor_id

Conversation

@felipemontoya

@felipemontoya felipemontoya commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Implements the removal proposed in the DEPR openedx/tutor-contrib-aspects#1403.

  • CourseEnrollmentSerializer drops username and user_id and writes actor_id (the learner's xAPI actor id) instead. The sink wrote both whatever ASPECTS_ENABLE_PII said, and neither truncate-on-init nor user retirement cleared them.
  • With only actor_id, the table holds no PII, is written whether PII is on or off, and joins the xAPI tables and the other learner sinks.
  • actor_id is the last field because sink inserts are positional CSV.
  • Bulk dumps create missing xAPI actor ids in batches (create_xapi_actor_ids: one bulk_create and one batched external_id dump per batch) instead of one get_or_create per learner, which dominated cold dumps.

Breaking: apply the matching migration from openedx/tutor-contrib-aspects#1402 before upgrading. Against the old table, single-row dumps are dropped silently.

Backfill after the migration: dump_data_to_clickhouse --object course_enrollment --force

Merge checklist:
Check off if complete or not applicable:

  • Commit messages (and PR title, if squash merging) use the correct
    Conventional Commits type — they determine the
    release: fix: → patch, feat: → minor, ! / BREAKING CHANGE: → major
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Dec 1, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @felipemontoya!

This repository is currently maintained by @openedx/committers-analytics.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/platform_plugin_aspects
  utils.py
  src/platform_plugin_aspects/sinks
  base_sink.py
  course_enrollment_sink.py
  serializers.py
Project Total  

This report was generated by python-coverage-comment-action

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Dec 2, 2026
@bmtcril

bmtcril commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Couple of items:

  1. The README's ordering advice is misleading, rows drop in both orders.
    • I ran the sink's insert settings in clickhouse local
    • A row one column short (old plugin, new table) inserts 0 rows with no error. So does a row one column long (new plugin, old table).
    • "Apply the migration before upgrading" therefore only moves the loss window. Enrollments changed during the deploy are lost either way.
    • Ask: say so in the README, and call the --force backfill required.
  2. The backfill potentially gets much heavier on big sites.
    • get_actor_id adds 2 MySQL queries per enrollment row: the ExternalIdType lookup and the get_or_create. The sink's select_related("user") does not cover them.
    • Every learner without an xAPI id also gets a MySQL insert and a queued ExternalIdSink Celery task. The task is queued even with PII off, and exits as a no-op but should be rare.
    • The pathway and competency sinks use the same pattern, but enrollment is far larger. A site adopting Aspects with years of history hits this for every user. I'm not sure if we are caching this anywhere relevant, but we did have a plan for that at one point, which would eliminate a lot of this.
    • A cheap improvement would be to cache the ExternalIdType lookup, which is the same row every time. That halves the extra queries. Batching users per page with ExternalId.batch_get_or_create_user_ids would remove most of the rest.

felipemontoya and others added 2 commits December 4, 2026 10:34
Actor_id is added while user_id and username are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@felipemontoya
felipemontoya force-pushed the fmo/course_enrollment_actor_id branch from 3acd66c to 93149d9 Compare December 4, 2026 15:36
@felipemontoya felipemontoya changed the title feat!: add actor_id to the course_enrollment sink feat!: replace username and user_id with actor_id in the course_enrollment sink Dec 4, 2026
@felipemontoya

Copy link
Copy Markdown
Member Author

@bmtcril I updated this PR with the new implementation based on the Fast DEPR. After your review, I understood and became concerned about the cost this could have both in Celery and the pressure on the MySQL database if one were to dump a big enrollments table over to Clickhouse.

I built a batch getter for the actor Ids and bulk setter for creating the missing ones.

I ran stress tests over it and here is a summary:

Setup

  • Dev stack, so Celery ran sink tasks inline instead of queuing them.
  • 100,000 stress_* users with 299,292 enrollments across 71 courses.
    • 69,921 learners already had an xAPI id.
    • 30,079 learners had none, standing in for learners who never sent an xAPI event (the usual case in a first backfill).
  • Full dumps used dump_target_objects_to_clickhouse with force, batch size 1000 and sleep 0.

Full dump of about 300k enrollments

  • Warm, every learner already has an id (the nightly dump): 49.8 s
    • 302 SQL queries in total, so the per-batch prefetch works.
    • 26 s of it was the paginator's OFFSET queries and 3.7 s the ClickHouse inserts.
  • Cold with the old per-learner fallback: 1,300 s
    • About 1,250 s was spent creating ids one learner at a time.
    • It made 30,079 inserts, about 150k selects, 30,079 sink tasks and 30,079 one-row POSTs to ClickHouse.
    • It also left 30,461 new external_id parts. With parallel workers in production that could hit ClickHouse's "too many parts" error.
  • Cold with the batch path (create_xapi_actor_ids): 80.6 s, about 16× faster.
    • 300 inserts, 602 selects, 300 POSTs and no tasks.
    • 27 s was OFFSET paging and 18 s the external_id inserts.
  • In both cold runs, MySQL and ClickHouse matched row for row, no actor_id was empty, and every created id reached external_id exactly once.
  • Most of the remaining time comes from OFFSET paging, which every sink already does.

Two cold dumps at once over 10,000 new learners without an id

  • Each run took 81.5 s.
  • They created 4,068 and 5,932 ids. With the batch path, every created id reached external_id exactly once.
  • There was no IntegrityError, and 330,654 enrollments matched MySQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants