prefab-cloud-ruby 0.14.0 → 0.15.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: 2fef66a6ac50710f11854f9168c30573ef3fea74acd9089308d1a70ac754f584
4
- data.tar.gz: 7b424813748667165d263f0869cf0a93c56d9f0fdafe60f22799b358f3f5688a
3
+ metadata.gz: 56f869e526c34a5e949e257b7d3bad480e9bfc35a32c228c00edf27bd1ffd0e1
4
+ data.tar.gz: 34e5775b22b085295618be7f9c411923d3b643e16032ee70c7dc6340fed6009b
5
5
  SHA512:
6
- metadata.gz: 03d9230267363cc51962c3a244f39cc9b6e6bda7da3c6e9b460ed195330d3035840f69fc2837f66b86a4c05d6b830a14db56aee4578fa5e13e580c7be89fa6c8
7
- data.tar.gz: 1b084b6f4b8180069a214a6edcaeb5d23c1afb234f5161870a6b11d5d2841a1d05683f65eeb94c9cd6b92cd02d70296e2abb9d430d2f1c6143ee2d0224ae3b85
6
+ metadata.gz: d5ce5a0a3c1dc3d0d8e258da5da8cd9f12975d8232c0775a39a205cbfb464074bf0fda9c7467d5bdbc4d04a4020d48aa68a816eaf1714ea5c3863a299178b2ac
7
+ data.tar.gz: 5123db89a4947143ceff5e29f30cd655870193c6ec8afaa7eca9f2fb85d61c1da2eae18a1fd31fbd3ae5c580a4e438c93c330ecb54fffdaf05b94259b6dc96ec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.14.0
1
+ 0.15.0
data/lib/prefab/client.rb CHANGED
@@ -5,7 +5,7 @@ module Prefab
5
5
  BASE_SLEEP_SEC = 0.5
6
6
  NO_DEFAULT_PROVIDED = :no_default_provided
7
7
 
8
- attr_reader :project_id, :shared_cache, :stats, :namespace, :interceptor, :api_key, :prefab_api_url, :options
8
+ attr_reader :shared_cache, :stats, :namespace, :interceptor, :api_key, :prefab_api_url, :options
9
9
 
10
10
  def initialize(options = Prefab::Options.new)
11
11
  @options = options
@@ -15,12 +15,10 @@ module Prefab
15
15
  @stubs = {}
16
16
 
17
17
  if @options.local_only?
18
- @project_id = 0
19
18
  log_internal Logger::INFO, "Prefab Running in Local Mode"
20
19
  else
21
20
  @api_key = @options.api_key
22
- raise Prefab::Errors::InvalidApiKeyError.new(@api_key) if @api_key.nil? || @api_key.empty? || api_key.count("-") != 3
23
- @project_id = @api_key.split("-")[0].to_i # unvalidated, but that's ok. APIs only listen to the actual passwd
21
+ raise Prefab::Errors::InvalidApiKeyError.new(@api_key) if @api_key.nil? || @api_key.empty? || api_key.count("-") < 1
24
22
  @interceptor = Prefab::AuthInterceptor.new(@api_key)
25
23
  @prefab_api_url = @options.prefab_api_url
26
24
  @prefab_grpc_url = @options.prefab_grpc_url
@@ -82,10 +80,6 @@ module Prefab
82
80
  end
83
81
  end
84
82
 
85
- def cache_key(post_fix)
86
- "prefab:#{project_id}:#{post_fix}"
87
- end
88
-
89
83
  def reset!
90
84
  @stubs.clear
91
85
  @_channel = nil
@@ -6,6 +6,7 @@ module Prefab
6
6
  RECONNECT_WAIT = 5
7
7
  DEFAULT_CHECKPOINT_FREQ_SEC = 60
8
8
  SSE_READ_TIMEOUT = 300
9
+ AUTH_USER = "authuser"
9
10
 
10
11
  def initialize(base_client, timeout)
11
12
  @base_client = base_client
@@ -149,14 +150,14 @@ module Prefab
149
150
 
