Skip to content

Commit 6ecf03e

Browse files
committed
feat: added eval reasons to variable properties
1 parent fa9260e commit 6ecf03e

File tree

9 files changed

+127
-77
lines changed

9 files changed

+127
-77
lines changed

lib/devcycle-ruby-server-sdk.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require 'devcycle-ruby-server-sdk/eval_hooks_runner'
3030
require 'devcycle-ruby-server-sdk/models/eval_hook'
3131
require 'devcycle-ruby-server-sdk/models/eval_hook_context'
32+
require 'devcycle-ruby-server-sdk/eval_reasons'
3233

3334
# APIs
3435
require 'devcycle-ruby-server-sdk/api/client'

lib/devcycle-ruby-server-sdk/api/client.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,16 @@ def variable(user, key, default, opts = {})
195195
value = default
196196
type = determine_variable_type(default)
197197
defaulted = true
198+
eval = { reason: DevCycle::DEFAULT_REASONS::UNKNOWN, details: DevCycle::EVAL_REASON_DETAILS::UNKNOWN }
198199
if local_bucketing_initialized? && @local_bucketing.has_config
199200
type_code = variable_type_code_from_type(type)
200201
variable_pb = variable_for_user_pb(user, key, type_code)
201202
unless variable_pb.nil?
202203
value = get_variable_value(variable_pb)
203204
defaulted = false
205+
eval = get_eval_reason(variable_pb)
206+
else
207+
eval = { reason: DevCycle::DEFAULT_REASONS::USER_NOT_TARGETED, details: DevCycle::DEFAULT_REASONS::USER_NOT_TARGETED }
204208
end
205209
else
206210
@logger.warn("Local bucketing not initialized, returning default value for variable #{key}")
@@ -214,7 +218,8 @@ def variable(user, key, default, opts = {})
214218
value: value,
215219
type: type,
216220
defaultValue: default,
217-
isDefaulted: defaulted
221+
isDefaulted: defaulted,
222+
eval: eval
218223
})
219224
end
220225

@@ -574,6 +579,15 @@ def get_variable_value(variable_pb)
574579
end
575580
end
576581

582+
def get_eval_reason(variable_pb)
583+
if variable_pb.eval.nil?
584+
{ reason: DevCycle::DEFAULT_REASONS::UNKNOWN, details: DevCycle::DEFAULT_REASONS::UNKNOWN }
585+
else
586+
puts ("variable_pb.eval bruh: #{variable_pb.eval}")
587+
{ reason: variable_pb.eval.reason, details: variable_pb.eval.details }
588+
end
589+
end
590+
577591
# Adds an eval hook to the client
578592
# @param [EvalHook] eval_hook The eval hook to add
579593
# @return [void]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module DevCycle
2+
# Default reasons for evaluation failures
3+
module DEFAULT_REASONS
4+
MISSING_CONFIG = 'MISSING_CONFIG'
5+
MISSING_VARIABLE = 'MISSING_VARIABLE'
6+
MISSING_FEATURE = 'MISSING_FEATURE'
7+
MISSING_VARIATION = 'MISSING_VARIATION'
8+
MISSING_VARIABLE_FOR_VARIATION = 'MISSING_VARIABLE_FOR_VARIATION'
9+
USER_NOT_IN_ROLLOUT = 'USER_NOT_IN_ROLLOUT'
10+
USER_NOT_TARGETED = 'USER_NOT_TARGETED'
11+
INVALID_VARIABLE_TYPE = 'INVALID_VARIABLE_TYPE'
12+
UNKNOWN = 'UNKNOWN'
13+
end
14+
15+
# Evaluation reasons for successful evaluations
16+
module EVAL_REASONS
17+
TARGETING_MATCH = 'TARGETING_MATCH'
18+
SPLIT = 'SPLIT'
19+
DEFAULT = 'DEFAULT'
20+
DISABLED = 'DISABLED'
21+
ERROR = 'ERROR'
22+
OVERRIDE = 'OVERRIDE'
23+
OPT_IN = 'OPT_IN'
24+
end
25+
26+
# Detailed evaluation reason descriptions
27+
module EVAL_REASON_DETAILS
28+
# All Users
29+
ALL_USERS = 'All Users'
30+
# Audiences
31+
AUDIENCE_MATCH = 'Audience Match'
32+
NOT_IN_AUDIENCE = 'Not in Audience'
33+
# Opt-In
34+
OPT_IN = 'Opt-In'
35+
NOT_OPTED_IN = 'Not Opt-In'
36+
# Overrides
37+
OVERRIDE = 'Override'
38+
# Split details
39+
RANDOM_DISTRIBUTION = 'Random Distribution'
40+
ROLLOUT = 'Rollout'
41+
# User Specific
42+
USER_ID = 'User ID'
43+
EMAIL = 'Email'
44+
COUNTRY = 'Country'
45+
PLATFORM = 'Platform'
46+
PLATFORM_VERSION = 'Platform Version'
47+
APP_VERSION = 'App Version'
48+
DEVICE_MODEL = 'Device Model'
49+
CUSTOM_DATA = 'Custom Data'
50+
# Error cases
51+
ERROR = 'Error'
52+
DEFAULT = 'Default'
53+
UNKNOWN = 'Unknown'
54+
end
55+
end

