Skip to content

Commit 0ddd4d1

Browse files
authored
Merge pull request #964 from Underdog-Inc/fix/synchronizer-instrumenter
Fix: Pass instrumenter to Feature instances in Synchronizer
2 parents 941f417 + 78ac31e commit 0ddd4d1

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

lib/flipper/adapters/sync/synchronizer.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def sync
3838

3939
# Sync all the gate values.
4040
remote_get_all.each do |feature_key, remote_gates_hash|
41-
feature = Feature.new(feature_key, @local)
41+
feature = Feature.new(feature_key, @local, instrumenter: @instrumenter)
4242
# Check if feature_key is in hash before accessing to prevent unintended hash modification
4343
local_gates_hash = local_get_all.key?(feature_key) ? local_get_all[feature_key] : @local.default_config
4444
local_gate_values = GateValues.new(local_gates_hash)
@@ -48,11 +48,11 @@ def sync
4848

4949
# Add features that are missing in local and present in remote.
5050
features_to_add = remote_get_all.keys - local_get_all.keys
51-
features_to_add.each { |key| Feature.new(key, @local).add }
51+
features_to_add.each { |key| Feature.new(key, @local, instrumenter: @instrumenter).add }
5252

5353
# Remove features that are present in local and missing in remote.
5454
features_to_remove = local_get_all.keys - remote_get_all.keys
55-
features_to_remove.each { |key| Feature.new(key, @local).remove }
55+
features_to_remove.each { |key| Feature.new(key, @local, instrumenter: @instrumenter).remove }
5656

5757
nil
5858
rescue => exception

spec/flipper/adapters/sync/synchronizer_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,43 @@
8484

8585
expect(local_flipper.features.map(&:key)).to eq([])
8686
end
87+
88+
it 'emits feature_operation.flipper events when syncing' do
89+
remote_flipper.enable(:search)
90+
91+
subject.call
92+
93+
events = instrumenter.events_by_name("feature_operation.flipper")
94+
expect(events).not_to be_empty
95+
96+
feature_names = events.map { |e| e.payload[:feature_name].to_s }
97+
expect(feature_names).to include("search")
98+
end
99+
100+
it 'emits feature_operation.flipper events when adding features' do
101+
remote_flipper.add(:new_feature)
102+
103+
subject.call
104+
105+
events = instrumenter.events_by_name("feature_operation.flipper")
106+
add_events = events.select { |e| e.payload[:operation] == :add }
107+
expect(add_events).not_to be_empty
108+
109+
feature_names = add_events.map { |e| e.payload[:feature_name].to_s }
110+
expect(feature_names).to include("new_feature")
111+
end
112+
113+
it 'emits feature_operation.flipper events when removing features' do
114+
local_flipper.add(:old_feature)
115+
116+
subject.call
117+
118+
events = instrumenter.events_by_name("feature_operation.flipper")
119+
remove_events = events.select { |e| e.payload[:operation] == :remove }
120+
expect(remove_events).not_to be_empty
121+
122+
feature_names = remove_events.map { |e| e.payload[:feature_name].to_s }
123+
expect(feature_names).to include("old_feature")
124+
end
87125
end
88126
end

0 commit comments

Comments
 (0)