Skip to content

prepare 5.3.0 release #108

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 33 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f5092af
Remove @ashanbrown from codeowners
ashanbrown Jul 24, 2018
fd63b2b
log exception stacktraces at debug level
eli-darkly Aug 2, 2018
d4be186
re-add minimal unit test
eli-darkly Aug 2, 2018
d73d66c
log exceptions at error level
eli-darkly Aug 2, 2018
94c8485
Merge pull request #75 from launchdarkly/eb/ch19339/exception-logging
eli-darkly Aug 2, 2018
ca15234
add new version of all_flags that captures more metadata
eli-darkly Aug 17, 2018
ed19523
add tests for FeatureFlagsState
eli-darkly Aug 17, 2018
73f2d89
provide as_json method that returns a hash instead of just a string
eli-darkly Aug 20, 2018
ab896b1
state can be serialized with JSON.generate
eli-darkly Aug 21, 2018
00347c6
add $valid
eli-darkly Aug 21, 2018
bdac27e
add ability to filter for only client-side flags
eli-darkly Aug 21, 2018
748b59b
Merge pull request #76 from launchdarkly/eb/ch22308/all-flags-state
eli-darkly Aug 21, 2018
50b3aa5
Merge pull request #77 from launchdarkly/eb/ch12124/client-side-filter
eli-darkly Aug 21, 2018
cee4c18
implement evaluation with explanations
eli-darkly Aug 23, 2018
d2c2ab8
misc cleanup
eli-darkly Aug 23, 2018
64a00a1
misc cleanup, more error checking
eli-darkly Aug 23, 2018
46b642b
don't keep evaluating prerequisites if one fails
eli-darkly Aug 23, 2018
855c4e2
doc comment
eli-darkly Aug 23, 2018
a0f002f
rename variation to variation_index
eli-darkly Aug 23, 2018
4ec43db
comment
eli-darkly Aug 23, 2018
9622e01
more test coverage, convenience method
eli-darkly Aug 24, 2018
7a453b0
Merge branch 'master' of github.com:launchdarkly/ruby-client
eli-darkly Aug 27, 2018
88d217e
Merge branch 'master' of github.com:launchdarkly/ruby-client
eli-darkly Aug 27, 2018
084d9ea
fix event generation for a prerequisite that is off
eli-darkly Aug 29, 2018
02b5712
fix private
eli-darkly Aug 29, 2018
53e8408
Merge pull request #78 from launchdarkly/eb/ch19976/explanations
eli-darkly Aug 29, 2018
c78db15
Merge pull request #79 from launchdarkly/eb/ch22995/prereq-off
eli-darkly Aug 29, 2018
960bb89
Merge branch 'explanation'
eli-darkly Aug 30, 2018
39d6ad1
Merge branch 'master' of github.com:launchdarkly/ruby-client
eli-darkly Aug 30, 2018
8867638
add option to reduce front-end metadata for untracked flags
eli-darkly Oct 5, 2018
7ac39ba
Merge pull request #80 from launchdarkly/eb/ch24449/less-metadata
eli-darkly Oct 5, 2018
9ea43e0
fix logic for whether a flag is tracked in all_flags_state
eli-darkly Oct 8, 2018
cbbc2ea
Merge pull request #81 from launchdarkly/eb/ch24449/less-metadata-2
eli-darkly Oct 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/ldclient-rb/flags_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ def initialize(valid)
end

