Skip to content

Commit 6482918

Browse files
authored
feat: added eval reasons to variable properties (#122)
* feat: added eval reasons to variable properties * chore: add eval reason capability to ruby * chore: update bucketing lib and use correct eval reasons * chore: attempt to debug failing harness tests * chore: fix _feature being returned in allVariables * fix: filter out _feature in allVariables return * chore: add eval reason to agg_variable_defaulted metadata * chore: update bucketing lib for events eval reasons * chore: added default reason to event metadata * chore: removed unused reasons and details * chore: try to run cloud for ruby test harness
1 parent fa9260e commit 6482918

File tree

10 files changed

+88
-73
lines changed

10 files changed

+88
-73
lines changed

.github/workflows/test-harness.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ jobs:
1414
with:
1515
sdks-to-test: ruby
1616
sdk-github-sha: ${{github.event.pull_request.head.sha}}
17+
sdk-capabilities: '{ "Ruby": ["clientCustomData", "v2Config", "allVariables", "allFeatures", "evalReason", "eventsEvalReason", "variablesFeatureId"]}'

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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,19 @@ def variable(user, key, default, opts = {})
195195
value = default
196196
type = determine_variable_type(default)
197197
defaulted = true
198+
eval = { reason: DevCycle::EVAL_REASONS::DEFAULT, details: DevCycle::DEFAULT_REASON_DETAILS::USER_NOT_TARGETED }
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
204205
end
206+
eval = get_eval_reason(variable_pb)
205207
else
208+
eval = { reason: DevCycle::EVAL_REASONS::DEFAULT, details: DevCycle::DEFAULT_REASON_DETAILS::MISSING_CONFIG }
206209
@logger.warn("Local bucketing not initialized, returning default value for variable #{key}")
207-
variable_event = Event.new({ type: DevCycle::EventTypes[:agg_variable_defaulted], target: key })
210+
variable_event = Event.new({ type: DevCycle::EventTypes[:agg_variable_defaulted], target: key, metaData: { evalReason: DevCycle::EVAL_REASONS::DEFAULT }})
208211
bucketed_config = BucketedUserConfig.new({}, {}, {}, {}, {}, {}, [])
209212
@event_queue.queue_aggregate_event(variable_event, bucketed_config)
210213
end
@@ -214,7 +217,8 @@ def variable(user, key, default, opts = {})
214217
value: value,
215218
type: type,
216219
defaultValue: default,
217-
isDefaulted: defaulted
220+
isDefaulted: defaulted,
221+
eval: eval
218222
})
219223
end
220224

@@ -574,6 +578,18 @@ def get_variable_value(variable_pb)
574578
end
575579
end
576580

581+
def get_eval_reason(variable_pb)
582+
if variable_pb.nil?
583+
{ reason: DevCycle::EVAL_REASONS::DEFAULT, details: DevCycle::DEFAULT_REASON_DETAILS::USER_NOT_TARGETED}
584+
else
585+
if variable_pb.eval.nil?
586+
{ reason: DevCycle::EVAL_REASONS::DEFAULT, details: DevCycle::DEFAULT_REASON_DETAILS::USER_NOT_TARGETED }
587+
else
588+
{ reason: variable_pb.eval.reason, details: variable_pb.eval.details, target_id: variable_pb.eval.target_id }
589+
end
590+
end
591+
end
592+
577593
# Adds an eval hook to the client
578594
# @param [EvalHook] eval_hook The eval hook to add
579595
# @return [void]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module DevCycle
2+
# Evaluation reasons for successful evaluations
3+
module EVAL_REASONS
4+
DEFAULT = 'DEFAULT'
5+
ERROR = 'ERROR'
6+
end
7+
8+
# Default reason details
9+
module DEFAULT_REASON_DETAILS
10+
MISSING_CONFIG = 'Missing Config'
11+
USER_NOT_TARGETED = 'User Not Targeted'
12+
end
13+
end
Binary file not shown.

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: 2 additions & 2 deletions
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.41.0"
33
WAT_DOWNLOAD=0
44
rm bucketing-lib.release.wasm
5-
wget "https://unpkg.com/@devcycle/bucketing-assembly-script@$BUCKETING_LIB_VERSION/build/bucketing-lib.release.wasm"
5+
wget "https://unpkg.com/@devcycle/bucketing-assembly-script@$BUCKETING_LIB_VERSION/build/bucketing-lib.release.wasm"

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)