lib/devcycle-ruby-server-sdk/localbucketing/proto/variableForUserParams.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,12 @@ message SDKVariable_PB {
6666
double doubleValue = 5;
6767
string stringValue = 6;
6868
NullableString evalReason = 7;
69+
NullableString _feature = 8;
70+
EvalReason_PB eval = 9;
6971
}
72+
73+
message EvalReason_PB {
74+
string reason = 1;
75+
string details = 2;
76+
string target_id = 3;
77+
}

lib/devcycle-ruby-server-sdk/localbucketing/proto/variableForUserParams_pb.rb

Lines changed: 25 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
BUCKETING_LIB_VERSION="1.35.1"
2+
BUCKETING_LIB_VERSION="1.40.0"
33
WAT_DOWNLOAD=0
44
rm bucketing-lib.release.wasm
55
wget "https://unpkg.com/@devcycle/bucketing-assembly-script@$BUCKETING_LIB_VERSION/build/bucketing-lib.release.wasm"

lib/devcycle-ruby-server-sdk/models/feature.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Feature
3434
attr_accessor :variationName
3535

3636
# Evaluation reasoning
37-
attr_accessor :eval_reason
37+
attr_accessor :eval
3838

3939
class EnumAttributeValidator
4040
attr_reader :datatype
@@ -67,7 +67,7 @@ def self.attribute_map
6767
:'_variation' => :'_variation',
6868
:'variationKey' => :'variationKey',
6969
:'variationName' => :'variationName',
70-
:'eval_reason' => :'evalReason'
70+
:'eval' => :'eval'
7171
}
7272
end
7373

@@ -133,10 +133,6 @@ def initialize(attributes = {})
133133
if attributes.key?(:'variationName')
134134
self.variationName = attributes[:'variationName']
135135
end
136-
137-
if attributes.key?(:'eval_reason')
138-
self.eval_reason = attributes[:'eval_reason']
139-
end
140136
end
141137

142138
# Show invalid properties with the reasons. Usually used together with valid?

lib/devcycle-ruby-server-sdk/models/variable.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class Variable
2929

3030
attr_accessor :defaultValue
3131

32+
# Variable evaluation details
33+
attr_accessor :eval
34+
3235
class EnumAttributeValidator
3336
attr_reader :datatype
3437
attr_reader :allowable_values
@@ -58,7 +61,8 @@ def self.attribute_map
5861
:'type' => :'type',
5962
:'value' => :'value',
6063
:'defaultValue' => :'defaultValue',
61-
:'isDefaulted' => :'isDefaulted'
64+
:'isDefaulted' => :'isDefaulted',
65+
:'eval' => :'eval'
6266
}
6367
end
6468

@@ -120,6 +124,10 @@ def initialize(attributes = {})
120124
if attributes.key?(:'defaultValue')
121125
self.defaultValue = attributes[:'defaultValue']
122126
end
127+
128+
if attributes.key?(:'eval')
129+
self.eval = attributes[:'eval']
130+
end
123131
end
124132

125133
# Show invalid properties with the reasons. Usually used together with valid?

spec/api/devcycle_api_spec.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
sdk_key = ENV["DEVCYCLE_SERVER_SDK_KEY"]
2222
if sdk_key.nil?
2323
puts("SDK KEY NOT SET - SKIPPING INIT")
24-
return
24+
@skip_tests = true
25+
else
26+
# run before each test
27+
options = DevCycle::Options.new(enable_cloud_bucketing: true)
28+
@api_instance = DevCycle::Client.new(sdk_key, options)
29+
30+
@user = DevCycle::User.new({
31+
user_id: 'test-user',
32+
appVersion: '1.2.3'
33+
})
34+
@skip_tests = false
2535
end
26-
# run before each test
27-
options = DevCycle::Options.new(enable_cloud_bucketing: true)
28-
@api_instance = DevCycle::Client.new(sdk_key, options)
29-
30-
@user = DevCycle::User.new({
31-
user_id: 'test-user',
32-
appVersion: '1.2.3'
33-
})
3436
end
3537

3638
after do

0 commit comments

Comments
 (0)