Skip to content

Commit bd60e09

Browse files
committed
Change RC and reconfiguration flow
1 parent d1bfb76 commit bd60e09

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

lib/datadog/open_feature/evaluation_engine.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def reconfigure!
6060

6161
@logger.error("#{error_message}, error #{e.inspect}")
6262
@telemetry.report(e, description: error_message)
63+
64+
raise e
6365
end
6466
end
6567
end

lib/datadog/open_feature/remote.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
module Datadog
66
module OpenFeature
7+
# This module contains the remote configuration functionality for OpenFeature
78
module Remote
89
ReadError = Class.new(StandardError)
910

@@ -33,24 +34,22 @@ def receivers(telemetry)
3334
next telemetry.error("OpenFeature: RemoteConfig change is not present on #{change.type}")
3435
end
3536

36-
# NOTE: We don't validate config and immediately mark content as
37-
# applied, even tho it might be a failure.
38-
#
39-
# The re-configuration process is fail-safe by itself and
40-
# will be changed once RC updated to deliver patches.
37+
# NOTE: In the current RC implementation we immediately apply the configuration,
38+
# but that might change if we need to apply patches instead.
4139
case change.type
4240
when :insert, :update
4341
# @type var content: Core::Remote::Configuration::Content
4442
engine.configuration = read_content(content)
43+
engine.reconfigure!
44+
4545
content.applied
4646
when :delete
4747
# NOTE: For now, we treat deletion as clearing the configuration
4848
# In a multi-config scenario, we might track configs per path
4949
engine.configuration = nil
50+
engine.reconfigure!
5051
end
5152
end
52-
53-
engine.reconfigure!
5453
end
5554

5655
[receiver]

spec/datadog/open_feature/evaluation_engine_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
.with(error, description: match(/OpenFeature: Failed to reconfigure/))
167167

168168
engine.configuration = '{}'
169-
expect { engine.reconfigure! }.not_to raise_error
169+
expect { engine.reconfigure! }.to raise_error(error)
170170
end
171171

172172
it 'persists previouly configured evaluator' do
@@ -175,9 +175,9 @@
175175
allow(reporter).to receive(:report)
176176

177177
engine.configuration = '{}'
178-
expect { engine.reconfigure! }.not_to change {
179-
engine.fetch_value(flag_key: 'test', expected_type: :string).value
180-
}.from('hello')
178+
179+
expect { engine.reconfigure! }.to raise_error(error)
180+
expect(engine.fetch_value(flag_key: 'test', expected_type: :string).value).to eq('hello')
181181
end
182182
end
183183

spec/datadog/open_feature/remote_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@
105105
end
106106
end
107107

108+
context 'when change type is insert and reconfigure fails' do
109+
before { allow(engine).to receive(:reconfigure!).and_raise(error) }
110+
111+
let(:error) { StandardError.new('Ooops') }
112+
let(:transaction) do
113+
repository.transaction { |_, t| t.insert(content.path, target, content) }
114+
end
115+
116+
it 'does not acknowledge applied change and logs error' do
117+
expect { receiver.call(repository, transaction) }.to raise_error(error)
118+
119+
expect(content.apply_state).to eq(Datadog::Core::Remote::Configuration::Content::ApplyState::UNACKNOWLEDGED)
120+
end
121+
end
122+
108123
context 'when change type is update' do
109124
before do
110125
txn = repository.transaction { |_, t| t.insert(content.path, target, content) }
@@ -175,9 +190,9 @@
175190
Datadog::Core::Remote::Configuration::Path.parse('datadog/1/FFE_FLAGS/other/config')
176191
end
177192

178-
it 'logs error when content missing and still reconfigures' do
193+
it 'logs error when content is missing and does not reconfigure the engine' do
179194
expect(telemetry).to receive(:error).with(/OpenFeature: RemoteConfig change is not present/)
180-
expect(engine).to receive(:reconfigure!)
195+
expect(engine).not_to receive(:reconfigure!)
181196

182197
receiver.call(repository, changes)
183198
end

0 commit comments

Comments
 (0)