# Used internally to build the state map.
def add_flag(flag, value, variation, reason = nil)
def add_flag(flag, value, variation, reason = nil, details_only_if_tracked = false)
key = flag[:key]
@flag_values[key] = value
meta = { version: flag[:version], trackEvents: flag[:trackEvents] }
meta = {}
with_details = !details_only_if_tracked || flag[:trackEvents]
if !with_details && flag[:debugEventsUntilDate]
with_details = flag[:debugEventsUntilDate] > (Time.now.to_f * 1000).to_i
end
if with_details
meta[:version] = flag[:version]
meta[:reason] = reason if !reason.nil?
end
meta[:variation] = variation if !variation.nil?
meta[:trackEvents] = true if flag[:trackEvents]
meta[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
meta[:reason] = reason if !reason.nil?
@flag_metadata[key] = meta
end

Expand Down
10 changes: 8 additions & 2 deletions lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def all_flags(user)
# client-side SDK should be included in the state. By default, all flags are included.
# @option options [Boolean] :with_reasons (false) True if evaluation reasons should be included
# in the state (see `variation_detail`). By default, they are not included.
# @option options [Boolean] :details_only_for_tracked_flags (false) True if any flag metadata that is
# normally only used for event generation - such as flag versions and evaluation reasons - should be
# omitted for any flag that does not have event tracking or debugging turned on. This reduces the size
# of the JSON data if you are passing the flag state to the front end.
# @return [FeatureFlagsState] a FeatureFlagsState object which can be serialized to JSON
#
def all_flags_state(user, options={})
Expand All @@ -234,16 +238,18 @@ def all_flags_state(user, options={})
state = FeatureFlagsState.new(true)
client_only = options[:client_side_only] || false
with_reasons = options[:with_reasons] || false
details_only_if_tracked = options[:details_only_for_tracked_flags] || false
features.each do |k, f|
if client_only && !f[:clientSide]
next
end
begin
result = evaluate(f, user, @store, @config.logger)
state.add_flag(f, result.detail.value, result.detail.variation_index, with_reasons ? result.detail.reason : nil)
state.add_flag(f, result.detail.value, result.detail.variation_index, with_reasons ? result.detail.reason : nil,
details_only_if_tracked)
rescue => exn
Util.log_exception(@config.logger, "Error evaluating flag \"#{k}\" in all_flags_state", exn)
state.add_flag(f, nil, nil, with_reasons ? { kind: 'ERROR', errorKind: 'EXCEPTION' } : nil)
state.add_flag(f, nil, nil, with_reasons ? { kind: 'ERROR', errorKind: 'EXCEPTION' } : nil, details_only_if_tracked)
end
end

Expand Down
3 changes: 1 addition & 2 deletions spec/flags_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
'$flagsState' => {
'key1' => {
:variation => 0,
:version => 100,
:trackEvents => false
:version => 100
},
'key2' => {
:variation => 1,
Expand Down
41 changes: 39 additions & 2 deletions spec/ldclient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ def event_processor
'$flagsState' => {
'key1' => {
:variation => 0,
:version => 100,
:trackEvents => false
:version => 100
},
'key2' => {
:variation => 1,
Expand Down Expand Up @@ -263,6 +262,44 @@ def event_processor
expect(values).to eq({ 'client-side-1' => 'value1', 'client-side-2' => 'value2' })
end

it "can omit details for untracked flags" do
future_time = (Time.now.to_f * 1000).to_i + 100000
flag1 = { key: "key1", version: 100, offVariation: 0, variations: [ 'value1' ], trackEvents: false }
flag2 = { key: "key2", version: 200, offVariation: 1, variations: [ 'x', 'value2' ], trackEvents: true }
flag3 = { key: "key3", version: 300, offVariation: 1, variations: [ 'x', 'value3' ], debugEventsUntilDate: future_time }

config.feature_store.init({ LaunchDarkly::FEATURES => { 'key1' => flag1, 'key2' => flag2, 'key3' => flag3 } })

state = client.all_flags_state({ key: 'userkey' }, { details_only_for_tracked_flags: true })
expect(state.valid?).to be true

values = state.values_map
expect(values).to eq({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' })

result = state.as_json
expect(result).to eq({
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
'$flagsState' => {
'key1' => {
:variation => 0
},
'key2' => {
:variation => 1,
:version => 200,
:trackEvents => true
},
'key3' => {
:variation => 1,
:version => 300,
:debugEventsUntilDate => future_time
}
},
'$valid' => true
})
end

it "returns empty state for nil user" do
config.feature_store.init({ LaunchDarkly::FEATURES => { 'key1' => flag1, 'key2' => flag2 } })

Expand Down