librato-rails 1.2.0 → 1.3.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: 0ce2ae4e1528ebaf9d1a0530a44b359732605e58
4
- data.tar.gz: 651bd515fba4f8c855f7a7f192fa983ff8be48bf
3
+ metadata.gz: 8edc380bcb2f20518999f643e9c7d13174d84db6
4
+ data.tar.gz: da5c0130f153953623836aab0638a97f2ce4fc09
5
5
  SHA512:
6
- metadata.gz: 303a719b828e20520f08a3bc6bada5383cf2abf5a9c557862e50b6a31e9b089be404442ea701b9c8ae039ff59a433c578582ce81346fc8a87f37584699720e05
7
- data.tar.gz: fba27e56efb1cf238d145ea1bce403b8a23988905290b3e8486c74a05ab41c7bff3ea7b1c316ffc8272bde3367bb825ce3bdfd8dca2830972c33641cda8687d9
6
+ metadata.gz: de8fa725eb2a36317341c01b9ee6b4855a74e64cbcdb2840be949d3259b8a8c490fb15053721c7b558bc8beabde9f1d1bfedb1e50641eef0134eaf1e3fd9508b
7
+ data.tar.gz: 7e0f2ba4b6220a55d8597f12d95037e0d9a5981c527ea7ff550c4eb3989eb46e0ec6272fca60570817b45f59c046c16e5f1f25caa9bbc4184025aadad8f16538
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- "���R��'��/j�]
2
- �������4�Z�$fk[��S��Q�U�4�
3
- ���)���$F#
1
+ OU�'�C�d!���N'�v�b�@+j?-���2����/�hD�ٲ� �|������b��TSy�Po'�#����IJ1E7��k �Q���j7Z��l�<��I��e>�����=�o�%(9
2
+ f�\u�;�
3
+  ?��F��X�����'���9�Rn����[�_�)��Y�n�B�|l�74�鲜�B����G��l�.!���E����Vv+q�{RC���(�2��>j���A�j�)u*�|��}�nǍ�Ų�w
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### Version 1.3.0
2
+ * Add support for configurable metric suites
3
+
1
4
  ### Version 1.2.0
2
5
  * Allow use of Rails.application.secrets in the librato.yaml (Zack Siri)
3
6
 
data/README.md CHANGED
@@ -66,6 +66,48 @@ Note that if a config file is present, _all environment variables will be ignore
66
66
 
