prefab-cloud-ruby 0.0.12 → 0.0.13

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
  SHA1:
3
- metadata.gz: b7493404ed66c944e4970a6c27a72082bdd7fe19
4
- data.tar.gz: bf00ac9c226101534c6121d8be551ba28554ab96
3
+ metadata.gz: 4e22f15bdc4f3f3d98d0a397e0685a7b457231cc
4
+ data.tar.gz: 3a1b5af166637f72160e1fdea3ed2f0d08aa2ded
5
5
  SHA512:
6
- metadata.gz: 66e77c6f6a6c099b2f5573621e763e6f1ec7266c48a3d1463d4422c8eda3ecf2fb9ef9d3aa0ad0da67993e2663254533254ed27b91bb334428886a7d467ba867
7
- data.tar.gz: 98afff75125328e9e97e611d4fb92132af3bd109b93246a369f498bec46f50591979bb5ab6d5ad0140b3a054f82c312a2efd8e65d89b79f68d5eb77f2c5f644e
6
+ metadata.gz: a94a74cc16025df1c4cf0cdf2a1a8b1aa1f7b501bb9aba66d7643ba643ed96f82b840adabed2f14a3038a5f10aac4641557869777da0cf56d842dfcb1e3d9e06
7
+ data.tar.gz: 9c659f681aa37174f81967e8a698fbf796f87c4d12bc647353e5e30b0266b6e6f0a127ace4fe342bb4d55c97fdf83957559ad95ff750c4b81310e6cd3a6957e5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
data/lib/prefab/client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Prefab
2
2
  class Client
3
- attr_reader :account_id, :shared_cache, :stats, :namespace, :logger, :creds, :interceptor
3
+ attr_reader :account_id, :shared_cache, :stats, :namespace, :creds, :interceptor
4
4
 
5
5
  def initialize(api_key: ENV['PREFAB_API_KEY'],
6
6
  logger: nil,
@@ -9,7 +9,7 @@ module Prefab
9
9
  local: false,
10
10
  namespace: ""
11
11
  )
12
- raise "No API key. Set PREFAB_API_KEY env var" if api_key.blank?
12
+ raise "No API key. Set PREFAB_API_KEY env var" if api_key.empty?
13
13
 
14
14
  @logger = (logger || Logger.new($stdout)).tap do |log|
15
15
  log.progname = "Prefab" if log.respond_to? :progname=
@@ -38,6 +38,8 @@ module Prefab
38
38
 
39
39
  def config_client(timeout: 5.0)
40
40
  @config_client ||= Prefab::ConfigClient.new(self, timeout)
41
+ @config_init = true
42
+ @config_client
41
43
  end
42
44
 
43
45
  def ratelimit_client(timeout: 5.0)
@@ -48,6 +50,11 @@ module Prefab
48
50
  @feature_flag_client ||= Prefab::FeatureFlagClient.new(self)
49
51
  end
50
52
 
53
+ def log(base_logger = @logger)
54
+ return @logger if !@config_init
55
+ @logger_client || Prefab::LoggerClient.new(self, base_logger)
56
+ end
57
+
51
58
  private
52
59
 
53
60
  def ssl_certs
@@ -60,7 +67,7 @@ module Prefab
60
67
  end
61
68
  ssl_certs
62
69
  rescue => e
63
- @logger.warn("Issue loading SSL certs #{e.message}")
70
+ log.warn("Issue loading SSL certs #{e.message}")
64
71
  ssl_certs
65
72
  end
66
73
 
@@ -29,6 +29,7 @@ module Prefab
29
29
  Retry.it method(:stub_with_timeout), :upsert, upsert_req, @timeout, method(:reset)
30
30
  @config_loader.set(config_delta)
31
31
  @config_loader.rm(previous_key) if previous_key&.present?
32
+ @config_resolver.update
32
33
  end
33
34
 
34
35
  def reset
@@ -76,14 +77,14 @@ module Prefab
76
77
  if checkpoint
77
78
  deltas = Prefab::ConfigDeltas.decode(checkpoint)
78
79
  deltas.deltas.each do |delta|
79
- @base_client.logger.debug "checkpoint set #{delta.key} #{delta.value.int} #{delta.value.string} #{delta.id} "
80
+ @base_client.log.debug "checkpoint set #{delta.key} #{delta.value.int} #{delta.value.string} #{delta.id} "
80
81
  @config_loader.set(delta)
81
82
  start_at_id = [delta.id, start_at_id].max
82
83
  end
83
- @base_client.logger.info "Found checkpoint with highwater id #{start_at_id}"
84
+ @base_client.log.info "Found checkpoint with highwater id #{start_at_id}"
84
85
  @config_resolver.update
85
86
  else
86
- @base_client.logger.info "No checkpoint"
87
+ @base_client.log.info "No checkpoint"
87
88
  end
88
89
 
89
90
  start_at_id
@@ -100,10 +101,10 @@ module Prefab
100
101
  sleep(delta)
101
102
  end
102
103
  deltas = @config_resolver.export_api_deltas
103
- @base_client.logger.debug "==CHECKPOINT==#{deltas.deltas.map {|d| d.id}.max}===#{Thread.current.object_id}=="
104
+ @base_client.log.debug "==CHECKPOINT==#{deltas.deltas.map {|d| d.id}.max}===#{Thread.current.object_id}=="
104
105
  @base_client.shared_cache.write(cache_key, Prefab::ConfigDeltas.encode(deltas))
105
106
  rescue StandardError => exn
106
- @base_client.logger.info "Issue Checkpointing #{exn.message}"
107
+ @base_client.log.info "Issue Checkpointing #{exn.message}"
107
108
  end
108
109
  end
109
110
  end
@@ -125,7 +126,7 @@ module Prefab
125
126
  @config_resolver.update
126
127
  end
127
128
  rescue => e
128
- @base_client.logger.info("config client encountered #{e.message} pausing #{RECONNECT_WAIT}")
129
+ @base_client.log.info("config client encountered #{e.message} pausing #{RECONNECT_WAIT}")
129
130
  reset
130
131
  sleep(RECONNECT_WAIT)
131
132
  end
@@ -154,7 +155,7 @@ module Prefab
154
155
  rescue GRPC::DeadlineExceeded
155
156
  # Ignore. This is a streaming endpoint, but we only need a single response
156
157
  rescue => e
157
- @base_client.logger.info "Suspenders encountered an issue #{e.message}"
158
+ @base_client.log.info "Suspenders encountered an issue #{e.message}"
158
159
  end
159
160
 
160
161
  delta = SUSPENDERS_FREQ_SEC - (Time.now - started_at)
@@ -6,7 +6,7 @@ module Prefab
6
6
  @local_store = {}
7
7
  @namespace = base_client.namespace
8
8
  @config_loader = config_loader
9
- @logger = base_client.logger
9
+ @logger = base_client.log
10
10
  make_local
11
11
  end
12
12
 
@@ -0,0 +1,57 @@
1
+ module Prefab
2
+ class LoggerClient
3
+
4
+ def initialize(base_client, base_logger)
5
+ @base_client = base_client
6
+ @base_logger = base_logger
7
+ end
8
+
9
+ def info msg
10
+ pf_log :info, msg, caller_locations(1, 1)[0]
11
+ end
12
+
13
+ def debug msg
14
+ pf_log :debug, msg, caller_locations(1, 1)[0]
15
+ end
16
+
17
+ def warn msg
18
+ pf_log :warn, msg, caller_locations(1, 1)[0]
19
+ end
20
+
21
+ def pf_log level, msg, loc
22
+ path = loc.absolute_path + ""
23
+ path.slice! Dir.pwd
24
+
25
+ path = "#{path.gsub("/", ":").gsub(".rb", "")}:#{loc.base_label}"
26
+ path.slice! ":"
27
+
28
+ base = "log_level"
29
+ closest_log_level_match = @base_client.config_client.get(base) || :warn
30
+ path.split(":").inject([base]) do |memo, n|
31
+ memo << n
32
+ val = @base_client.config_client.get memo.join(".")
33
+ unless val.nil?
34
+ closest_log_level_match = val
35
+ end
36
+ memo
37
+ end
38
+ if val(closest_log_level_match) <= val(level)
39
+ @base_logger.unknown "#{level.to_s.upcase.ljust(5)} #{path} #{msg}"
40
+ end
41
+ end
42
+
43
+ def val level
44
+ case level.to_sym
45
+ when :debug then
46
+ 1
47
+ when :info then
48
+ 2
49
+ when :warn then
50
+ 3
51
+ when :error then
52
+ 4
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -9,6 +9,7 @@ require 'prefab/client'
9
9
  require 'prefab/ratelimit_client'
10
10
  require 'prefab/config_client'
11
11
  require 'prefab/feature_flag_client'
12
+ require 'prefab/logger_client'
12
13
  require 'prefab/auth_interceptor'
13
14
  require 'prefab/noop_cache'
14
15
  require 'prefab/noop_stats'
@@ -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.0.12 ruby lib
5
+ # stub: prefab-cloud-ruby 0.0.13 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.0.12"
9
+ s.version = "0.0.13"
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 = "2018-02-04"
14
+ s.date = "2018-02-13"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/prefab/config_loader.rb",
33
33
  "lib/prefab/config_resolver.rb",
34
34
  "lib/prefab/feature_flag_client.rb",
35
+ "lib/prefab/logger_client.rb",
35
36
  "lib/prefab/murmer3.rb",
36
37
  "lib/prefab/noop_cache.rb",
37
38
  "lib/prefab/noop_stats.rb",
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.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-04 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -149,6 +149,7 @@ files:
149
149
  - lib/prefab/config_loader.rb
150
150
  - lib/prefab/config_resolver.rb
151
151
  - lib/prefab/feature_flag_client.rb
152
+ - lib/prefab/logger_client.rb
152
153
  - lib/prefab/murmer3.rb
153
154
  - lib/prefab/noop_cache.rb
154
155
  - lib/prefab/noop_stats.rb