-
Notifications
You must be signed in to change notification settings - Fork 529
feat(experimentation): experiment exposures read and refresh endpoints #7754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gagantrivedi
wants to merge
4
commits into
main
Choose a base branch
from
feat/experiment-exposures-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7e3ed09
feat(experimentation): experiment exposures read and refresh endpoints
gagantrivedi c5b9474
feat(experimentation): throttle exposure refreshes and guard final rows
gagantrivedi 9d73293
refactor(experimentation): centralise exposures finality on the model
gagantrivedi c48b818
refactor(experimentation): drop task logging for now
gagantrivedi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
api/experimentation/migrations/0007_exposures_refresh_requested_at.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 5.2.14 on 2026-06-11 10:12 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("experimentation", "0006_experiment_exposures"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="experimentexposures", | ||
| name="refresh_requested_at", | ||
| field=models.DateTimeField(blank=True, null=True), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| from django.utils import timezone | ||
| from task_processor.decorators import register_task_handler | ||
|
|
||
| from experimentation import ingestion_sync_service | ||
| from experimentation.models import Experiment, ExperimentExposures | ||
| from experimentation.services import compute_exposures_summary | ||
|
|
||
|
|
||
| @register_task_handler() | ||
|
|
@@ -11,3 +14,32 @@ def add_environment_key_to_ingestion(environment_api_key: str) -> None: | |
| @register_task_handler() | ||
| def delete_environment_key_from_ingestion(environment_api_key: str) -> None: | ||
| ingestion_sync_service.delete_environment_key(environment_api_key) | ||
|
|
||
|
|
||
| @register_task_handler() | ||
| def compute_experiment_exposures(experiment_id: int) -> None: | ||
| experiment = ( | ||
| Experiment.objects.select_related("environment", "feature") | ||
| .filter(id=experiment_id) | ||
| .first() | ||
| ) | ||
| if experiment is None or not experiment.started_at: | ||
| return | ||
|
|
||
| exposures, _ = ExperimentExposures.objects.get_or_create(experiment=experiment) | ||
| if exposures.is_final: | ||
| return | ||
|
|
||
| as_of = experiment.ended_at or timezone.now() | ||
| try: | ||
| summary = compute_exposures_summary( | ||
| environment_key=experiment.environment.api_key, | ||
| feature_name=experiment.feature.name, | ||
| window_start=experiment.started_at, | ||
| window_end=as_of, | ||
| ) | ||
| except Exception: | ||
| exposures.record_failure() | ||
| return | ||
|
Comment on lines
+41
to
+43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we log an error here or within |
||
|
|
||
| exposures.record_refresh(summary, as_of) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also return true when an experiment has been running for more than 90 days and the first buckets data have expired ?