statsig 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8f1e2b0340c9bbeb49888f54d13505bc7b89c8a70d33e5adaed1e4b95568798
4
- data.tar.gz: f70a5060da61c965bbe7e93d0ee7a42cbb30fd0504228959aba7d5ca894278a2
3
+ metadata.gz: 1590d900487869f3cbd76aae50f38ccb535b372ba0468a446ab5574ccfc782eb
4
+ data.tar.gz: 1e94c594d470d0baa21a073177677d6c631297aa1fe51747853ef25106b55c6e
5
5
  SHA512:
6
- metadata.gz: cadde7dcab3590b3d9a3d44bc3856f847b5cb50e9b8f365c1287ebad6bff59a5f82aeaef74e8ab958fb6e8e489ee811df9998cf86f1c18b588389f6194f2f2c0
7
- data.tar.gz: 879e6ee89157ee4e86032d0d28c6588f21236b3503955150f6e702d06feaac503a8572696c82fe40b086a1e6df17900952c7b08e35f46162df8c50938e0f1225
6
+ metadata.gz: 7b2ceb928a74c83e00b783aa46ea45010dbd9daa4a8932a29528e7edc10d9393a6cad9139c26bcd98b13509957565637593c4d0115bd5f929425dc7872f54260
7
+ data.tar.gz: db7812f360b4e68b402107fedea8f7d7c591bdb83ad206265b871d22b837c6be04e867c51d879a1730dbcc8cec76097879e47f601d42d8e1c456018dda5dd44e
data/lib/evaluator.rb CHANGED
@@ -17,14 +17,29 @@ module Statsig
17
17
  @ua_parser = UserAgentParser::Parser.new
18
18
  CountryLookup.initialize
19
19
  @initialized = true
20
+
21
+ @gate_overrides = {}
22
+ @config_overrides = {}
20
23
  end
21
24
 
22
25
  def check_gate(user, gate_name)
26
+ return Statsig::ConfigResult.new(
27
+ gate_name,
28
+ @gate_overrides[gate_name],
29
+ @gate_overrides[gate_name],
30
+ 'override',
31
+ []) unless !@gate_overrides.has_key?(gate_name)
23
32
  return nil unless @initialized && @spec_store.has_gate?(gate_name)
24
33
  eval_spec(user, @spec_store.get_gate(gate_name))
25
34
  end
26
35
 
27
36
  def get_config(user, config_name)
37
+ return Statsig::ConfigResult.new(
38
+ config_name,
39
+ false,
40
+ @config_overrides[config_name],
41
+ 'override',
42
+ []) unless !@config_overrides.has_key?(config_name)
28
43
  return nil unless @initialized && @spec_store.has_config?(config_name)
29
44
  eval_spec(user, @spec_store.get_config(config_name))
30
45
  end
@@ -38,6 +53,14 @@ module Statsig
38
53
  @spec_store.shutdown
39
54
  end
40
55
 
56
+ def override_gate(gate, value)
57
+ @gate_overrides[gate] = value
58
+ end
59
+
60
+ def override_config(config, value)
61
+ @config_overrides[config] = value
62
+ end
63
+
41
64
  private
42
65
 
43
66
  def eval_spec(user, config)
data/lib/network.rb CHANGED
@@ -6,18 +6,20 @@ $retry_codes = [408, 500, 502, 503, 504, 522, 524, 599]
6
6
 
7
7
  module Statsig
8
8
  class Network
9
- def initialize(server_secret, api, backoff_mult = 10)
9
+ def initialize(server_secret, api, local_mode, backoff_mult = 10)
10
10
  super()
11
11
  unless api.end_with?('/')
12
12
  api += '/'
13
13
  end
14
14
  @server_secret = server_secret
15
15
  @api = api
16
+ @local_mode = local_mode
16
17
  @backoff_multiplier = backoff_mult
17
18
  @session_id = SecureRandom.uuid
18
19
  end
19
20
 
20
21
  def post_helper(endpoint, body, retries = 0, backoff = 1)
22
+ return nil unless !@local_mode
21
23
  http = HTTP.headers(
22
24
  {"STATSIG-API-KEY" => @server_secret,
23
25
  "STATSIG-CLIENT-TIME" => (Time.now.to_f * 1000).to_s,
data/lib/spec_store.rb CHANGED
@@ -16,8 +16,8 @@ module Statsig
16
16
  :layers => {},
17
17
  :id_lists => {},
18
18
  }
19
- e = download_config_specs
20
- error_callback.call(e) unless error_callback.nil?
19
+ @error_callback = error_callback
20
+ download_config_specs
21
21
  get_id_lists
22
22
 
23
23
  @config_sync_thread = sync_config_specs
@@ -81,10 +81,16 @@ module Statsig
81
81
  end
82
82
 
83
83
  def download_config_specs
84
+ e = get_config_specs_from_network
85
+ @error_callback.call(e) unless e.nil? or @error_callback.nil?
86
+ end
87
+
88
+ def get_config_specs_from_network
84
89
  begin
85
90
  response, e = @network.post_helper('download_config_specs', JSON.generate({'sinceTime' => @last_sync_time}))
86
91
  if e.nil?
87
92
  process(JSON.parse(response.body))
93
+ nil
88
94
  else
89
95
  e
90
96
  end
data/lib/statsig.rb CHANGED
@@ -42,10 +42,20 @@ module Statsig
42
42
  @shared_instance = nil
43
43
  end
44
44
 
45
+ def self.override_gate(gate_name, gate_value)
46
+ ensure_initialized
47
+ @shared_instance&.override_gate(gate_name, gate_value)
48
+ end
49
+
50
+ def self.override_config(config_name, config_value)
51
+ ensure_initialized
52
+ @shared_instance&.override_config(config_name, config_value)
53
+ end
54
+
45
55
  def self.get_statsig_metadata
46
56
  {
47
57
  'sdkType' => 'ruby-server',
48
- 'sdkVersion' => '1.11.0',
58
+ 'sdkVersion' => '1.12.0',
49
59
  }
50
60
  end
51
61
 
@@ -22,7 +22,7 @@ class StatsigDriver
22
22
  @options = options || StatsigOptions.new
23
23
  @shutdown = false
24
24
  @secret_key = secret_key
25
- @net = Statsig::Network.new(secret_key, @options.api_url_base)
25
+ @net = Statsig::Network.new(secret_key, @options.api_url_base, @options.local_mode)
26
26
  @logger = Statsig::StatsigLogger.new(@net, @options)
27
27
  @evaluator = Statsig::Evaluator.new(@net, @options, error_callback)
28
28
  end
@@ -98,6 +98,14 @@ class StatsigDriver
98
98
  @evaluator.shutdown
99
99
  end
100
100
 
101
+ def override_gate(gate_name, gate_value)
102
+ @evaluator.override_gate(gate_name, gate_value)
103
+ end
104
+
105
+ def override_config(config_name, config_value)
106
+ @evaluator.override_config(config_name, config_value)
107
+ end
108
+
101
109
  private
102
110
 
103
111
  def verify_inputs(user, config_name, variable_name)
@@ -1,10 +1,11 @@
1
1
  class StatsigOptions
2
- attr_reader :environment
3
- attr_reader :api_url_base
4
- attr_reader :rulesets_sync_interval
5
- attr_reader :idlists_sync_interval
6
- attr_reader :logging_interval_seconds
7
- attr_reader :logging_max_buffer_size
2
+ attr_accessor :environment
3
+ attr_accessor :api_url_base
4
+ attr_accessor :rulesets_sync_interval
5
+ attr_accessor :idlists_sync_interval
6
+ attr_accessor :logging_interval_seconds
7
+ attr_accessor :logging_max_buffer_size
8
+ attr_accessor :local_mode
8
9
 
9
10
  def initialize(
10
11
  environment=nil,
@@ -12,12 +13,14 @@ class StatsigOptions
12
13
  rulesets_sync_interval: 10,
13
14
  idlists_sync_interval: 60,
14
15
  logging_interval_seconds: 60,
15
- logging_max_buffer_size: 1000)
16
+ logging_max_buffer_size: 1000,
17
+ local_mode: false)
16
18
  @environment = environment.is_a?(Hash) ? environment : nil
17
19
  @api_url_base = api_url_base
18
20
  @rulesets_sync_interval = rulesets_sync_interval
19
21
  @idlists_sync_interval = idlists_sync_interval
20
22
  @logging_interval_seconds = logging_interval_seconds
21
23
  @logging_max_buffer_size = [logging_max_buffer_size, 1000].min
24
+ @local_mode = local_mode
22
25
  end
23
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Statsig, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.3.11
156
+ rubygems_version: 3.2.32
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Statsig server SDK for Ruby