Class: Statsig::SpecStore
- Inherits:
-
Object
- Object
- Statsig::SpecStore
- Defined in:
- lib/spec_store.rb
Instance Attribute Summary collapse
-
#cmab_configs ⇒ Object
Returns the value of attribute cmab_configs.
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#experiment_to_layer ⇒ Object
Returns the value of attribute experiment_to_layer.
-
#gates ⇒ Object
Returns the value of attribute gates.
-
#hashed_sdk_keys_to_app_ids ⇒ Object
Returns the value of attribute hashed_sdk_keys_to_app_ids.
-
#id_lists ⇒ Object
Returns the value of attribute id_lists.
-
#init_reason ⇒ Object
Returns the value of attribute init_reason.
-
#initial_config_sync_time ⇒ Object
Returns the value of attribute initial_config_sync_time.
-
#last_config_sync_time ⇒ Object
Returns the value of attribute last_config_sync_time.
-
#layers ⇒ Object
Returns the value of attribute layers.
-
#sdk_keys_to_app_ids ⇒ Object
Returns the value of attribute sdk_keys_to_app_ids.
-
#unsupported_configs ⇒ Object
Returns the value of attribute unsupported_configs.
Instance Method Summary collapse
- #get_app_id_for_sdk_key(sdk_key) ⇒ Object
- #get_cmab_config(config_name) ⇒ Object
- #get_condition(condition_hash) ⇒ Object
- #get_config(config_name) ⇒ Object
- #get_gate(gate_name) ⇒ Object
- #get_id_list(list_name) ⇒ Object
- #get_initialization_details ⇒ Object
- #get_layer(layer_name) ⇒ Object
- #has_cmab_config?(config_name) ⇒ Boolean
- #has_config?(config_name) ⇒ Boolean
- #has_gate?(gate_name) ⇒ Boolean
- #has_hashed_sdk_key?(hashed_sdk_key) ⇒ Boolean
- #has_layer?(layer_name) ⇒ Boolean
- #has_sdk_key?(sdk_key) ⇒ Boolean
-
#initialize(network, options, error_callback, diagnostics, error_boundary, logger, secret_key, sdk_config) ⇒ SpecStore
constructor
A new instance of SpecStore.
- #is_ready_for_checks ⇒ Object
- #maybe_restart_background_threads ⇒ Object
- #shutdown ⇒ Object
- #sync_config_specs ⇒ Object
- #sync_id_lists ⇒ Object
Constructor Details
#initialize(network, options, error_callback, diagnostics, error_boundary, logger, secret_key, sdk_config) ⇒ SpecStore
Returns a new instance of SpecStore.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/spec_store.rb', line 24 def initialize(network, , error_callback, diagnostics, error_boundary, logger, secret_key, sdk_config) @init_reason = EvaluationReason::UNINITIALIZED @network = network @options = @error_callback = error_callback @last_config_sync_time = 0 @initial_config_sync_time = 0 @rulesets_sync_interval = .rulesets_sync_interval @id_lists_sync_interval = .idlists_sync_interval @rules_updated_callback = .rules_updated_callback @gates = {} @configs = {} @layers = {} @cmab_configs = {} @condition_map = {} @id_lists = {} @experiment_to_layer = {} @sdk_keys_to_app_ids = {} @hashed_sdk_keys_to_app_ids = {} @diagnostics = diagnostics @error_boundary = error_boundary @logger = logger @secret_key = secret_key @unsupported_configs = Set.new @sdk_configs = sdk_config startTime = (Time.now.to_f * 1000).to_i @id_list_thread_pool = Concurrent::FixedThreadPool.new( .idlist_threadpool_size, name: 'statsig-idlist', max_queue: 100, fallback_policy: :discard ) unless @options.bootstrap_values.nil? if !@options.data_store.nil? puts 'data_store gets priority over bootstrap_values. bootstrap_values will be ignored' else tracker = @diagnostics.track('initialize','bootstrap', 'process') begin if process_specs(.bootstrap_values).nil? @init_reason = EvaluationReason::BOOTSTRAP end rescue StandardError puts 'the provided bootstrapValues is not a valid JSON string' ensure tracker.end(success: @init_reason == EvaluationReason::BOOTSTRAP) end end end failure_details = nil unless @options.data_store.nil? @options.data_store.init failure_details = load_config_specs_from_storage_adapter('initialize') end if @init_reason == EvaluationReason::UNINITIALIZED failure_details = download_config_specs('initialize') end @initial_config_sync_time = @last_config_sync_time == 0 ? -1 : @last_config_sync_time if !@options.data_store.nil? get_id_lists_from_adapter('initialize') else get_id_lists_from_network('initialize') end @config_sync_thread = spawn_sync_config_specs_thread @id_lists_sync_thread = spawn_sync_id_lists_thread endTime = (Time.now.to_f * 1000).to_i @initialization_details = {duration: endTime - startTime, isSDKReady: true, configSpecReady: @init_reason != EvaluationReason::UNINITIALIZED, failureDetails: failure_details} end |
Instance Attribute Details
#cmab_configs ⇒ Object
Returns the value of attribute cmab_configs.
22 23 24 |
# File 'lib/spec_store.rb', line 22 def cmab_configs @cmab_configs end |
#configs ⇒ Object
Returns the value of attribute configs.
15 16 17 |
# File 'lib/spec_store.rb', line 15 def configs @configs end |
#experiment_to_layer ⇒ Object
Returns the value of attribute experiment_to_layer.
18 19 20 |
# File 'lib/spec_store.rb', line 18 def experiment_to_layer @experiment_to_layer end |
#gates ⇒ Object
Returns the value of attribute gates.
14 15 16 |
# File 'lib/spec_store.rb', line 14 def gates @gates end |
#hashed_sdk_keys_to_app_ids ⇒ Object
Returns the value of attribute hashed_sdk_keys_to_app_ids.
20 21 22 |
# File 'lib/spec_store.rb', line 20 def hashed_sdk_keys_to_app_ids @hashed_sdk_keys_to_app_ids end |
#id_lists ⇒ Object
Returns the value of attribute id_lists.
17 18 19 |
# File 'lib/spec_store.rb', line 17 def id_lists @id_lists end |
#init_reason ⇒ Object
Returns the value of attribute init_reason.
13 14 15 |
# File 'lib/spec_store.rb', line 13 def init_reason @init_reason end |
#initial_config_sync_time ⇒ Object
Returns the value of attribute initial_config_sync_time.
12 13 14 |
# File 'lib/spec_store.rb', line 12 def initial_config_sync_time @initial_config_sync_time end |
#last_config_sync_time ⇒ Object
Returns the value of attribute last_config_sync_time.
11 12 13 |
# File 'lib/spec_store.rb', line 11 def last_config_sync_time @last_config_sync_time end |
#layers ⇒ Object
Returns the value of attribute layers.
16 17 18 |
# File 'lib/spec_store.rb', line 16 def layers @layers end |
#sdk_keys_to_app_ids ⇒ Object
Returns the value of attribute sdk_keys_to_app_ids.
19 20 21 |
# File 'lib/spec_store.rb', line 19 def sdk_keys_to_app_ids @sdk_keys_to_app_ids end |
#unsupported_configs ⇒ Object
Returns the value of attribute unsupported_configs.
21 22 23 |
# File 'lib/spec_store.rb', line 21 def unsupported_configs @unsupported_configs end |
Instance Method Details
#get_app_id_for_sdk_key(sdk_key) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/spec_store.rb', line 179 def get_app_id_for_sdk_key(sdk_key) if sdk_key.nil? return nil end hashed_sdk_key = Statsig::HashUtils.djb2(sdk_key).to_sym if has_hashed_sdk_key?(hashed_sdk_key) return @hashed_sdk_keys_to_app_ids[hashed_sdk_key] end key = sdk_key.to_sym return nil unless has_sdk_key?(key) @sdk_keys_to_app_ids[key] end |
#get_cmab_config(config_name) ⇒ Object
157 158 159 160 161 |
# File 'lib/spec_store.rb', line 157 def get_cmab_config(config_name) config_sym = config_name.to_sym return nil unless has_cmab_config?(config_sym) @cmab_configs[config_sym] end |
#get_condition(condition_hash) ⇒ Object
163 164 165 |
# File 'lib/spec_store.rb', line 163 def get_condition(condition_hash) @condition_map[condition_hash.to_sym] end |
#get_config(config_name) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/spec_store.rb', line 143 def get_config(config_name) config_sym = config_name.to_sym return nil unless has_config?(config_sym) @configs[config_sym] end |
#get_gate(gate_name) ⇒ Object
137 138 139 140 141 |
# File 'lib/spec_store.rb', line 137 def get_gate(gate_name) gate_sym = gate_name.to_sym return nil unless has_gate?(gate_sym) @gates[gate_sym] end |
#get_id_list(list_name) ⇒ Object
167 168 169 |
# File 'lib/spec_store.rb', line 167 def get_id_list(list_name) @id_lists[list_name] end |
#get_initialization_details ⇒ Object
104 105 106 |
# File 'lib/spec_store.rb', line 104 def get_initialization_details @initialization_details end |
#get_layer(layer_name) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/spec_store.rb', line 150 def get_layer(layer_name) layer_sym = layer_name.to_sym return nil unless has_layer?(layer_sym) @layers[layer_sym] end |
#has_cmab_config?(config_name) ⇒ Boolean
130 131 132 133 134 135 |
# File 'lib/spec_store.rb', line 130 def has_cmab_config?(config_name) if @cmab_configs.nil? return false end @cmab_configs.key?(config_name.to_sym) end |
#has_config?(config_name) ⇒ Boolean
122 123 124 |
# File 'lib/spec_store.rb', line 122 def has_config?(config_name) @configs.key?(config_name.to_sym) end |
#has_gate?(gate_name) ⇒ Boolean
118 119 120 |
# File 'lib/spec_store.rb', line 118 def has_gate?(gate_name) @gates.key?(gate_name.to_sym) end |
#has_hashed_sdk_key?(hashed_sdk_key) ⇒ Boolean
175 176 177 |
# File 'lib/spec_store.rb', line 175 def has_hashed_sdk_key?(hashed_sdk_key) @hashed_sdk_keys_to_app_ids.key?(hashed_sdk_key) end |
#has_layer?(layer_name) ⇒ Boolean
126 127 128 |
# File 'lib/spec_store.rb', line 126 def has_layer?(layer_name) @layers.key?(layer_name.to_sym) end |
#has_sdk_key?(sdk_key) ⇒ Boolean
171 172 173 |
# File 'lib/spec_store.rb', line 171 def has_sdk_key?(sdk_key) @sdk_keys_to_app_ids.key?(sdk_key) end |
#is_ready_for_checks ⇒ Object
100 101 102 |
# File 'lib/spec_store.rb', line 100 def is_ready_for_checks @last_config_sync_time != 0 end |
#maybe_restart_background_threads ⇒ Object
195 196 197 198 199 200 201 202 |
# File 'lib/spec_store.rb', line 195 def maybe_restart_background_threads if @config_sync_thread.nil? || !@config_sync_thread.alive? @config_sync_thread = spawn_sync_config_specs_thread end if @id_lists_sync_thread.nil? || !@id_lists_sync_thread.alive? @id_lists_sync_thread = spawn_sync_id_lists_thread end end |
#shutdown ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/spec_store.rb', line 108 def shutdown @config_sync_thread&.exit @id_lists_sync_thread&.exit @id_list_thread_pool.shutdown @id_list_thread_pool.wait_for_termination(timeout = 3) unless @options.data_store.nil? @options.data_store.shutdown end end |
#sync_config_specs ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/spec_store.rb', line 204 def sync_config_specs if @options.data_store&.(Interfaces::IDataStore::CONFIG_SPECS_V2_KEY) load_config_specs_from_storage_adapter('config_sync') else download_config_specs('config_sync') end @logger.log_diagnostics_event(@diagnostics, 'config_sync') end |
#sync_id_lists ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'lib/spec_store.rb', line 213 def sync_id_lists if @options.data_store&.(Interfaces::IDataStore::ID_LISTS_KEY) get_id_lists_from_adapter('config_sync') else get_id_lists_from_network('config_sync') end @logger.log_diagnostics_event(@diagnostics, 'config_sync') end |