150
151
  def load_checkpoint_api_cdn
151
152
  key_hash = Murmur3.murmur3_32(@base_client.api_key)
152
- url = "#{@options.url_for_api_cdn}/api/v1/configs/#{@base_client.project_id}/#{key_hash}/0"
153
+ url = "#{@options.url_for_api_cdn}/api/v1/configs/0/#{key_hash}/0"
153
154
  conn = if Faraday::VERSION[0].to_i >= 2
154
155
  Faraday.new(url) do |conn|
155
- conn.request :authorization, :basic, @base_client.project_id, @base_client.api_key
156
+ conn.request :authorization, :basic, AUTH_USER, @base_client.api_key
156
157
  end
157
158
  else
158
159
  Faraday.new(url) do |conn|
159
- conn.request :basic_auth, @base_client.project_id, @base_client.api_key
160
+ conn.request :basic_auth, AUTH_USER, @base_client.api_key
160
161
  end
161
162
  end
162
163
  load_url(conn, :remote_cdn_api)
@@ -178,6 +179,7 @@ module Prefab
178
179
  end
179
180
 
180
181
  def load_configs(configs, source)
182
+ project_id = configs.config_service_pointer.project_id
181
183
  project_env_id = configs.config_service_pointer.project_env_id
182
184
  @config_resolver.project_env_id = project_env_id
183
185
  starting_highwater_mark = @config_loader.highwater_mark
@@ -186,7 +188,7 @@ module Prefab
186
188
  @config_loader.set(config, source)
187
189
  end
188
190
  if @config_loader.highwater_mark > starting_highwater_mark
189
- @base_client.log_internal Logger::INFO, "Found new checkpoint with highwater id #{@config_loader.highwater_mark} from #{source} in project #{@base_client.project_id} environment: #{project_env_id} and namespace: '#{@namespace}'"
191
+ @base_client.log_internal Logger::INFO, "Found new checkpoint with highwater id #{@config_loader.highwater_mark} from #{source} in project #{project_id} environment: #{project_env_id} and namespace: '#{@namespace}'"
190
192
  else
191
193
  @base_client.log_internal Logger::DEBUG, "Checkpoint with highwater id #{@config_loader.highwater_mark} from #{source}. No changes.", "prefab.config_client.load_configs"
192
194
  end
@@ -225,7 +227,7 @@ module Prefab
225
227
  end
226
228
 
227
229
  def start_sse_streaming_connection_thread(start_at_id)
228
- auth = "#{@base_client.project_id}:#{@base_client.api_key}"
230
+ auth = "#{AUTH_USER}:#{@base_client.api_key}"
229
231
  auth_string = Base64.strict_encode64(auth)
