Module: Datadog::OpenFeature::Remote

Defined in:
lib/datadog/open_feature/remote.rb

Overview

This module contains the remote configuration functionality for OpenFeature

Constant Summary collapse

ReadError =
Class.new(StandardError)
FFE_FLAG_CONFIGURATION_RULES =
1 << 46
FFE_PRODUCTS =
['FFE_FLAGS'].freeze
FFE_CAPABILITIES =
[FFE_FLAG_CONFIGURATION_RULES].freeze

Class Method Summary collapse

Class Method Details

.capabilitiesObject



16
17
18
# File 'lib/datadog/open_feature/remote.rb', line 16

def capabilities
  FFE_CAPABILITIES
end

.productsObject



20
21
22
# File 'lib/datadog/open_feature/remote.rb', line 20

def products
  FFE_PRODUCTS
end

.receivers(telemetry) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/open_feature/remote.rb', line 24

def receivers(telemetry)
  matcher = Core::Remote::Dispatcher::Matcher::Product.new(FFE_PRODUCTS)
  receiver = Core::Remote::Dispatcher::Receiver.new(matcher) do |repository, changes|
    engine = OpenFeature.engine
    next unless engine

    changes.each do |change|
      content = repository[change.path]

      unless content || change.type == :delete
        next telemetry.error("OpenFeature: Remote Configuration change is not present on #{change.type}")
      end

      # NOTE: In the current RC implementation we immediately apply the configuration,
      #       but that might change if we need to apply patches instead.
      case change.type
      when :insert, :update
        begin
          # @type var content: Core::Remote::Configuration::Content
          engine.reconfigure!(read_content(content))
          content.applied
        rescue ReadError => e
          content.errored("Error reading Remote Configuration content: #{e.message}")
        rescue EvaluationEngine::ReconfigurationError => e
          content.errored("Error applying OpenFeature configuration: #{e.message}")
        end
      when :delete
        # NOTE: For now, we treat deletion as clearing the configuration
        #       In a multi-config scenario, we might track configs per path
        engine.reconfigure!(nil)
      end
    end
  end

  [receiver]
end