alacrity-rails 0.1.1 → 0.2.0

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: 7c3c649968a43d9431fa8c353627d5738df24e05
4
- data.tar.gz: 4e337ca4057a990220e54c43577bdcc1a427edf0
3
+ metadata.gz: 453dd5ed4a8173cab3ccca146a1fa7827cc81d2e
4
+ data.tar.gz: 6959b45a643e9a7e8814af00710eb61a188abd97
5
5
  SHA512:
6
- metadata.gz: 01e088ce25d0f38bbd66daae94701a378c6ffee51a3f1f9f57ecd1f17dee1dcd798bf9c539db0b816239c1dc180a5af420a2e4b266f14d8c2ab45cfbe4735723
7
- data.tar.gz: b9cd184d6dfb2ce69773143febf7b89f4d7af603b17d10b0ded3ddbf5edae222a582e38739b2f47fd7b63829af7f9bb80b91a3943911e559854a97bb095e0553
6
+ metadata.gz: a284cb2d4c66c43244e0689f5499fc81cc96cdda869951b9266dbc1f744d5225f8ad7e1bf3975f272dd87bc3c4b8bb837573fd1d592ba475af769bf299c389e7
7
+ data.tar.gz: 9da624496779a56b6dd4b1db105fc97b975fef39368b9e443acdea6a4877d3dff7713c643b9a5ddb4b2d3c166c5462e08056ae594d32885225761ea05718de3e
@@ -12,7 +12,11 @@ module AlacrityRails
12
12
  autoload :VERSION, 'alacrity-rails/version'
13
13
 
14
14
  module Probe
15
- autoload :MongoDriver, 'alacrity-rails/probe/mongo_driver'
15
+ autoload :ActionController, 'alacrity-rails/probe/action_controller'
16
+ autoload :ActionView, 'alacrity-rails/probe/action_view'
17
+ autoload :ActiveModelSerializers, 'alacrity-rails/probe/active_model_serializers'
18
+ autoload :ActiveRecord, 'alacrity-rails/probe/active_record'
19
+ autoload :MongoDriver, 'alacrity-rails/probe/mongo_driver'
16
20
  end
17
21
 
18
22
  module Transaction
@@ -5,24 +5,12 @@ module AlacrityRails
5
5
  new_transaction!(env)
6
6
  end
7
7
 
8
- def self.store_request_metrics(started_at, ended_at, data)
9
- if transaction
10
- transaction.store_request_metrics(started_at, ended_at, data)
11
- end
12
- end
13
-
14
- def self.store_database_metrics(started_at, ended_at, data)
15
- if transaction
16
- transaction.store_database_metrics(started_at, ended_at, data)
17
- end
18
- end
19
-
20
- def self.store_serializer_metrics(started_at, ended_at, data)
21
- transaction&.store_serializer_metrics(started_at, ended_at, data)
8
+ def self.store_request(data)
9
+ transaction&.store_request(data)
22
10
  end
23
11
 
24
- def self.store_template_metrics(started_at, ended_at, data)
25
- transaction&.store_template_metrics(started_at, ended_at, data)
12
+ def self.store_timeline_event(data)
13
+ transaction&.store_timeline_event(data)
26
14
  end
27
15
 
28
16
  def self.close_transaction!