230
232
  headers = {
231
233
  "x-prefab-start-at-id": start_at_id,
@@ -116,7 +116,7 @@ module Prefab
116
116
  end
117
117
 
118
118
  def get_user_pct(feature, lookup_key)
119
- to_hash = "#{@base_client.project_id}#{feature}#{lookup_key}"
119
+ to_hash = "#{feature}#{lookup_key}"
120
120
  int_value = Murmur3.murmur3_32(to_hash)
121
121
  int_value / MAX_32_FLOAT
122
122
  end
@@ -19,7 +19,7 @@ module Prefab
19
19
  end
20
20
 
21
21
  def add_internal(severity, message = nil, progname = nil, loc, &block)
22
- path = get_path(loc.absolute_path, loc.base_label)
22
+ path = get_loc_path(loc)
23
23
  log_internal(message, path, progname, severity, &block)
24
24
  end
25
25
 
@@ -121,15 +121,19 @@ module Prefab
121
121
  val(closest_log_level_match)
122
122
  end
123
123
 
124
+ def get_loc_path(loc)
125
+ loc_path = loc.absolute_path || loc.to_s
126
+ get_path(loc_path, loc.base_label)
127
+ end
128
+
124
129
  # sanitize & clean the path of the caller so the key
125
130
  # looks like log_level.app.models.user
126
131
  def get_path(absolute_path, base_label)
127
132
  path = (absolute_path || UNKNOWN).dup
128
133
  path.slice! Dir.pwd
134
+ path.gsub!(/(.*)?(?=\/lib)/im, "") # replace everything before first lib
129
135
 
130
- path.gsub!(/.*?(?=\/lib\/)/im, "")
131
-
132
- path = path.gsub("/", SEP).gsub(".rb", "") + SEP + base_label
136
+ path = path.gsub("/", SEP).gsub(/.rb.*/, "") + SEP + base_label
133
137
  path.slice! ".lib"
134
138
  path.slice! SEP
135
139
  path
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: prefab-cloud-ruby 0.14.0 ruby lib
5
+ # stub: prefab-cloud-ruby 0.15.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.14.0"
9
+ s.version = "0.15.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2022-08-15"
14
+ s.date = "2022-08-28"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -37,10 +37,10 @@ class TestFeatureFlagClient < Minitest::Test
37
37
  # weights above chosen to be 86% in variant_idx 2. and 14% in variant_idx 1.
38
38
  # since hashes high is 86.32 > 86 it just falls outside the 86% range and gets false
39
39
 
40
- # "1FlagNamehashes high" hashes to 86.322% through dist
40
+ # "FlagNamevery high hash" hashes to 88.8602812% through dist
41
41
  assert_equal false,
42
- evaluate(feature, "hashes high", [], flag, variants)
43
- # "1FlagNamehashes low" hashes to 44.547% through dist
42
+ evaluate(feature, "very high hash", [], flag, variants)
43
+ # "FlagNamehashes low" hashes to 42.7934% through dist
44
44
  assert_equal true,
45
45
  evaluate(feature, "hashes low", [], flag, variants)
46
46
 
data/test/test_logger.rb CHANGED
@@ -4,6 +4,7 @@ require 'test_helper'
4
4
  class TestCLogger < Minitest::Test
5
5
  def setup
6
6
  Prefab::LoggerClient.send(:public, :get_path)
7
+ Prefab::LoggerClient.send(:public, :get_loc_path)
7
8
  Prefab::LoggerClient.send(:public, :level_of)
8
9
  @logger = Prefab::LoggerClient.new($stdout)
9
10
  end
@@ -16,6 +17,27 @@ class TestCLogger < Minitest::Test
16
17
  assert_equal "active_support.log_subscriber.info",
17
18
  @logger.get_path("/Users/jdwyah/.rvm/gems/ruby-2.3.3@forcerank/gems/activesupport-4.1.16/lib/active_support/log_subscriber.rb",
18
19
  "info")
20
+ assert_equal "active_support.log_subscriber.info",
21
+ @logger.get_path("/Users/jeffdwyer/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.4/lib/active_support/log_subscriber.rb:130:in `info'",
22
+ "info")
23
+ end
24
+
25
+ def test_loc_resolution
26
+ backtrace_location = Struct.new(:absolute_path, :base_label, :string) do
27
+ def to_s
28
+ string
29
+ end
30
+ end # https://ruby-doc.org/core-3.0.0/Thread/Backtrace/Location.html
31
+
32
+ # verify that even if the Thread::Backtrace::Location does not have an absolute_location, we do our best
33
+ assert_equal "active_support.log_subscriber.info",
34
+ @logger.get_loc_path(backtrace_location.new(nil,
35
+ "info",
36
+ "/Users/jeffdwyer/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.4/lib/active_support/log_subscriber.rb:130:in `info'"))
37
+ assert_equal "test_l.info",
38
+ @logger.get_loc_path(backtrace_location.new("/Users/jdwyah/Documents/workspace/RateLimitInc/prefab-cloud-ruby/lib/test_l.rb",
39
+ "info",
40
+ "/Users/jeffdwyer/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.4/lib/active_support/log_subscriber.rb:130:in `info'"))
19
41
  end
20
42
 
21
43
  def test_level_of
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prefab-cloud-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-15 00:00:00.000000000 Z
11
+ date: 2022-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby