Skip to content

Commit 3b1e70a

Browse files
committed
fix: Reduce overzealous index event emission
1 parent 36d4c44 commit 3b1e70a

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

contract-tests/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'context-comparison',
4242
'polling-gzip',
4343
'inline-context-all',
44+
'reduce-index-events',
4445
'anonymous-redaction',
4546
'evaluation-hooks',
4647
'omit-anonymous-contexts',

lib/ldclient-rb/events.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,24 +321,23 @@ def dispatch_event(event, outbox)
321321
will_add_full_event = true
322322
end
323323

324-
get_indexable_context(event) do |ctx|
324+
suppress_index = (will_add_full_event or !debug_event.nil?)
325+
get_indexable_context(event, suppress_index) do |ctx|
325326
outbox.add_event(LaunchDarkly::Impl::IndexEvent.new(event.timestamp, ctx))
326327
end
327328

328329
outbox.add_event(event) if will_add_full_event && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
329330
outbox.add_event(debug_event) if !debug_event.nil? && @sampler.sample(event.sampling_ratio.nil? ? 1 : event.sampling_ratio)
330331
end
331332

332-
private def get_indexable_context(event, &block)
333+
private def get_indexable_context(event, suppress_index, &block)
333334
return if event.context.nil?
334335

335336
context = !@config.omit_anonymous_contexts ? event.context : event.context.without_anonymous_contexts
336337
return unless context.valid?
337338

338339
return if notice_context(context)
339-
return if event.is_a?(LaunchDarkly::Impl::IdentifyEvent)
340-
return if event.is_a?(LaunchDarkly::Impl::CustomEvent)
341-
return if event.is_a?(LaunchDarkly::Impl::MigrationOpEvent)
340+
return if suppress_index
342341

343342
yield context unless block.nil?
344343
end

spec/events_spec.rb

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ module LaunchDarkly
7979

8080
output = flush_and_get_events(ep, sender)
8181
expect(output).to contain_exactly(
82-
eq(index_event(default_config, anon_context)),
8382
eq(feature_event(default_config, flag, anon_context, 1, 'value')),
8483
include(:kind => "summary")
8584
)
@@ -113,7 +112,6 @@ module LaunchDarkly
113112

114113
output = flush_and_get_events(ep, sender)
115114
expect(output).to contain_exactly(
116-
eq(index_event(omit_anonymous_contexts_config, context)),
117115
eq(feature_event(omit_anonymous_contexts_config, flag, multi, 1, 'value')),
118116
include(:kind => "summary")
119117
)
@@ -170,14 +168,13 @@ module LaunchDarkly
170168
end
171169
end
172170

173-
it "queues individual feature event with index event" do
171+
it "does not queue index event when tracking event" do
174172
with_processor_and_sender(default_config, starting_timestamp) do |ep, sender|
175173
flag = { key: "flagkey", version: 11 }
176174
ep.record_eval_event(context, 'flagkey', 11, 1, 'value', nil, nil, true)
177175

178176
output = flush_and_get_events(ep, sender)
179177
expect(output).to contain_exactly(
180-
eq(index_event(default_config, context)),
181178
eq(feature_event(default_config, flag, context, 1, 'value')),
182179
include(:kind => "summary")
183180
)
@@ -191,7 +188,6 @@ module LaunchDarkly
191188

192189
output = flush_and_get_events(ep, sender)
193190
expect(output).to contain_exactly(
194-
eq(index_event(default_config, context)),
195191
include(:kind => "summary")
196192
)
197193
end
@@ -205,7 +201,6 @@ module LaunchDarkly
205201

206202
output = flush_and_get_events(ep, sender)
207203
expect(output).to contain_exactly(
208-
eq(index_event(default_config, context)),
209204
eq(feature_event(default_config, flag, context, 1, 'value'))
210205
)
211206
end
@@ -215,12 +210,11 @@ module LaunchDarkly
215210
config = Config.new(default_config_opts.merge(all_attributes_private: true))
216211
with_processor_and_sender(config, starting_timestamp) do |ep, sender|
217212
flag = { key: "flagkey", version: 11 }
218-
ep.record_eval_event(context, 'flagkey', 11, 1, 'value', nil, nil, true)
213+
ep.record_eval_event(context, 'flagkey', 11, 1, 'value', nil, nil, false)
219214

220215
output = flush_and_get_events(ep, sender)
221216
expect(output).to contain_exactly(
222217
eq(index_event(config, context)),
223-
eq(feature_event(config, flag, context, 1, 'value')),
224218
include(:kind => "summary")
225219
)
226220
end
@@ -234,7 +228,6 @@ module LaunchDarkly
234228

235229
output = flush_and_get_events(ep, sender)
236230
expect(output).to contain_exactly(
237-
eq(index_event(config, context)),
238231
eq(feature_event(config, flag, context, 1, 'value')),
239232
include(:kind => "summary")
240233
)
@@ -249,7 +242,6 @@ module LaunchDarkly
249242

250243
output = flush_and_get_events(ep, sender)
251244
expect(output).to contain_exactly(
252-
eq(index_event(default_config, context)),
253245
eq(debug_event(default_config, flag, context, 1, 'value')),
254246
include(:kind => "summary")
255247
)
@@ -264,7 +256,6 @@ module LaunchDarkly
264256

265257
output = flush_and_get_events(ep, sender)
266258
expect(output).to contain_exactly(
267-
eq(index_event(default_config, context)),
268259
include(:kind => "summary")
269260
)
270261
end
@@ -278,7 +269,6 @@ module LaunchDarkly
278269

279270
output = flush_and_get_events(ep, sender)
280271
expect(output).to contain_exactly(
281-
eq(index_event(default_config, context)),
282272
eq(feature_event(default_config, flag, context, 1, 'value')),
283273
eq(debug_event(default_config, flag, context, 1, 'value')),
284274
include(:kind => "summary")
@@ -338,14 +328,12 @@ module LaunchDarkly
338328
flag1 = { key: "flagkey1", version: 11 }
339329
flag2 = { key: "flagkey2", version: 22 }
340330

341-
ep.record_eval_event(context, 'flagkey1', 11, 1, 'value', nil, nil, true)
342-
ep.record_eval_event(context, 'flagkey2', 22, 1, 'value', nil, nil, true)
331+
ep.record_eval_event(context, 'flagkey1', 11, 1, 'value', nil, nil, false)
332+
ep.record_eval_event(context, 'flagkey2', 22, 1, 'value', nil, nil, false)
343333

344334
output = flush_and_get_events(ep, sender)
345335
expect(output).to contain_exactly(
346336
eq(index_event(default_config, context)),
347-
eq(feature_event(default_config, flag1, context, 1, 'value', starting_timestamp)),
348-
eq(feature_event(default_config, flag2, context, 1, 'value', starting_timestamp + 1)),
349337
include(:kind => "summary")
350338
)
351339
end

0 commit comments

Comments
 (0)