statsig 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e976fe13de26ad1653e42b8a5a710210b51234cb96e6eaed6cbd350097f2370f
4
- data.tar.gz: d0a3e427187fd4ae7cd0ff0b0c0e3c2bb88c3cf5dd7ed14a272f5dae89b18ea1
3
+ metadata.gz: 87f81b59161aaf7f035b0822858db6528c4268dddddaa46f012b6da61017c366
4
+ data.tar.gz: 0c4b7ce02036994d5f3afcf1e1ecda13df7a3541b0bb1f6441996842cd91614f
5
5
  SHA512:
6
- metadata.gz: 2eeaf918074df7b66ffd9746d7f1717efa1912be27e86698c44bd57869f2ca023590d5db9779bbf0b3312a26735781b51afc5fd7a5e726f13fc5af00f7395fec
7
- data.tar.gz: '08d264d18cd2c772f05886782999e8c5703cf92d006a3395f57af84795b4cd309b8a7efe4d98b9e9d62378f584eb3735f3c299f859f0a46e660013e543780dca'
6
+ metadata.gz: 344af0408c2136fa81acfe1f30258cd30b9ded6c472d0c1092583888793f9b998c303c77a86c99ff7484ceab6e3f2bdf69cf02ba17160208ca5ea2cbece562a0
7
+ data.tar.gz: 75a9cd2967a25295b062f68279a7e6b0e0da4e59d7aeacaafbd9261605dce4ee9795633b9631c00008bace9395350210978b882edcc0364ecc3a1b80883c819c
@@ -2,6 +2,8 @@
2
2
  module Statsig
3
3
  module Interfaces
4
4
  class IDataStore
5
+ CONFIG_SPECS_KEY = "statsig.cache"
6
+
5
7
  def init
6
8
  end
7
9
 
@@ -14,6 +16,14 @@ module Statsig
14
16
 
15
17
  def shutdown
16
18
  end
19
+
20
+ ##
21
+ # Determines whether the SDK should poll for updates from
22
+ # the data adapter (instead of Statsig network) for the given key
23
+ #
24
+ # @param key Key of stored item to poll from data adapter
25
+ def should_be_used_for_querying_updates(key)
26
+ end
17
27
  end
18
28
  end
19
29
  end
data/lib/network.rb CHANGED
@@ -20,16 +20,18 @@ module Statsig
20
20
  class Network
21
21
  extend T::Sig
22
22
 
23
- sig { params(server_secret: String, api: String, local_mode: T::Boolean, backoff_mult: Integer).void }
23
+ sig { params(server_secret: String, options: StatsigOptions, backoff_mult: Integer).void }
24
24
 
25
- def initialize(server_secret, api, local_mode, backoff_mult = 10)
25
+ def initialize(server_secret, options, backoff_mult = 10)
26
26
  super()
27
+ api = options.api_url_base
27
28
  unless api.end_with?('/')
28
29
  api += '/'
29
30
  end
30
31
  @server_secret = server_secret
31
32
  @api = api
32
- @local_mode = local_mode
33
+ @local_mode = options.local_mode
34
+ @timeout = options.network_timeout
33
35
  @backoff_multiplier = backoff_mult
34
36
  @session_id = SecureRandom.uuid
35
37
  end
@@ -52,6 +54,9 @@ module Statsig
52
54
  "STATSIG-SDK-TYPE" => meta['sdkType'],
53
55
  "STATSIG-SDK-VERSION" => meta['sdkVersion'],
54
56
  }).accept(:json)
57
+ if @timeout
58
+ http = http.timeout(@timeout)
59
+ end
55
60
  begin
56
61
  res = http.post(@api + endpoint, body: body)
57
62
  rescue StandardError => e
data/lib/spec_store.rb CHANGED
@@ -8,8 +8,6 @@ require 'concurrent-ruby'
8
8
  module Statsig
9
9
  class SpecStore
10
10
 
11
- CONFIG_SPECS_KEY = "statsig.cache"
12
-
13
11
  attr_accessor :last_config_sync_time
14
12
  attr_accessor :initial_config_sync_time
15
13
  attr_accessor :init_reason
