-
Notifications
You must be signed in to change notification settings - Fork 167
LG-15560: Enhance A/B tests to support configurable max participants #11853
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e64827
Add persistence option for A/B tests
aduth 933da3e
LG-15560: Enhance A/B tests to support configurable max participants
aduth 64ca25c
Refactor A/B test report to receive AbTest instance
aduth 71638b0
Include participants status in A/B test report mailer
aduth f11c221
Fix indentation on multi-line param
aduth 5cbe550
Delete outdated A/B assignments in batches with delete_all
aduth 029a812
Add YARDoc field documentation for new options
aduth 6181ebe
Replace automated deletion job with Rake task
aduth 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
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AbTestAssignment < ApplicationRecord | ||
| class << self | ||
| def bucket(**) | ||
| find_by(**)&.bucket&.to_sym | ||
| end | ||
| end | ||
| end | ||
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
10 changes: 10 additions & 0 deletions
10
db/primary_migrate/20250207144037_create_ab_test_assignments.rb
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,10 @@ | ||
| class CreateAbTestAssignments < ActiveRecord::Migration[8.0] | ||
| def change | ||
| create_table :ab_test_assignments do |t| | ||
| t.string :experiment, null: false, comment: 'sensitive=false' | ||
| t.string :discriminator, null: false, comment: 'sensitive=false' | ||
| t.string :bucket, null: false, comment: 'sensitive=false' | ||
| t.index [:experiment, :discriminator], unique: true, using: :btree | ||
| end | ||
| end | ||
| end |
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
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,42 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| namespace :ab_tests do | ||
| desc 'Deletes persisted A/B test assignments for outdated tests' | ||
| task :delete_outdated, [:confirm] => :environment do |_t, args| | ||
| args.with_defaults(confirm: false) | ||
|
|
||
| configured_experiments = AbTests.all.values.map(&:experiment) | ||
| outdated_assignments = AbTestAssignment.where.not(experiment: configured_experiments) | ||
|
|
||
| names = outdated_assignments.distinct.pluck(:experiment).sort | ||
| if names.empty? | ||
| warn 'No outdated test assignments to delete!' | ||
| next | ||
| end | ||
|
|
||
| puts 'Found outdated test assignments with experiment names:' | ||
| names.each { |name| puts " - #{name}" } | ||
| puts '' | ||
|
|
||
| if args.confirm | ||
| deleted = log_to_stdout { outdated_assignments.in_batches.delete_all } | ||
| puts "\nSuccessfully deleted #{deleted} #{'record'.pluralize(deleted)}." | ||
| else | ||
| puts <<~STR | ||
| Re-run command with `confirm` arg to delete: | ||
|
|
||
| rake "ab_tests:delete_outdated[confirm]" | ||
|
|
||
| STR | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def log_to_stdout | ||
| original_logger = ActiveRecord::Base.logger | ||
| stdout_logger = Logger.new(STDOUT) | ||
| ActiveRecord::Base.logger = ActiveSupport::BroadcastLogger.new(original_logger, stdout_logger) | ||
| yield | ||
| ensure | ||
| ActiveRecord::Base.logger = original_logger | ||
| end |
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,9 @@ | ||
| FactoryBot.define do | ||
| factory :ab_test_assignment do | ||
| ab_test = AbTests.all.values.sample | ||
|
|
||
| experiment { ab_test.experiment } | ||
| discriminator { Random.uuid } | ||
| bucket { [*ab_test.buckets.keys, ab_test.default_bucket].sample } | ||
| end | ||
| end |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.