Class: Datadog::OpenFeature::EvaluationEngine
- Inherits:
-
Object
- Object
- Datadog::OpenFeature::EvaluationEngine
- Defined in:
- lib/datadog/open_feature/evaluation_engine.rb
Overview
This class performs the evaluation of the feature flag
Constant Summary collapse
- ReconfigurationError =
Class.new(StandardError)
- ALLOWED_TYPES =
%i[boolean string number float integer object].freeze
Instance Method Summary collapse
- #fetch_value(flag_key, default_value:, expected_type:, evaluation_context: nil) ⇒ Object
-
#initialize(reporter, telemetry:, logger:) ⇒ EvaluationEngine
constructor
A new instance of EvaluationEngine.
-
#reconfigure!(configuration) ⇒ Object
NOTE: In a currect implementation configuration is expected to be a raw JSON string containing feature flags (straight from the remote config) in the format expected by
libdatadogwithout any modifications.
Constructor Details
#initialize(reporter, telemetry:, logger:) ⇒ EvaluationEngine
Returns a new instance of EvaluationEngine.
16 17 18 19 20 21 22 |
# File 'lib/datadog/open_feature/evaluation_engine.rb', line 16 def initialize(reporter, telemetry:, logger:) @reporter = reporter @telemetry = telemetry @logger = logger @evaluator = NoopEvaluator.new(nil) end |
Instance Method Details
#fetch_value(flag_key, default_value:, expected_type:, evaluation_context: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datadog/open_feature/evaluation_engine.rb', line 24 def fetch_value(flag_key, default_value:, expected_type:, evaluation_context: nil) unless ALLOWED_TYPES.include?(expected_type) = "unknown type #{expected_type.inspect}, allowed types #{ALLOWED_TYPES.join(", ")}" return ResolutionDetails.build_error( value: default_value, error_code: Ext::UNKNOWN_TYPE, error_message: ) end context = evaluation_context&.fields.to_h result = @evaluator.get_assignment( flag_key, default_value: default_value, context: context, expected_type: expected_type ) @reporter.report(result, flag_key: flag_key, context: evaluation_context) result rescue => e @telemetry.report(e, description: 'OpenFeature: Failed to fetch flag value') ResolutionDetails.build_error( value: default_value, error_code: Ext::GENERAL, error_message: e. ) end |
#reconfigure!(configuration) ⇒ Object
NOTE: In a currect implementation configuration is expected to be a raw
JSON string containing feature flags (straight from the remote config)
in the format expected by libdatadog without any modifications
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/datadog/open_feature/evaluation_engine.rb', line 51 def reconfigure!(configuration) if configuration.nil? @logger.debug('OpenFeature: Removing configuration') return @evaluator = NoopEvaluator.new(configuration) end @evaluator = NativeEvaluator.new(configuration) rescue => e = 'OpenFeature: Failed to reconfigure, reverting to the previous configuration' @logger.error("#{}, #{e.class}: #{e.}") @telemetry.report(e, description: "#{} (#{e.class})") raise ReconfigurationError, e. end |