@@ -133,7 +131,7 @@ module Statsig
133
131
  private
134
132
 
135
133
  def load_from_storage_adapter
136
- cached_values = @options.data_store.get(CONFIG_SPECS_KEY)
134
+ cached_values = @options.data_store.get(Interfaces::IDataStore::CONFIG_SPECS_KEY)
137
135
  if cached_values.nil?
138
136
  return
139
137
  end
@@ -145,14 +143,18 @@ module Statsig
145
143
  if @options.data_store.nil?
146
144
  return
147
145
  end
148
- @options.data_store.set(CONFIG_SPECS_KEY, specs_string)
146
+ @options.data_store.set(Interfaces::IDataStore::CONFIG_SPECS_KEY, specs_string)
149
147
  end
150
148
 
151
149
  def sync_config_specs
152
150
  Thread.new do
153
151
  loop do
154
152
  sleep @options.rulesets_sync_interval
155
- download_config_specs
153
+ if @options.data_store&.should_be_used_for_querying_updates(Interfaces::IDataStore::CONFIG_SPECS_KEY)
154
+ load_from_storage_adapter
155
+ else
156
+ download_config_specs
157
+ end
156
158
  end
157
159
  end
158
160
  end
@@ -36,7 +36,7 @@ class StatsigDriver
36
36
  @options = options || StatsigOptions.new
37
37
  @shutdown = false
38
38
  @secret_key = secret_key
39
- @net = Statsig::Network.new(secret_key, @options.api_url_base, @options.local_mode)
39
+ @net = Statsig::Network.new(secret_key, @options)
40
40
  @logger = Statsig::StatsigLogger.new(@net, @options)
41
41
  @evaluator = Statsig::Evaluator.new(@net, @options, error_callback, @init_diagnostics)
42
42
  @init_diagnostics.mark("overall", "end")
@@ -75,6 +75,10 @@ class StatsigOptions
75
75
  # default: false
76
76
  attr_accessor :disable_sorbet_logging_handlers
77
77
 
78
+ sig { returns(T.any(Integer, NilClass)) }
79
+ # Number of seconds before a network call is timed out
80
+ attr_accessor :network_timeout
81
+
78
82
  sig do
79
83
  params(
80
84
  environment: T.any(T::Hash[String, String], NilClass),
@@ -89,7 +93,8 @@ class StatsigOptions
89
93
  data_store: T.any(Statsig::Interfaces::IDataStore, NilClass),
90
94
  idlist_threadpool_size: Integer,
91
95
  disable_diagnostics_logging: T::Boolean,
92
- disable_sorbet_logging_handlers: T::Boolean
96
+ disable_sorbet_logging_handlers: T::Boolean,
97
+ network_timeout: T.any(Integer, NilClass)
93
98
  ).void
94
99
  end
95
100
 
@@ -106,7 +111,8 @@ class StatsigOptions
106
111
  data_store: nil,
107
112
  idlist_threadpool_size: 3,
108
113
  disable_diagnostics_logging: false,
109
- disable_sorbet_logging_handlers: false)
114
+ disable_sorbet_logging_handlers: false,
115
+ network_timeout: nil)
110
116
  @environment = environment.is_a?(Hash) ? environment : nil
111
117
  @api_url_base = api_url_base
112
118
  @rulesets_sync_interval = rulesets_sync_interval
@@ -120,5 +126,6 @@ class StatsigOptions
120
126
  @idlist_threadpool_size = idlist_threadpool_size
121
127
  @disable_diagnostics_logging = disable_diagnostics_logging
122
128
  @disable_sorbet_logging_handlers = disable_sorbet_logging_handlers
129
+ @network_timeout = network_timeout
123
130
  end
124
131
  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.21.0
4
+ version: 1.22.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: 2023-01-31 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 0.4.27
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: puma
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '6.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '6.0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: user_agent_parser
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -215,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
243
  - !ruby/object:Gem::Version
216
244
  version: '0'
217
245
  requirements: []
218
- rubygems_version: 3.4.1
246
+ rubygems_version: 3.3.7
219
247
  signing_key:
220
248
  specification_version: 4
221
249
  summary: Statsig server SDK for Ruby