ldclient-rb 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aed3c4885f97dd1ad3f8dad1e9ea37ae53931fd6
4
- data.tar.gz: a33110bc3288b9529aebc076e2fa5c6c405ea41d
3
+ metadata.gz: c11f5029a26f9320594fad4b3e580add838f46dd
4
+ data.tar.gz: e9d8569a3f7b96a0cdbbc7ecedc1f76b798c8f1f
5
5
  SHA512:
6
- metadata.gz: 0e8fe67e4835f5a961a5bd65b3ef383f85910253c361202b75f18dff585dbb8e210b1bc388297cd771111409bf4f0620f8aeb9197d8db17da3a644976c87ff1d
7
- data.tar.gz: 85ad89319527662c86f18c6d472476b887f0382715577bf6fcf105c32dce3f24b51ea888a0022daff017cb9ffe4f1a3601edaa24f4d85d073de35284e478ac5b
6
+ metadata.gz: 55780c3aec6537b3491fe4c960a7475a29c3ea529b337ad3f3556140c9faa949c2de44340837ef1d3f069b043aa2e80de05a790e575f0b868b5c3e382c076cb6
7
+ data.tar.gz: aac072bbc8e7dc99c64ee282da1dd735c87d5f76518dab6e5c1ca3e86dfd11148b4b53e44ac40624b0db61a2fba61acc1b9fa2dacec595d71d4082505f3e3f3a
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to the LaunchDarkly Ruby SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [5.3.0] - 2018-10-24
6
+ ### Added:
7
+ - The `all_flags_state` method now accepts a new option, `details_only_for_tracked_flags`, which reduces the size of the JSON representation of the flag state by omitting some metadata. Specifically, it omits any data that is normally used for generating detailed evaluation events if a flag does not have event tracking or debugging turned on.
8
+
9
+ ### Fixed:
10
+ - JSON data from `all_flags_state` is now slightly smaller even if you do not use the new option described above, because it omits the flag property for event tracking unless that property is true.
11
+
5
12
  ## [5.2.0] - 2018-08-29
6
13
  ### Added:
7
14
  - The new `LDClient` method `variation_detail` allows you to evaluate a feature flag (using the same parameters as you would for `variation`) and receive more information about how the value was calculated. This information is returned in an `EvaluationDetail` object, which contains both the result value and a "reason" object which will tell you, for instance, if the user was individually targeted for the flag or was matched by one of the flag's rules, or if the flag returned the default value due to an error.
@@ -15,13 +15,21 @@ module LaunchDarkly
15
15
  end
16
16
 
17
17
  # Used internally to build the state map.
18
- def add_flag(flag, value, variation, reason = nil)
18
+ def add_flag(flag, value, variation, reason = nil, details_only_if_tracked = false)
19
19
  key = flag[:key]
20
20
  @flag_values[key] = value
21
- meta = { version: flag[:version], trackEvents: flag[:trackEvents] }
21
+ meta = {}
22
+ with_details = !details_only_if_tracked || flag[:trackEvents]
23
+ if !with_details && flag[:debugEventsUntilDate]
24
+ with_details = flag[:debugEventsUntilDate] > (Time.now.to_f * 1000).to_i
25
+ end
26
+ if with_details
27
+ meta[:version] = flag[:version]
28
+ meta[:reason] = reason if !reason.nil?
29
+ end
22
30
  meta[:variation] = variation if !variation.nil?
31
+ meta[:trackEvents] = true if flag[:trackEvents]
23
32
  meta[:debugEventsUntilDate] = flag[:debugEventsUntilDate] if flag[:debugEventsUntilDate]
24
- meta[:reason] = reason if !reason.nil?
25
33
  @flag_metadata[key] = meta
26
34
  end
27
35
 
@@ -212,6 +212,10 @@ module LaunchDarkly
212
212
  # client-side SDK should be included in the state. By default, all flags are included.
213
213
  # @option options [Boolean] :with_reasons (false) True if evaluation reasons should be included
214
214
  # in the state (see `variation_detail`). By default, they are not included.
215
+ # @option options [Boolean] :details_only_for_tracked_flags (false) True if any flag metadata that is
216
+ # normally only used for event generation - such as flag versions and evaluation reasons - should be
217
+ # omitted for any flag that does not have event tracking or debugging turned on. This reduces the size
218
+ # of the JSON data if you are passing the flag state to the front end.
215
219
  # @return [FeatureFlagsState] a FeatureFlagsState object which can be serialized to JSON
216
220
  #
217
221
  def all_flags_state(user, options={})
@@ -234,16 +238,18 @@ module LaunchDarkly
234
238
  state = FeatureFlagsState.new(true)
235
239
  client_only = options[:client_side_only] || false
236
240
  with_reasons = options[:with_reasons] || false
241
+ details_only_if_tracked = options[:details_only_for_tracked_flags] || false
237
242
  features.each do |k, f|
238
243
  if client_only && !f[:clientSide]
239
244
  next
240
245
  end
241
246
  begin
242
247
  result = evaluate(f, user, @store, @config.logger)
243
- state.add_flag(f, result.detail.value, result.detail.variation_index, with_reasons ? result.detail.reason : nil)
248
+ state.add_flag(f, result.detail.value, result.detail.variation_index, with_reasons ? result.detail.reason : nil,
249
+ details_only_if_tracked)
244
250
  rescue => exn
245
251
  Util.log_exception(@config.logger, "Error evaluating flag \"#{k}\" in all_flags_state", exn)
246
- state.add_flag(f, nil, nil, with_reasons ? { kind: 'ERROR', errorKind: 'EXCEPTION' } : nil)
252
+ state.add_flag(f, nil, nil, with_reasons ? { kind: 'ERROR', errorKind: 'EXCEPTION' } : nil, details_only_if_tracked)
247
253
  end
248
254
  end
249
255
 
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "5.2.0"
2
+ VERSION = "5.3.0"
3
3
  end
@@ -42,8 +42,7 @@ describe LaunchDarkly::FeatureFlagsState do
42
42
  '$flagsState' => {
43
43
  'key1' => {
44
44
  :variation => 0,
45
- :version => 100,
46
- :trackEvents => false
45
+ :version => 100
47
46
  },
48
47
  'key2' => {
49
48
  :variation => 1,
@@ -233,8 +233,7 @@ describe LaunchDarkly::LDClient do
233
233
  '$flagsState' => {
234
234
  'key1' => {
235
235
  :variation => 0,
236
- :version => 100,
237
- :trackEvents => false
236
+ :version => 100
238
237
  },
239
238
  'key2' => {
240
239
  :variation => 1,
@@ -263,6 +262,44 @@ describe LaunchDarkly::LDClient do
263
262
  expect(values).to eq({ 'client-side-1' => 'value1', 'client-side-2' => 'value2' })
264
263
  end
265
264
 
265
+ it "can omit details for untracked flags" do
266
+ future_time = (Time.now.to_f * 1000).to_i + 100000
267
+ flag1 = { key: "key1", version: 100, offVariation: 0, variations: [ 'value1' ], trackEvents: false }
268
+ flag2 = { key: "key2", version: 200, offVariation: 1, variations: [ 'x', 'value2' ], trackEvents: true }
269
+ flag3 = { key: "key3", version: 300, offVariation: 1, variations: [ 'x', 'value3' ], debugEventsUntilDate: future_time }
270
+
271
+ config.feature_store.init({ LaunchDarkly::FEATURES => { 'key1' => flag1, 'key2' => flag2, 'key3' => flag3 } })
272
+
273
+ state = client.all_flags_state({ key: 'userkey' }, { details_only_for_tracked_flags: true })
274
+ expect(state.valid?).to be true
275
+
276
+ values = state.values_map
277
+ expect(values).to eq({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' })
278
+
279
+ result = state.as_json
280
+ expect(result).to eq({
281
+ 'key1' => 'value1',
282
+ 'key2' => 'value2',
283
+ 'key3' => 'value3',
284
+ '$flagsState' => {
285
+ 'key1' => {
286
+ :variation => 0
287
+ },
288
+ 'key2' => {
289
+ :variation => 1,
290
+ :version => 200,
291
+ :trackEvents => true
292
+ },
293
+ 'key3' => {
294
+ :variation => 1,
295
+ :version => 300,
296
+ :debugEventsUntilDate => future_time
297
+ }
298
+ },
299
+ '$valid' => true
300
+ })
301
+ end
302
+
266
303
  it "returns empty state for nil user" do
267
304
  config.feature_store.init({ LaunchDarkly::FEATURES => { 'key1' => flag1, 'key2' => flag2 } })
268
305
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler