feat: route Insights video APIs through Snowflake - #214
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
🟡 Changes recommended
There are correctness issues that can cause failures in Snowflake row mapping (NULL integer handling) and in test cleanup logic (thread-local DB hint fallback can point to a non-existent DB alias).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Migrates the Insights video engagement endpoints to optionally read from Snowflake (behind the global insights_snowflake_enabled Waffle flag) while preserving existing response shapes and adding an X-Insights-Data-Source response header indicating Aurora vs Snowflake.
Changes:
- Added Snowflake query + mapping + service layers for course videos and video timeline endpoints.
- Updated existing course/videos and video/timeline views to route through Snowflake only when the global flag is enabled (otherwise defaulting to Aurora).
- Added unit tests covering query construction, mapping, service orchestration, data-source headers, and empty-result 404 behavior.
File summaries
| File | Description |
|---|---|
| analytics_data_api/v0/views/videos.py | Routes videos/{video_id}/timeline/ through Snowflake when enabled and sets data-source response header. |
| analytics_data_api/v0/views/courses.py | Routes courses/{course_id}/videos/ through Snowflake when enabled and sets data-source response header. |
| analytics_data_api/v0/tests/views/test_videos.py | Adds view-level tests for Snowflake/Aurora routing, headers, and empty-result 404 behavior. |
| analytics_data_api/v0/tests/views/test_courses.py | Adds view-level tests for Snowflake/Aurora routing, headers, and empty-result 404 behavior. |
| analytics_data_api/tests/test_insights_snowflake.py | Adds tests for Snowflake video query SQL, mappers, and service orchestration. |
| analytics_data_api/insights_snowflake/service.py | Adds service functions to orchestrate video queries and mapping. |
| analytics_data_api/insights_snowflake/queries/videos.py | Introduces Snowflake SQL query helpers for course videos and video timeline data. |
| analytics_data_api/insights_snowflake/mappers/videos.py | Introduces Snowflake row-to-API-shape mappers for video and timeline data. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| value = _row_value(row, name) | ||
| if name in INTEGER_FIELDS: | ||
| return int(value) | ||
| return value |
| def tearDown(self): | ||
| thread_data.analyticsapi_database = getattr(settings, 'ANALYTICS_DATABASE', 'analytics') | ||
| super().tearDown() |
| def tearDown(self): | ||
| thread_data.analyticsapi_database = getattr(settings, 'ANALYTICS_DATABASE', 'analytics') | ||
| super().tearDown() |
Description
Migrates the Insights video engagement APIs to support Snowflake reads behind the global
insights_snowflake_enabledWaffle flag.This covers:
GET /api/v1/courses/{course_id}/videos/GET /api/v1/videos/{video_id}/timeline/Aurora remains the default path when the flag is off.
Changes
VIDEOandVIDEO_TIMELINE.