Skip to content

feat(experimentation): sync warehouse connection environment keys to ingestion redis#7588

Merged
gagantrivedi merged 5 commits into
mainfrom
feature/redis-warehouse-sync
May 25, 2026
Merged

feat(experimentation): sync warehouse connection environment keys to ingestion redis#7588
gagantrivedi merged 5 commits into
mainfrom
feature/redis-warehouse-sync

Conversation

@gagantrivedi
Copy link
Copy Markdown
Member

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to experimentation warehouse ingestion sync.

Adds AFTER_CREATE / AFTER_DELETE hooks on WarehouseConnection that enqueue background tasks to publish the environment's API key to the ingestion server's Redis Cluster under the experimentation:environment_keys: namespace:

  • SET experimentation:environment_keys:<env-api-key> "" on connection create
  • DEL experimentation:environment_keys:<env-api-key> on connection delete

New pieces:

  • experimentation/ingestion_sync_service.py — owns the Redis Cluster client (lazy, from_url with socket_timeout=1, socket_keepalive=True) and the key-prefix constant. Logs ingestion_sync.environment_key.{set,deleted,failed} via structlog; swallows RedisError so a Redis outage cannot break Django requests.
  • experimentation/tasks.pyadd_environment_key_to_ingestion / delete_environment_key_from_ingestion task handlers.
  • INGESTION_REDIS_URL setting (empty default).

How did you test this code?

  • New unit tests:
    • tests/unit/experimentation/test_ingestion_sync_service.py — set/delete write the expected key, RedisError is logged and swallowed.
    • tests/unit/experimentation/test_tasks.py — task handlers delegate to the service.
    • tests/unit/experimentation/test_models.py — hooks enqueue the right task with environment.api_key.
  • Autouse fixture in tests/unit/experimentation/conftest.py mocks _get_client so no test touches real Redis.
  • Ran pytest tests/unit/experimentation/ — 43/43 pass.
  • Ran mypy on the touched files — clean.

…ingestion redis

Adds AFTER_CREATE / AFTER_DELETE hooks on WarehouseConnection that enqueue
tasks to set/delete the environment's API key in the ingestion server's
Redis Cluster under the `experimentation:environment_keys:` namespace.
@gagantrivedi gagantrivedi requested a review from a team as a code owner May 25, 2026 05:00
@gagantrivedi gagantrivedi requested review from emyller and removed request for a team May 25, 2026 05:00
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 25, 2026 8:02am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ignored Ignored Preview May 25, 2026 8:02am
flagsmith-frontend-staging Ignored Ignored Preview May 25, 2026 8:02am

Request Review

@github-actions github-actions Bot added api Issue related to the REST API feature New feature or request labels May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7588 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-7588 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7588 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-7588 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7588 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7588 Finished ✅ Results

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a synchronization mechanism between warehouse connections and an event ingestion Redis cluster. It introduces a new service for Redis communication, background tasks for asynchronous processing, and lifecycle hooks on the WarehouseConnection model. Feedback highlights a potential ValueError when the Redis URL is unconfigured and a logic error in the deletion hook where the environment key might be prematurely removed if multiple connections exist for the same environment.

Comment thread api/experimentation/ingestion_sync_service.py Outdated
Comment thread api/experimentation/ingestion_sync_service.py Outdated
Comment thread api/experimentation/models.py
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.51%. Comparing base (2be8504) to head (6553639).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7588      +/-   ##
==========================================
+ Coverage   98.49%   98.51%   +0.01%     
==========================================
  Files        1417     1436      +19     
  Lines       53749    54363     +614     
==========================================
+ Hits        52939    53553     +614     
  Misses        810      810              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.6 seconds
commit  c337da4
info  🔄 Run: #16957 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  41 seconds
commit  c337da4
info  🔄 Run: #16957 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 9 seconds
commit  c337da4
info  🔄 Run: #16957 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

failed  1 failed
passed  1 passed

Details

stats  2 tests across 2 suites
duration  26.9 seconds
commit  c337da4
info  📦 Artifacts: View test results and HTML report
🔄 Run: #16957 (attempt 1)

Failed tests

firefox › tests/project-permission-test.pw.ts › Project Permission Tests › Project-level permissions control access to features, environments, audit logs, and segments @enterprise

### Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.8 seconds
commit  d2e5553
info  🔄 Run: #16958 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.6 seconds
commit  d2e5553
info  🔄 Run: #16958 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  33 seconds
commit  d2e5553
info  🔄 Run: #16958 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  38.7 seconds
commit  d2e5553
info  🔄 Run: #16958 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38 seconds
commit  946f39d
info  🔄 Run: #16959 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  42 seconds
commit  946f39d
info  🔄 Run: #16959 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  42.5 seconds
commit  946f39d
info  🔄 Run: #16959 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  48 seconds
commit  946f39d
info  🔄 Run: #16959 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  31.9 seconds
commit  7acfc73
info  🔄 Run: #16960 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.2 seconds
commit  7acfc73
info  🔄 Run: #16960 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  6.8 seconds
commit  7acfc73
info  🔄 Run: #16960 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  48.3 seconds
commit  7acfc73
info  🔄 Run: #16960 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  39 seconds
commit  6553639
info  🔄 Run: #16968 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  43.2 seconds
commit  6553639
info  🔄 Run: #16968 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  37.8 seconds
commit  6553639
info  🔄 Run: #16968 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.3 seconds
commit  6553639
info  🔄 Run: #16968 (attempt 1)

…atalogue

Drop the try/except RedisError in ingestion_sync_service — failures should
surface to the task processor rather than being swallowed. Regenerate the
events catalogue to include the new ingestion_sync events.
@gagantrivedi gagantrivedi requested a review from a team as a code owner May 25, 2026 05:08
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

Visual Regression

19 screenshots compared. See report for details.
View full report

Push the autouse mock down from _get_client to RedisCluster.from_url so the
real _get_client body runs in tests. Add a direct test that asserts the
socket timeout / keepalive kwargs we pass to RedisCluster.from_url.
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels May 25, 2026
Point both admin-api and task-processor task definitions at the existing
serverless-redis-cache cluster (rediss://...:6379) in staging and production
so the experimentation ingestion sync hooks can publish environment keys.
@gagantrivedi gagantrivedi requested a review from a team as a code owner May 25, 2026 05:31
@github-actions github-actions Bot added docs Documentation updates infrastructure and removed feature New feature or request infrastructure labels May 25, 2026
@github-actions github-actions Bot added feature New feature or request and removed docs Documentation updates labels May 25, 2026
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for emyller May 25, 2026 05:48
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

NIT: 2 additions in structlogs and I think we should merge #7582 before this one to rebase with the migration and constraint

Comment thread api/experimentation/ingestion_sync_service.py Outdated
Comment thread api/experimentation/ingestion_sync_service.py Outdated
Zaimwa9
Zaimwa9 previously approved these changes May 25, 2026
Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

I let you decide on the log

…rvice

The set/delete success logs added no operational value over what the task
processor already records. Regenerate the events catalogue to drop the
ingestion_sync.environment_key.{set,deleted} entries.
@gagantrivedi gagantrivedi merged commit 7d3b541 into main May 25, 2026
35 of 38 checks passed
@gagantrivedi gagantrivedi deleted the feature/redis-warehouse-sync branch May 25, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants