Skip to content

Commit 8352517

Browse files
committed
Add libdatadog FFI Reason enum support to OpenFeature binding
* Add DEFAULT and DISABLED constants to AssignmentReason module * Update error handling to use specific assignment reasons: - DEFAULT_ALLOCATION_NULL errors → AssignmentReason::DEFAULT - FLAG_DISABLED errors → AssignmentReason::DISABLED - Other errors → AssignmentReason::ERROR * Align Ruby binding with libdatadog's complete FFI Reason enum * Maintain backward compatibility with existing constants * All 31 internal evaluator tests continue passing
1 parent ea5beb4 commit 8352517

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

lib/datadog/open_feature/binding/assignment_reason.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ module Datadog
44
module OpenFeature
55
module Binding
66
# Assignment reasons returned in ResolutionDetails
7+
# Aligned with libdatadog FFI Reason enum
78
module AssignmentReason
89
TARGETING_MATCH = 'TARGETING_MATCH'
910
SPLIT = 'SPLIT'
1011
STATIC = 'STATIC'
12+
DEFAULT = 'DEFAULT' # For DefaultAllocationNull cases (matches libdatadog FFI Reason::Default)
13+
DISABLED = 'DISABLED' # For FlagDisabled cases
14+
ERROR = 'ERROR'
1115
end
1216
end
1317
end

lib/datadog/open_feature/binding/internal_evaluator.rb

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def create_success_result(value, variant, allocation_key, variation_type, do_log
150150
variant: variant,
151151
error_code: nil, # nil for successful cases (so "if result.error_code" works correctly)
152152
error_message: '', # Empty string for Ok cases (matches libdatadog FFI)
153-
reason: convert_reason_to_symbol(reason),
153+
reason: reason,
154154
allocation_key: allocation_key,
155155
do_log: do_log,
156156
flag_metadata: {
@@ -170,11 +170,14 @@ def create_error_result(error_code, error_message)
170170
ERROR_CODE_MAPPING[error_code] || :general
171171
end
172172

173-
# Determine reason based on error type
174-
reason = if [Ext::DEFAULT_ALLOCATION_NULL, Ext::FLAG_DISABLED].include?(error_code)
175-
:static # These are expected conditions, not errors
173+
# Determine reason based on error type - aligned with libdatadog FFI Reason enum
174+
reason = case error_code
175+
when Ext::DEFAULT_ALLOCATION_NULL
176+
AssignmentReason::DEFAULT
177+
when Ext::FLAG_DISABLED
178+
AssignmentReason::DISABLED
176179
else
177-
:error
180+
AssignmentReason::ERROR
178181
end
179182

180183
ResolutionDetails.new(
@@ -511,25 +514,6 @@ def convert_variation_type_for_output(variation_type)
511514
VARIATION_TYPE_MAPPING[variation_type] || variation_type.to_s.downcase
512515
end
513516

514-
def convert_reason_to_symbol(reason)
515-
# Convert assignment reasons to string format matching libdatadog Reason enum
516-
case reason
517-
when AssignmentReason::STATIC
518-
'STATIC'
519-
when AssignmentReason::TARGETING_MATCH
520-
'TARGETING_MATCH'
521-
when AssignmentReason::SPLIT
522-
'SPLIT'
523-
when 'ERROR'
524-
'ERROR'
525-
when 'DEFAULT'
526-
'DEFAULT'
527-
when 'DISABLED'
528-
'DISABLED'
529-
else
530-
reason.to_s if reason
531-
end
532-
end
533517

534518
end
535519
end

0 commit comments

Comments
 (0)