-
Notifications
You must be signed in to change notification settings - Fork 33
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
Introduce Split Registry Endpoint Accepting a Timestamp #133
Merged
jmileham
merged 9 commits into
Betterment:master
from
phantomphildius:aburgel+freeman/split-registry-timestamp
Jan 9, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a83c1cd
Initial pass
aburgel 0e45a36
add specs
phantomphildius 1e7a869
split_registry_snapshots
phantomphildius 490c4f7
v2/builds/:timestamp/split_registry
phantomphildius 65d0718
uses build_timestamp param
phantomphildius c584872
upgrade to v3
phantomphildius a0f2144
combine endpoint naming approaches
phantomphildius 0977312
remove references to timestamp and split registry snapshot
phantomphildius c3cc06c
final pr code review tweaks
phantomphildius 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 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 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,19 @@ | ||
class Api::V3::SplitRegistriesController < UnauthenticatedApiController | ||
include CorsSupport | ||
|
||
def show | ||
split_registry = SplitRegistry.new(as_of: split_registry_params[:build_timestamp]) | ||
|
||
if split_registry.valid? | ||
@split_registry = split_registry | ||
else | ||
render_errors split_registry | ||
end | ||
end | ||
|
||
private | ||
|
||
def split_registry_params | ||
params.permit(:build_timestamp) | ||
end | ||
end |
This file contains 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 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 @@ | ||
json.splits do | ||
@split_registry.splits.each do |split| | ||
json.set! split.name do | ||
json.weights split.registry | ||
json.feature_gate split.feature_gate? | ||
end | ||
end | ||
json.merge!({}) | ||
end | ||
json.(@split_registry, :experience_sampling_weight) |
This file contains 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 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
71 changes: 71 additions & 0 deletions
71
spec/controllers/api/v3/split_registries_controller_spec.rb
This file contains 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,71 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Api::V3::SplitRegistriesController, type: :controller do | ||
describe "#show" do | ||
before do | ||
allow(ENV).to receive(:fetch).with('EXPERIENCE_SAMPLING_WEIGHT', any_args).and_return(10) | ||
end | ||
|
||
it "includes sampling weight" do | ||
get :show, params: { build_timestamp: '2019-11-11T14:35:30Z' } | ||
|
||
expect(response).to have_http_status :ok | ||
expect(response_json['experience_sampling_weight']).to eq(10) | ||
end | ||
|
||
context "without active split on given timestamp" do | ||
let!(:split_1) { FactoryBot.create :split, name: "one", finished_at: Time.zone.parse('2019-11-13'), registry: { all: 100 } } | ||
|
||
it "returns empty with no active splits on the timestamp" do | ||
expect(split_1).to be_finished | ||
|
||
get :show, params: { build_timestamp: '2019-11-14T14:35:30Z' } | ||
|
||
expect(response).to have_http_status :ok | ||
expect(response_json['splits']).to eq({}) | ||
end | ||
end | ||
|
||
context "with splits active on given during timestamp" do | ||
let(:split_1) { FactoryBot.create :split, name: "one", finished_at: Time.zone.parse('2019-11-13'), registry: { all: 100 } } | ||
let(:split_2) { FactoryBot.create :split, name: "two", registry: { on: 50, off: 50 } } | ||
let(:split_3) { FactoryBot.create :split, name: "three_enabled", registry: { true: 99, false: 1 }, feature_gate: true } | ||
|
||
it "returns the full split registry of splits that are active during timestamp" do | ||
expect(split_1).to be_finished | ||
expect(split_2).not_to be_finished | ||
expect(split_3).not_to be_finished | ||
|
||
get :show, params: { build_timestamp: '2019-11-12T14:35:30Z' } | ||
|
||
expect(response).to have_http_status :ok | ||
expect(response_json['splits']).to eq( | ||
"one" => { | ||
"weights" => { "all" => 100 }, | ||
"feature_gate" => false | ||
}, | ||
"two" => { | ||
"weights" => { "on" => 50, "off" => 50 }, | ||
"feature_gate" => false | ||
}, | ||
"three_enabled" => { | ||
"weights" => { "true" => 99, "false" => 1 }, | ||
"feature_gate" => true | ||
} | ||
) | ||
end | ||
end | ||
|
||
it "returns unprocessable_entity if the timestamp url param is invalid" do | ||
get :show, params: { build_timestamp: "2019-04-16 10:38:08 -0400" } | ||
|
||
expect(response).to have_http_status :unprocessable_entity | ||
end | ||
|
||
it "returns unprocessable_entity if the timestamp url param is missing" do | ||
get :show, params: { build_timestamp: "" } | ||
|
||
expect(response).to have_http_status :unprocessable_entity | ||
end | ||
end | ||
end |
This file contains 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
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.
Hey so given the fact that if I merge and deploy this, the behavior will be on my head I looked a little deeper at the current behavior here. It's my understanding that the closest to zero behavior change for this call would be to pass
as_of: nil
, becauseinstance
used to meanSplit.for_presentation()
, andSplit.for_presentation()
would call Split.active() which would apply the conditionwhere(finished_at: nil)
. As it is this would end up applying the conditionwhere('splits.finished_at is null or splits.finished_at > ?', Time.zone.now)
, which is sort of spurious since we'd expect there to be no splits finished in the future, but clock error and all that jazz could make that a thing under some circumstances.Granted this would fail validation for
SplitRegistry
, if we actuallyvalid?
, which we're not doing here. Do we care? I guess not. Ok I'm on board with this. Basically this is behaviorally correct under all normal circumstances and hard to behaviorally regress, and the whole v2 api is soft deprecated at this point anyway so the blast radius of a regression here is low. Ok. I'mma merge this.