@@ -0,0 +1,18 @@
1
+ module AlacrityRails
2
+ module Probe
3
+ class ActionController
4
+ def self.activate
5
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |name, started, finished, unique_id, data|
6
+ AlacrityRails::Client.store_request(
7
+ started_at: started,
8
+ finished_at: finished,
9
+ controller: data[:controller],
10
+ action: data[:action],
11
+ format: data[:format],
12
+ status: data[:status]
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module AlacrityRails
2
+ module Probe
3
+ class ActionView
4
+ def self.activate
5
+ ActiveSupport::Notifications.subscribe 'render_partial.action_view' do |name, started, finished, unique_id, data|
6
+ AlacrityRails::Client.store_timeline_event(
7
+ name: 'Template',
8
+ event_type: 'template',
9
+ engine: 'ActionView',
10
+ started_at: started,
11
+ finished_at: finished,
12
+ detail: data[:identifier]
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module AlacrityRails
2
+ module Probe
3
+ class ActiveModelSerializers
4
+ def self.activate
5
+ ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |name, started, finished, unique_id, data|
6
+ AlacrityRails::Client.store_timeline_event(
7
+ name: 'Template',
8
+ event_type: 'template',
9
+ engine: 'ActiveModel::Serializers',
10
+ started_at: started,
11
+ finished_at: finished,
12
+ detail: data[:serializer].to_s
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module AlacrityRails
2
+ module Probe
3
+ class ActiveRecord
4
+ def self.activate
5
+ ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, started, finished, unique_id, data|
6
+ AlacrityRails::Client.store_timeline_event(
7
+ name: data[:name],
8
+ event_type: 'database',
9
+ engine: 'ActiveRecord',
10
+ started_at: started,
11
+ finished_at: finished,
12
+ detail: data[:sql]
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,6 +1,12 @@
1
1
  module AlacrityRails
2
2
  module Probe
3
3
  class MongoDriver
4
+ def self.activate
5
+ if defined?(Mongo)
6
+ Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::COMMAND, new)
7
+ end
8
+ end
9
+
4
10
  def start_events
5
11
  @start_events ||= {}
6
12
  end
@@ -18,15 +24,24 @@ module AlacrityRails
18
24
  command[key] = value.respond_to?(:keys) ? value.keys : value
19
25
  end
20
26
 
21
- data = {
22
- name: "#{event.database_name}.#{event.command_name}",
23
- sql: command.to_s
24
- }
25
- AlacrityRails::Client.store_database_metrics(start_event[:started_at], finished, data)
27
+ store(event.command_name, start_event[:started_at], finished, command)
26
28
  rescue => error
27
29
  Logger.error("Alacrity mongo driver tracking failed: #{error.inspect}")
28
30
  end
29
31
  alias failed succeeded
32
+
33
+ protected
34
+
35
+ def store(command_name, started_at, finished_at, command)
36
+ AlacrityRails::Client.store_timeline_event(
37
+ name: command_name,
38
+ event_type: 'database',
39
+ engine: 'Mongo',
40
+ started_at: started_at,
41
+ finished_at: finished_at,
42
+ detail: command.to_s
43
+ )
44
+ end
30
45
  end
31
46
  end
32
47
  end
@@ -6,25 +6,13 @@ module AlacrityRails
6
6
 
7
7
  config.middleware.insert_before 0, AlacrityRails::Middleware
8
8
 
9
- ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, started, finished, unique_id, data|
10
- AlacrityRails::Client.store_database_metrics(started, finished, data)
11
- end
12
-
13
- ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |name, started, finished, unique_id, data|
14
- AlacrityRails::Client.store_request_metrics(started, finished, data)
15
- end
16
-
17
- if defined?(Mongo)
18
- Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::COMMAND, AlacrityRails::Probe::MongoDriver.new)
19
- end
20
-
21
- ActiveSupport::Notifications.subscribe 'render.active_model_serializers' do |name, started, finished, unique_id, data|
22
- AlacrityRails::Client.store_serializer_metrics(started, finished, data)
23
- end
24
-
25
- ActiveSupport::Notifications.subscribe 'render_partial.action_view' do |name, started, finished, unique_id, data|
26
- AlacrityRails::Client.store_template_metrics(started, finished, data)
27
- end
9
+ [
10
+ Probe::ActionController,
11
+ Probe::ActionView,
12
+ Probe::ActiveModelSerializers,
13
+ Probe::ActiveRecord,
14
+ Probe::MongoDriver
15
+ ].each(&:activate)
28
16
  end
29
17
  end
30
18
  end
@@ -9,42 +9,23 @@ module AlacrityRails::Transaction
9
9
  self.method = env['REQUEST_METHOD']
10
10
  end
11
11
 
12
- def store_database_metrics(started_at, finished_at, data)
13
- timeline_events << {
14
- name: data[:name],
15
- event_type: 'database',
16
- started_at: absolute_time(started_at.to_datetime),
17
- finished_at: absolute_time(finished_at.to_datetime),
18
- detail: data[:sql]
19
- }
20
- end
21
-
22
- def store_request_metrics(started_at, finished_at, data)
23
- self.framework_started_at = absolute_time(started_at.to_datetime)
24
- self.framework_finished_at = absolute_time(finished_at.to_datetime)
12
+ def store_request(data)
13
+ self.framework_started_at = absolute_time(data[:started_at].to_datetime)
14
+ self.framework_finished_at = absolute_time(data[:finished_at].to_datetime)
25
15
  self.controller = data[:controller]
26
16
  self.action = data[:action]
27
17
  self.format = data[:format]
28
18
  self.status = data[:status]
29
19
  end
30
20
 
31
- def store_serializer_metrics(started_at, finished_at, data)
21
+ def store_timeline_event(data)
32
22
  timeline_events << {
33
- name: 'Template',
34
- event_type: 'template',
35
- started_at: absolute_time(started_at.to_datetime),
36
- finished_at: absolute_time(finished_at.to_datetime),
37
- detail: data[:serializer].to_s
38
- }
39
- end
40
-
41
- def store_template_metrics(started_at, finished_at, data)
42
- timeline_events << {
43
- name: 'Template',
44
- event_type: 'template',
45
- started_at: absolute_time(started_at.to_datetime),
46
- finished_at: absolute_time(finished_at.to_datetime),
47
- detail: data[:identifier]
23
+ name: data[:name],
24
+ event_type: data[:event_type],
25
+ engine: data[:engine],
26
+ started_at: absolute_time(data[:started_at].to_datetime),
27
+ finished_at: absolute_time(data[:finished_at].to_datetime),
28
+ detail: data[:detail]
48
29
  }
49
30
  end
50
31
 
@@ -1,3 +1,3 @@
1
1
  module AlacrityRails
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alacrity-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alacrity, LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,6 +39,10 @@ files:
39
39
  - lib/alacrity-rails/config.rb
40
40
  - lib/alacrity-rails/connection_tester.rb
41
41
  - lib/alacrity-rails/middleware.rb
42
+ - lib/alacrity-rails/probe/action_controller.rb
43
+ - lib/alacrity-rails/probe/action_view.rb
44
+ - lib/alacrity-rails/probe/active_model_serializers.rb
45
+ - lib/alacrity-rails/probe/active_record.rb
42
46
  - lib/alacrity-rails/probe/mongo_driver.rb
43
47
  - lib/alacrity-rails/railtie.rb
44
48
  - lib/alacrity-rails/server_config.rb