67
67
  For more information on combining config files and environment variables, see the [full configuration docs](https://github.com/librato/librato-rails/wiki/Configuration).
68
68
 
69
+ ##### Metric Suites
70
+
71
+ The metrics recorded by `librato-rails` are organized into named metric suites that can be selectively enabled/disabled:
72
+
73
+ * `rack`: The `rack.request.total`, `rack.request.time`, `rack.request.slow`, and `rack.request.queue.time` metrics
74
+ * `rack_status`: All of the `rack.request.status.*` metrics
75
+ * `rack_method`: All of the `rack.request.method.*` metrics
76
+ * `rails_action`: All of the `rails.action.*` metrics reported by the `instrument_action` helper
77
+ * `rails_cache`: All of the `rails.cache.*` metrics
78
+ * `rails_controller`: The `rails.request.total`, `rails.request.exceptions`, `rails.request.slow` and `rails.request.time.*` metrics
79
+ * `rails_job`: All of the `rails.job.*` metrics
80
+ * `rails_mail`: All of the `rails.mail.*` metrics
81
+ * `rails_method`: All of the `rails.request.method.*` metrics
82
+ * `rails_render`: All of the `rails.view.*` metrics
83
+ * `rails_sql`: All of the `rails.sql.*` metrics
84
+ * `rails_status`: All of the `rails.request.status.*` metrics
85
+
86
+ All of the metric suites listed above are enabled by default.
87
+
88
+ The metric suites can be configured via either the `LIBRATO_SUITES` environment variable or the `config/librato.yml` configuration file. The configuration syntax is the same regardless of which configuration method you use.
89
+
90
+ ```bash
91
+ LIBRATO_SUITES="rails_controller,rails_sql" # use ONLY the rails_controller and rails_sql suites
92
+ LIBRATO_SUITES="+foo,+bar" # + prefix indicates that you want the default suites plus foo and bar
93
+ LIBRATO_SUITES="-rails_render" # - prefix indicates that you want the default suites removing rails_render
94
+ LIBRATO_SUITES="+foo,-rack_status" # Use all default suites except for rack_status while also adding foo
95
+ LIBRATO_SUITES="all" # Enable all suites
96
+ LIBRATO_SUITES="none" # Disable all suites
97
+ LIBRATO_SUITES="" # Use only the default suites (same as if env var is absent)
98
+ ```
99
+
100
+ Note that you should EITHER specify an explict list of suites to enable OR add/subtract individual suites from the default list (using the +/- prefixes). If you try to mix these two forms a `Librato::Rack::InvalidSuiteConfiguration` error will be raised.
101
+
102
+ Configuring the metric suites via the `config/librato.yml` file would look like this:
103
+
104
+ ```yaml
105
+ production:
106
+ user: name@example.com
107
+ token: abc123
108
+ suites: 'all'
109
+ ```
110
+
69
111
  ##### Running on Heroku
70
112
 
71
113
  If you are using the Librato Heroku addon, your user and token environment variables will already be set in your Heroku environment. If you are running without the addon you will need to provide them yourself.
@@ -8,7 +8,9 @@ module Librato
8
8
  # https://github.com/librato/librato-rack/blob/master/lib/librato/rack/configuration.rb
9
9
  #
10
10
  class Configuration < Rack::Configuration
11
- CONFIG_SETTABLE = %w{user token flush_interval log_level prefix source source_pids proxy}
11
+ CONFIG_SETTABLE = %w{user token flush_interval log_level prefix source source_pids proxy suites}
12
+
13
+ DEFAULT_SUITES = [:rails_action, :rails_cache, :rails_controller, :rails_mail, :rails_method, :rails_render, :rails_sql, :rails_status, :rails_job]
12
14
 
13
15
  attr_accessor :config_by, :config_file
14
16
 
@@ -33,6 +35,7 @@ module Librato
33
35
  # respect autorun and log_level env vars regardless of config method
34
36
  self.autorun = detect_autorun
35
37
  self.log_level = :info if log_level.blank?
38
+ self.suites = '' if suites.nil?
36
39
  self.log_level = ENV['LIBRATO_LOG_LEVEL'] if ENV['LIBRATO_LOG_LEVEL']
37
40
  end
38
41
 
@@ -47,6 +50,10 @@ module Librato
47
50
  end
48
51
  end
49
52
 
53
+ def default_suites
54
+ super + DEFAULT_SUITES
55
+ end
56
+
50
57
  end
51
58
  end
52
59
  end
@@ -39,6 +39,19 @@ module Librato
39
39
  end
40
40
  end
41
41
 
42
+ tracker = config.librato_rails.tracker
43
+ require_relative 'subscribers/action' if tracker.suite_enabled?(:rails_action)
44
+ require_relative 'subscribers/cache' if tracker.suite_enabled?(:rails_cache)
45
+ require_relative 'subscribers/controller' if tracker.suite_enabled?(:rails_controller)
46
+ require_relative 'subscribers/mail' if tracker.suite_enabled?(:rails_mail)
47
+ require_relative 'subscribers/method' if tracker.suite_enabled?(:rails_method)
48
+ require_relative 'subscribers/render' if tracker.suite_enabled?(:rails_render)
49
+ require_relative 'subscribers/sql' if tracker.suite_enabled?(:rails_sql)
50
+ require_relative 'subscribers/status' if tracker.suite_enabled?(:rails_status)
51
+
52
+ Librato::Rails::VersionSpecifier.supported(min: '4.2') do
53
+ require_relative 'subscribers/job'if tracker.suite_enabled?(:rails_job)
54
+ end
42
55
  end
43
56
 
44
57
  end
@@ -11,16 +11,10 @@ module Librato
11
11
  @collector ||= Librato.tracker.collector
12
12
  end
13
13
 
14
+ def self.watch_controller_action(controller, action)
15
+ @watches ||= []
16
+ @watches << "#{controller}##{action}".freeze
17
+ end
14
18
  end
15
19
  end
16
20
  end
17
-
18
- require_relative 'subscribers/cache'
19
- require_relative 'subscribers/controller'
20
- require_relative 'subscribers/render'
21
- require_relative 'subscribers/sql'
22
- require_relative 'subscribers/mail'
23
-
24
- Librato::Rails::VersionSpecifier.supported(min: '4.2') do
25
- require_relative 'subscribers/job'
26
- end
@@ -0,0 +1,39 @@
1
+ module Librato
2
+ module Rails
3
+ module Subscribers
4
+
5
+ # Controller Actions
6
+
7
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
8
+
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ controller = event.payload[:controller]
11
+ action = event.payload[:action]
12
+
13
+ format = event.payload[:format] || "all"
14
+ format = "all" if format == "*/*"
15
+ exception = event.payload[:exception]
16
+
17
+ if @watches && @watches.index("#{controller}##{action}")
18
+ source = "#{controller}.#{action}.#{format}"
19
+ collector.group 'rails.action.request' do |r|
20
+
21
+ r.increment 'total', source: source
22
+ r.increment 'slow', source: source if event.duration > 200.0
23
+ r.timing 'time', event.duration, source: source, percentile: 95
24
+
25
+ if exception
26
+ r.increment 'exceptions', source: source
27
+ else
28
+ r.timing 'time.db', event.payload[:db_runtime] || 0, source: source, percentile: 95
29
+ r.timing 'time.view', event.payload[:view_runtime] || 0, source: source, percentile: 95
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ end # end subscribe
36
+
37
+ end
38
+ end
39
+ end
@@ -4,24 +4,10 @@ module Librato
4
4
 
5
5
  # Controllers
6
6
 
7
- def self.watch_controller_action(controller, action)
8
- @watches ||= []
9
- @watches << "#{controller}##{action}".freeze
10
- end
7
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
11
8
 
12
- AS = ActiveSupport
13
- AS::Notifications.subscribe 'process_action.action_controller' do |*args|
14
-
15
- event = AS::Notifications::Event.new(*args)
16
- controller = event.payload[:controller]
17
- action = event.payload[:action]
18
-
19
- format = event.payload[:format] || "all"
20
- format = "all" if format == "*/*"
21
- status = event.payload[:status]
22
- http_method = event.payload[:method]
9
+ event = ActiveSupport::Notifications::Event.new(*args)
23
10
  exception = event.payload[:exception]
24
- # page_key = "request.#{controller}.#{action}_#{format}."
25
11
 
26
12
  collector.group "rails.request" do |r|
27
13
 
@@ -35,46 +21,11 @@ module Librato
35
21
  r.timing 'time.view', event.payload[:view_runtime] || 0, percentile: 95
36
22
  end
37
23
 
38
- if http_method
39
- verb = http_method.to_s.downcase
40
- r.group 'method' do |m|
41
- m.increment verb
42
- m.timing "#{verb}.time", event.duration
43
- end
44
- end
45
-
46
- unless status.blank?
47
- r.group 'status' do |s|
48
- s.increment status
49
- s.increment "#{status.to_s[0]}xx"
50
- s.timing "#{status}.time", event.duration
51
- s.timing "#{status.to_s[0]}xx.time", event.duration
52
- end
53
- end
54
-
55
24
  r.increment 'slow' if event.duration > 200.0
56
25
  end # end group
57
26
 
58
- if @watches && @watches.index("#{controller}##{action}")
59
- source = "#{controller}.#{action}.#{format}"
60
- collector.group 'rails.action.request' do |r|
61
-
62
- r.increment 'total', source: source
63
- r.increment 'slow', source: source if event.duration > 200.0
64
- r.timing 'time', event.duration, source: source, percentile: 95
65
-
66
- if exception
67
- r.increment 'exceptions', source: source
68
- else
69
- r.timing 'time.db', event.payload[:db_runtime] || 0, source: source, percentile: 95
70
- r.timing 'time.view', event.payload[:view_runtime] || 0, source: source, percentile: 95
71
- end
72
-
73
- end
74
- end
75
-
76
27
  end # end subscribe
77
28
 
78
29
  end
79
30
  end
80
- end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Librato
2
+ module Rails
3
+ module Subscribers
4
+
5
+ # Controller Method
6
+
7
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
8
+
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ http_method = event.payload[:method]
11
+
12
+ if http_method
13
+ verb = http_method.to_s.downcase
14
+
15
+ collector.group "rails.request.method" do |m|
16
+ m.increment verb
17
+ m.timing "#{verb}.time", event.duration
18
+ end # end group
19
+ end
20
+
21
+ end # end subscribe
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Librato
2
+ module Rails
3
+ module Subscribers
4
+
5
+ # Controller Status
6
+
7
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
8
+
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ status = event.payload[:status]
11
+
12
+ unless status.blank?
13
+ collector.group "rails.request.status" do |s|
14
+ s.increment status
15
+ s.increment "#{status.to_s[0]}xx"
16
+ s.timing "#{status}.time", event.duration
17
+ s.timing "#{status.to_s[0]}xx.time", event.duration
18
+ end # end group
19
+ end
20
+
21
+ end # end subscribe
22
+
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Librato
2
2
  module Rails
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -6,6 +6,7 @@ test:
6
6
  source: 'custom-1'
7
7
  source_pids: false
8
8
  proxy: 'http://localhost:8080'
9
+ suites: all
9
10
 
10
11
  production:
11
12
  user: 'live@bar.com'
@@ -18,21 +18,12 @@ module Librato
18
18
  ENV['LIBRATO_USER'] = 'foo@bar.com'
19
19
  ENV['LIBRATO_TOKEN'] = 'api_key'
20
20
  ENV['LIBRATO_SOURCE'] = 'source'
21
+ ENV['LIBRATO_SUITES'] = 'all'
21
22
  config = Configuration.new
22
23
  assert_equal 'foo@bar.com', config.user
23
24
  assert_equal 'api_key', config.token
24
25
  assert_equal 'source', config.source
25
- assert config.explicit_source?, 'source is explicit'
26
- end
27
-
28
- def test_legacy_env_variable_config
29
- ENV['LIBRATO_METRICS_USER'] = 'foo@bar.com'
30
- ENV['LIBRATO_METRICS_TOKEN'] = 'api_key'
31
- ENV['LIBRATO_METRICS_SOURCE'] = 'source'
32
- config = Configuration.new
33
- assert_equal 'foo@bar.com', config.user
34
- assert_equal 'api_key', config.token
35
- assert_equal 'source', config.source
26
+ assert_equal 'all', config.suites
36
27
  assert config.explicit_source?, 'source is explicit'
37
28
  end
38
29
 
@@ -45,6 +36,7 @@ module Librato
45
36
  assert_equal 'custom-1', config.source
46
37
  assert_equal false, config.source_pids
47
38
  assert_equal 'http://localhost:8080', config.proxy
39
+ assert_equal 'all', config.suites
48
40
  assert config.explicit_source?, 'source is explicit'
49
41
  end
50
42
 
@@ -71,6 +63,26 @@ module Librato
71
63
  assert_equal :info, config.log_level, 'should be default'
72
64
  end
73
65
 
66
+ def test_empty_config_file_doesnt_break_suites
67
+ config = fixture_config('empty')
68
+ assert_equal '', config.suites, 'should be default'
69
+ end
70
+
71
+ def test_default_suites
72
+ defaults = Configuration.new.send(:default_suites)
73
+ assert_includes defaults, :rack
74
+ assert_includes defaults, :rack_method
75
+ assert_includes defaults, :rack_status
76
+ assert_includes defaults, :rails_cache
77
+ assert_includes defaults, :rails_controller
78
+ assert_includes defaults, :rails_mail
79
+ assert_includes defaults, :rails_method
80
+ assert_includes defaults, :rails_render
81
+ assert_includes defaults, :rails_sql
82
+ assert_includes defaults, :rails_status
83
+ assert_includes defaults, :rails_job
84
+ end
85
+
74
86
  def fixture_config(file='librato')
75
87
  fixture_config = File.join(File.dirname(__FILE__), "../fixtures/config/#{file}.yml")
76
88
  Configuration.new(:config_file => fixture_config)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librato-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Sanders
@@ -29,7 +29,7 @@ cert_chain:
29
29
  hvjx0WJP8pzZMJPKJBRZQXJO5ifEPyKjZyMi5XMHmrtDclHLj3sx4RAvEZjGWkRP
30
30
  JSQ=
31
31
  -----END CERTIFICATE-----
32
- date: 2016-03-09 00:00:00.000000000 Z
32
+ date: 2016-04-21 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: railties
@@ -65,14 +65,14 @@ dependencies:
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.6.0
68
+ version: 1.0.0
69
69
  type: :runtime
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.6.0
75
+ version: 1.0.0
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: sqlite3
78
78
  requirement: !ruby/object:Gem::Requirement
@@ -135,12 +135,15 @@ files:
135
135
  - lib/librato/rails/helpers/controller.rb
136
136
  - lib/librato/rails/railtie.rb
137
137
  - lib/librato/rails/subscribers.rb
138
+ - lib/librato/rails/subscribers/action.rb
138
139
  - lib/librato/rails/subscribers/cache.rb
139
140
  - lib/librato/rails/subscribers/controller.rb
140
141
  - lib/librato/rails/subscribers/job.rb
141
142
  - lib/librato/rails/subscribers/mail.rb
143
+ - lib/librato/rails/subscribers/method.rb
142
144
  - lib/librato/rails/subscribers/render.rb
143
145
  - lib/librato/rails/subscribers/sql.rb
146
+ - lib/librato/rails/subscribers/status.rb
144
147
  - lib/librato/rails/tracker.rb
145
148
  - lib/librato/rails/version.rb
146
149
  - lib/librato/rails/version_specifier.rb
metadata.gz.sig CHANGED
Binary file