ff-ruby-server-sdk 1.4.5 → 1.4.7
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 +4 -4
- data/docs/further_reading.md +3 -2
- data/example/getting_started/getting_started.rb +2 -0
- data/lib/ff/ruby/server/sdk/api/cf_client.rb +13 -5
- data/lib/ff/ruby/server/sdk/api/inner_client.rb +10 -5
- data/lib/ff/ruby/server/sdk/api/metrics_processor.rb +16 -9
- data/lib/ff/ruby/server/sdk/version.rb +1 -1
- data/scripts/sdk_specs.sh +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ceb06b99a2e2c3f2f6d1aa0d266287d0975e0284ee31707589240f607b894a0
|
|
4
|
+
data.tar.gz: 3ed9e32ef921a2e67be053769dcb2176e27728c07438199fa753a04f4be12817
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d45cf7ef2677ccedd2e612d349fef80a26cdcd020eb2cc24eb5969b4852ac5b8023216753dae778eb38657ab7801c25c5393cbc636d5c35b457a101969129c2
|
|
7
|
+
data.tar.gz: 8c9455611a21ba09fa95e09617461ee49f63a844b51f646e30d1d339fb6843afa8fcbed54e87a7bc84fbe86679969cbdc842d85461a204b6ed5a54cf9a435abf
|
data/docs/further_reading.md
CHANGED
|
@@ -96,11 +96,12 @@ client.init(apiKey, ConfigBuilder.new.logger(logger).build)
|
|
|
96
96
|
|
|
97
97
|
The Public API exposes a few methods that you can utilize:
|
|
98
98
|
|
|
99
|
-
Instantiate, initialize and close when done:
|
|
99
|
+
Instantiate, initialize, check if initialized and close when done:
|
|
100
100
|
|
|
101
101
|
* `def initialize(api_key = nil, config = nil, connector = nil)`
|
|
102
|
+
* `def initialized`
|
|
102
103
|
* `def init(api_key = nil, config = nil, connector = nil)`
|
|
103
|
-
* `def wait_for_initialization`
|
|
104
|
+
* `def wait_for_initialization(timeout: nil)`
|
|
104
105
|
* `def close`
|
|
105
106
|
|
|
106
107
|
Evaluations:
|
|
@@ -24,8 +24,10 @@ client = CfClient.instance
|
|
|
24
24
|
client.init(apiKey, ConfigBuilder.new.logger(logger).build)
|
|
25
25
|
|
|
26
26
|
logger.info "----- initialization started ----- "
|
|
27
|
+
logger.info "initialised: #{client.initialized}"
|
|
27
28
|
client.wait_for_initialization
|
|
28
29
|
logger.info "----- initialization done ----- "
|
|
30
|
+
logger.info "initialised: #{client.initialized}"
|
|
29
31
|
|
|
30
32
|
# Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
|
|
31
33
|
target = Target.new("RubySDK", identifier="rubysdk", attributes={"location": "emea"})
|
|
@@ -5,13 +5,17 @@ require_relative "inner_client"
|
|
|
5
5
|
|
|
6
6
|
class CfClient < Closeable
|
|
7
7
|
include Singleton
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
@@instance_mutex = Mutex.new
|
|
9
10
|
def init(api_key, config, connector = nil)
|
|
10
11
|
# Only initialize if @client is nil to avoid reinitialization
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
@client
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
@@instance_mutex.synchronize do
|
|
14
|
+
unless @client
|
|
15
|
+
@config = config || ConfigBuilder.new.build
|
|
16
|
+
@client = InnerClient.new(api_key, @config, connector)
|
|
17
|
+
@config.logger.debug "Client initialized with API key: #{api_key}"
|
|
18
|
+
end
|
|
15
19
|
end
|
|
16
20
|
@client
|
|
17
21
|
end
|
|
@@ -43,6 +47,10 @@ def wait_for_initialization(timeout_ms: nil)
|
|
|
43
47
|
@client.json_variation(identifier, target, default_value)
|
|
44
48
|
end
|
|
45
49
|
|
|
50
|
+
def initialized
|
|
51
|
+
@client.initialized
|
|
52
|
+
end
|
|
53
|
+
|
|
46
54
|
def destroy
|
|
47
55
|
|
|
48
56
|
close
|
|
@@ -98,6 +98,10 @@ class InnerClient < ClientCallback
|
|
|
98
98
|
@evaluator.json_variation(identifier, target, default_value, @evaluator_callback)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
+
def initialized
|
|
102
|
+
@initialized
|
|
103
|
+
end
|
|
104
|
+
|
|
101
105
|
def on_auth_success
|
|
102
106
|
|
|
103
107
|
SdkCodes::info_sdk_auth_ok @config.logger
|
|
@@ -120,9 +124,11 @@ class InnerClient < ClientCallback
|
|
|
120
124
|
end
|
|
121
125
|
|
|
122
126
|
def on_auth_failed
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
@my_mutex.synchronize do
|
|
128
|
+
SdkCodes::warn_auth_failed_srv_defaults @config.logger
|
|
129
|
+
@initialized = true
|
|
130
|
+
@condition.broadcast
|
|
131
|
+
end
|
|
126
132
|
end
|
|
127
133
|
|
|
128
134
|
def close
|
|
@@ -243,7 +249,7 @@ class InnerClient < ClientCallback
|
|
|
243
249
|
|
|
244
250
|
SdkCodes.info_sdk_init_ok @config.logger
|
|
245
251
|
|
|
246
|
-
@condition.
|
|
252
|
+
@condition.broadcast
|
|
247
253
|
@initialized = true
|
|
248
254
|
end
|
|
249
255
|
end
|
|
@@ -257,7 +263,6 @@ class InnerClient < ClientCallback
|
|
|
257
263
|
remaining = timeout ? timeout / 1000.0 : nil # Convert timeout to seconds
|
|
258
264
|
|
|
259
265
|
until @initialized
|
|
260
|
-
|
|
261
266
|
# Break if timeout has elapsed
|
|
262
267
|
if remaining && remaining <= 0
|
|
263
268
|
@config.logger.warn "The SDK has timed out waiting to initialize with supplied timeout #{timeout} ms. The SDK will continue to initialize in the background. Default variations will be served until the SDK initializes."
|
|
@@ -44,13 +44,12 @@ class MetricsProcessor < Closeable
|
|
|
44
44
|
@metric_maps_mutex = Mutex.new
|
|
45
45
|
@evaluation_metrics = {}
|
|
46
46
|
@target_metrics = {}
|
|
47
|
+
@target_metrics_max_payload = 1000
|
|
47
48
|
|
|
48
49
|
# Keep track of targets that have already been sent to avoid sending them again. We track a max 500K targets
|
|
49
50
|
# to prevent unbounded growth.
|
|
50
51
|
@seen_targets_mutex = Mutex.new
|
|
51
52
|
@seen_targets = Set.new
|
|
52
|
-
@max_seen_targets = 500000
|
|
53
|
-
@seen_targets_full = false
|
|
54
53
|
|
|
55
54
|
# Mutex to protect aggregation and sending metrics at the end of an interval
|
|
56
55
|
@send_data_mutex = Mutex.new
|
|
@@ -110,22 +109,30 @@ class MetricsProcessor < Closeable
|
|
|
110
109
|
return if target.is_private
|
|
111
110
|
|
|
112
111
|
add_to_target_metrics = @seen_targets_mutex.synchronize do
|
|
113
|
-
|
|
114
|
-
if @seen_targets_full
|
|
115
|
-
true
|
|
116
|
-
elsif @seen_targets.include?(target.identifier)
|
|
112
|
+
if @seen_targets.include?(target.identifier)
|
|
117
113
|
false
|
|
118
114
|
else
|
|
119
115
|
@seen_targets.add(target.identifier)
|
|
120
|
-
@seen_targets_full = @seen_targets.size >= @max_seen_targets
|
|
121
116
|
true
|
|
122
117
|
end
|
|
123
118
|
end
|
|
124
119
|
|
|
125
120
|
# Add to target_metrics if marked for inclusion
|
|
126
|
-
@metric_maps_mutex.synchronize do
|
|
127
|
-
@target_metrics
|
|
121
|
+
dropped = @metric_maps_mutex.synchronize do
|
|
122
|
+
if @target_metrics.size < @target_metrics_max_payload
|
|
123
|
+
@target_metrics[target.identifier] = target
|
|
124
|
+
false
|
|
125
|
+
else
|
|
126
|
+
true
|
|
127
|
+
end
|
|
128
128
|
end if add_to_target_metrics
|
|
129
|
+
|
|
130
|
+
# If we had to drop the target, remove it from the seen list too, assume it will be readded later
|
|
131
|
+
# avoids a situation where targets were marked seen but never really sent
|
|
132
|
+
@seen_targets_mutex.synchronize do
|
|
133
|
+
@seen_targets.delete(target.identifier)
|
|
134
|
+
end if dropped
|
|
135
|
+
|
|
129
136
|
end
|
|
130
137
|
|
|
131
138
|
|
data/scripts/sdk_specs.sh
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ff-ruby-server-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- 'Miloš Vasić, cyr.: Милош Васић'
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rake
|
|
@@ -288,7 +287,6 @@ metadata:
|
|
|
288
287
|
homepage_uri: https://www.harness.io/
|
|
289
288
|
source_code_uri: https://github.com/harness/ff-ruby-server-sdk
|
|
290
289
|
changelog_uri: https://github.com/harness/ff-ruby-server-sdk/blob/main/CHANGELOG.md
|
|
291
|
-
post_install_message:
|
|
292
290
|
rdoc_options: []
|
|
293
291
|
require_paths:
|
|
294
292
|
- lib
|
|
@@ -304,8 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
304
302
|
- !ruby/object:Gem::Version
|
|
305
303
|
version: '0'
|
|
306
304
|
requirements: []
|
|
307
|
-
rubygems_version: 3.
|
|
308
|
-
signing_key:
|
|
305
|
+
rubygems_version: 3.6.9
|
|
309
306
|
specification_version: 4
|
|
310
307
|
summary: Harness is a feature management platform that helps teams to build better
|
|
311
308
|
software and to test features quicker.
|