mnemosyne-ruby 1.2.0 → 1.2.1

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: 9627e0a03b472040c3b65023a44f1e1cea612bf9
4
- data.tar.gz: f76fea84c479995a59b4151b752af13e6a3a33c5
3
+ metadata.gz: fb0d5bc4abf9f3fbf32db3c4b38176059b4b3041
4
+ data.tar.gz: 3c088755475af2fb3317d770dbdffb053971257c
5
5
  SHA512:
6
- metadata.gz: 3ad571be34543f3de3437a05c1c9413f8c90be17153af484f0f3b6627c032ec455a73463452278438b44c85bcb3c92aa14800c1c355b0c307fd2e06d53bbc513
7
- data.tar.gz: 7ed59cb08efd1066173b08b32e2c0cf67c2e80cecbabd3a4fe504e1cb9e304f0f48472cada9cba9209f1f36052e3a7c0a11a2a919832d4b671e98987ebe9c429
6
+ metadata.gz: 83904f7bfc80eb52f9919df216d07302f6a134e517cd103c84c81450bf432f0ba6bf143f5a5b503357f5357f999f9a0285247050bad9a55a15ceda2e9d0c2129
7
+ data.tar.gz: 22d35f5acb70ac32b2dc7dac905116b0ea3c0aa06ac4d558764897e8c517bab5a12a9d174374bfa154ca974232e0c66f4fe6bdbea8f7e4267962b420164252a5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ * Improve AMQP connection recovery
6
+ * Fix dynamic probe loading
7
+
3
8
  ## 1.2.0
4
9
 
5
10
  * Collect response metadata in rack instrumentation
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'bunny'
3
4
 
4
5
  module Mnemosyne
5
6
  class Client
6
- attr_reader :connection
7
+ include ::Mnemosyne::Logging
7
8
 
8
9
  def initialize(config)
9
10
  @config = config
@@ -11,11 +12,11 @@ module Mnemosyne
11
12
 
12
13
  def connection
13
14
  @connection ||= begin
14
- @config.logger.info "[Mnemosyne] Connect to #{@config.server}..."
15
+ logger.info "[Mnemosyne] Connect to #{@config.server}..."
15
16
 
16
17
  connection = ::Bunny.new @config.amqp,
17
- logger: @config.logger,
18
- threaded: false
18
+ logger: logger,
19
+ heartbeat: :server
19
20
 
20
21
  connection.start
21
22
  connection
@@ -11,7 +11,6 @@ module Mnemosyne
11
11
  attr_reader :platform
12
12
  attr_reader :amqp
13
13
  attr_reader :exchange
14
- attr_reader :logger
15
14
  attr_reader :server
16
15
 
17
16
  def initialize(config) # rubocop:disable AbcSize
@@ -19,7 +18,6 @@ module Mnemosyne
19
18
  @application = config.fetch('application', nil).to_s.strip.freeze
20
19
  @enabled = config.fetch('enabled', true)
21
20
  @exchange = config.fetch('exchange', 'mnemosyne').to_s.freeze
22
- @logger = config.fetch('logger') { Logger.new(STDOUT) }
23
21
 
24
22
  hostname = config.fetch('hostname') { default_hostname }
25
23
  @hostname = hostname.to_s.strip.freeze
@@ -7,16 +7,15 @@ module Mnemosyne
7
7
  IDENT = :__mnemosyne_current_trace
8
8
  MUTEX = Mutex.new
9
9
 
10
- attr_reader :logger
10
+ include ::Mnemosyne::Logging
11
11
 
12
- def initialize(config:, client:, logger:)
12
+ def initialize(config:, client:)
13
13
  @client = client
14
14
  @config = config
15
- @logger = logger
16
15
 
17
16
  ::Mnemosyne::Probes.activate!
18
17
 
19
- logger.info 'Mnemosyne instrumenter started.'
18
+ logger.debug(Mnemosyne) { 'Instrumenter started' }
20
19
  end
21
20
 
22
21
  def current_trace
@@ -46,7 +45,7 @@ module Mnemosyne
46
45
  end
47
46
 
48
47
  def submit(trace)
49
- logger.debug { "Submit trace #{trace.uuid}" }
48
+ logger.debug(Mnemosyne) { "Submit trace #{trace.uuid}" }
50
49
 
51
50
  @client.call trace
52
51
  end
@@ -67,17 +66,12 @@ module Mnemosyne
67
66
  return @instance if @instance
68
67
 
69
68
  client = Client.new(config)
70
- logger = config.logger
71
69
 
72
- @instance = new(config: config, client: client, logger: logger)
70
+ @instance = new(config: config, client: client)
73
71
  end
74
72
  rescue => err
75
- message = "Unable to start instrumenter: #{err}"
76
-
77
- if config && config.respond_to?(:logger)
78
- config.logger.warn message
79
- else
80
- ::Kernel.warn message
73
+ ::Mnemosyne::Logging.logger.warn(Mnemosyne) do
74
+ "Unable to start instrumenter: #{err}"
81
75
  end
82
76
 
83
77
  raise
@@ -97,14 +91,6 @@ module Mnemosyne
97
91
  instrumenter.trace(*args)
98
92
  end
99
93
 
100
- def logger
101
- if (instrumenter = instance)
102
- instrumenter.logger
103
- else
104
- @logger ||= Logger.new($stdout)
105
- end
106
- end
107
-
108
94
  def current_trace
109
95
  return unless (instrumenter = instance)
110
96
  instrumenter.current_trace
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mnemosyne
4
+ module Logging
5
+ def logger
6
+ ::Mnemosyne::Logging.logger
7
+ end
8
+
9
+ class << self
10
+ attr_writer :logger
11
+
12
+ def logger
13
+ @logger ||= ::Logger.new($stdout).tap do |logger|
14
+ logger.level = ::Logger::INFO
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Mnemosyne
4
4
  class Probe
5
+ include ::Mnemosyne::Logging
6
+
5
7
  def install
6
8
  setup
7
9
 
@@ -14,9 +16,7 @@ module Mnemosyne
14
16
  end
15
17
  end
16
18
 
17
- ::Mnemosyne::Instrumenter.logger.debug do
18
- "Installed probe #{self.class.name}"
19
- end
19
+ logger.debug(Mnemosyne) { "Installed probe #{self.class.name}" }
20
20
  end
21
21
 
22
22
  def setup
@@ -11,6 +11,10 @@ module Mnemosyne
11
11
  registry.activate!
12
12
  end
13
13
 
14
+ def required(path)
15
+ registry.required(path)
16
+ end
17
+
14
18
  private
15
19
 
16
20
  def registry
@@ -27,7 +31,7 @@ module Kernel
27
31
  ret = require_without_mn(name)
28
32
 
29
33
  begin
30
- ::Mnemosyne::Probes.registry.required(name)
34
+ ::Mnemosyne::Probes.required(name)
31
35
  rescue Exception # rubocop:disable RescueException, HandleExceptions
32
36
  end
33
37
 
@@ -7,8 +7,9 @@ module Mnemosyne
7
7
  initializer 'mnemosyne.initialize' do |app|
8
8
  config = app.config_for('mnemosyne')
9
9
 
10
+ ::Mnemosyne::Logging.logger = Rails.logger
11
+
10
12
  config['application'] ||= app.class.name.underscore.titleize
11
- config['logger'] ||= Rails.logger
12
13
 
13
14
  # If server is configured mnemosyne should be enabled by default
14
15
  config['enabled'] = config.key?('server') unless config.key?('enabled')
@@ -20,7 +21,7 @@ module Mnemosyne
20
21
 
21
22
  app.middleware.insert 0, ::Mnemosyne::Middleware::Rack
22
23
  else
23
- config.logger.warn '[MNEMOSYNE] Instrumenter not enabled.'
24
+ Rails.logger.warn(Mnemosyne) { 'Instrumentation disabled' }
24
25
  end
25
26
  end
26
27
  end
@@ -53,6 +53,12 @@ module Mnemosyne
53
53
  activate(registration) if activated?
54
54
  end
55
55
 
56
+ def required(path)
57
+ return unless activated?
58
+ return unless (set = monitor.delete(path))
59
+ set.each(&method(:activate))
60
+ end
61
+
56
62
  private
57
63
 
58
64
  attr_reader :monitor
@@ -67,19 +73,16 @@ module Mnemosyne
67
73
 
68
74
  class Monitor
69
75
  def initialize
70
- @requirements = {}
76
+ @requirements = Hash.new {|h, k| h[k] = Set.new }
71
77
  end
72
78
 
73
- def <<(registration)
74
- registration.require_paths.each do |path|
75
- @requirements[path] ||= []
76
- @requirements[path] << registration
77
- end
79
+ def delete(path)
80
+ @requirements.delete(path)
78
81
  end
79
82
 
80
- def delete(registration)
83
+ def <<(registration)
81
84
  registration.require_paths.each do |path|
82
- @requirements[path].delete(registration)
85
+ @requirements[path] << registration
83
86
  end
84
87
  end
85
88
  end
@@ -4,7 +4,7 @@ module Mnemosyne
4
4
  module VERSION
5
5
  MAJOR = 1
6
6
  MINOR = 2
7
- PATCH = 0
7
+ PATCH = 1
8
8
  STAGE = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
@@ -1 +1,4 @@
1
+ # rubocop:disable FileName
2
+ # frozen_string_literal: true
3
+
1
4
  require 'mnemosyne'
data/lib/mnemosyne.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'mnemosyne/version'
3
4
 
4
5
  require 'active_support'
@@ -6,6 +7,8 @@ require 'active_support/core_ext/object/blank'
6
7
  require 'active_support/notifications'
7
8
 
8
9
  module Mnemosyne
10
+ require 'mnemosyne/logging'
11
+
9
12
  require 'mnemosyne/global'
10
13
  extend Global
11
14
 
@@ -14,7 +14,9 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'http://github.com/jgraichen/mnemosyne-ruby'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
18
20
  spec.bindir = 'bin'
19
21
  spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
20
22
  spec.require_paths = %w(lib)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mnemosyne-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -131,6 +131,7 @@ files:
131
131
  - lib/mnemosyne/configuration.rb
132
132
  - lib/mnemosyne/global.rb
133
133
  - lib/mnemosyne/instrumenter.rb
134
+ - lib/mnemosyne/logging.rb
134
135
  - lib/mnemosyne/middleware/acfs.rb
135
136
  - lib/mnemosyne/middleware/rack.rb
136
137
  - lib/mnemosyne/middleware/sidekiq.rb
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  requirements: []
182
183
  rubyforge_project:
183
- rubygems_version: 2.6.11
184
+ rubygems_version: 2.6.13
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Ruby/Rails client for Mnemosynce