roqua-support 0.1.16 → 0.1.17

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: fdc528029ceea9027cdb56ce3299bc59a64817e4
4
- data.tar.gz: b3eaa1c5921dd5684c595486580533d790a6dc5d
3
+ metadata.gz: 7a54ca79cd7b20e4121b8aa54b9d707ef1418680
4
+ data.tar.gz: e06d9c5eadc2fd970adaa4ef0c7602e485c743df
5
5
  SHA512:
6
- metadata.gz: 2fb16cd904080b1b5e22ed7bd14afda38139ee53b34583967a55a1cd986a54fc4e621adeed1fb64b1ec434f63b5012dc7da3ec317202aac624dd69108945677a
7
- data.tar.gz: c6c44518398a0e3a012bcfdcac524c9527de98183cb37930a7175e97e9fa51d59b7362e51309025b7e8579af37fd6fc54baf84df89713a33d2ddce08e45647d5
6
+ metadata.gz: a3eefb5cab8aaa04bd445f57d24535baf4247a28fdb081f93f14241cb39e9533699191d7e70fea13c9ff90bbc7202609b433ee85d216c656cc4837279a2f9f4f
7
+ data.tar.gz: 856eb8e8a015bf97ce6b88aea46c0008a8045d60900301dd8e8e5c4f7a55b29ca6e450cd592c5a113d4019488bfb128e0957a291780a51fbc8aee4b57c3a2373
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.17 / 2014-11-20
2
+
3
+ * Add support for Hosted Graphite through Roqua.stats
4
+ * Deprecate Roqua::Logging in favor of Roqua::Support::Instrumentation
5
+
1
6
  ## 0.1.16 / 2014-11-19
2
7
 
3
8
  * Add support for skipping the backtrace in the logs
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roqua-support (0.1.16)
4
+ roqua-support (0.1.17)
5
5
  activesupport (>= 3.2, < 5.0)
6
+ naught (~> 1.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -61,6 +62,7 @@ GEM
61
62
  lumberjack (1.0.9)
62
63
  method_source (0.8.2)
63
64
  minitest (5.4.2)
65
+ naught (1.0.0)
64
66
  pry (0.10.1)
65
67
  coderay (~> 1.1.0)
66
68
  method_source (~> 0.8.1)
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module Support
3
- VERSION = '0.1.16'
3
+ VERSION = '0.1.17'
4
4
  end
5
5
  end
data/lib/roqua/support.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'logger'
2
- require 'roqua/support/logging'
2
+ require 'roqua/support/instrumentation'
3
+ require 'roqua/support/log_wrapper'
3
4
  require 'roqua/support/errors'
5
+ require 'roqua/support/stats'
4
6
 
5
7
  module Roqua
6
8
  class << self
@@ -19,5 +21,13 @@ module Roqua
19
21
  def logger=(logger)
20
22
  @logger = LogWrapper.new(logger)
21
23
  end
24
+
25
+ def stats
26
+ @stats ||= Stats.new
27
+ end
28
+
29
+ def stats=(stats)
30
+ @stats = stats
31
+ end
22
32
  end
23
- end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support/core_ext/module/aliasing'
2
+ require 'roqua/support/log_wrapper'
3
+
4
+ module Roqua
5
+ module Support
6
+ module Instrumentation
7
+ def with_instrumentation(message, options = {})
8
+ started_at = Time.now.to_f
9
+ Roqua.logger.info("#{message}:started", options)
10
+ value = yield
11
+ finished_at = Time.now.to_f
12
+ duration = finished_at - started_at
13
+ Roqua.logger.info("#{message}:finished", {duration: duration}.merge(options))
14
+ Roqua.stats.submit("#{message}.finished", 1)
15
+ Roqua.stats.submit("#{message}.duration", duration)
16
+ value
17
+ rescue => e
18
+ Roqua.logger.error("#{message}:failed", {exception: e.class.name, message: e.message}.merge(options))
19
+ Roqua.stats.submit("#{message}.failed", 1)
20
+ raise
21
+ end
22
+
23
+ def eventlog
24
+ Roqua.logger
25
+ end
26
+ end
27
+ end
28
+
29
+ # Roqua::Logging is deprecated, this will keep it alive for now
30
+ Logging = Support::Instrumentation
31
+ end
@@ -11,7 +11,7 @@ module Roqua
11
11
  end
12
12
 
13
13
  class RequestLogger < ActiveSupport::LogSubscriber
14
- include Roqua::Logging
14
+ include Roqua::Support::Instrumentation
15
15
 
16
16
  def process_action(event)
17
17
  payload = event.payload
@@ -105,4 +105,4 @@ module Roqua
105
105
  end
106
106
  end
107
107
  end
108
- end
108
+ end
@@ -0,0 +1,28 @@
1
+ require 'naught'
2
+
3
+ module Roqua
4
+ module Support
5
+ class Stats
6
+ NullBackend = Naught.build do |config|
7
+ config.singleton
8
+ end
9
+
10
+ attr_reader :backend
11
+
12
+ def initialize(backend = NullBackend.instance)
13
+ @backend = backend
14
+ end
15
+
16
+ # Report a value to the stats backend
17
+ def submit(key, value)
18
+ backend.submit(prefix(key), value)
19
+ end
20
+
21
+ private
22
+
23
+ def prefix(key)
24
+ "#{Roqua.appname}.#{key}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'hosted_graphite'
2
+
3
+ module Roqua
4
+ module Support
5
+ class Stats
6
+ class HostedGraphiteBackend
7
+ def submit(key, value)
8
+ HostedGraphite.send_metric(key, value)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency 'activesupport', '>= 3.2', '< 5.0'
22
+ gem.add_dependency 'naught', '~> 1.0'
22
23
 
23
24
  gem.add_development_dependency 'bundler', '~> 1.0'
24
25
  gem.add_development_dependency 'rake'
@@ -0,0 +1,50 @@
1
+ require 'roqua/support/instrumentation'
2
+
3
+ describe 'Helper methods' do
4
+ describe '#with_instrumentation' do
5
+ include Roqua::Support::Instrumentation
6
+
7
+ let(:logger) { double("Logger", info: nil, error: nil) }
8
+ let(:stats) { double("Stats", submit: nil) }
9
+
10
+ before do
11
+ allow(Roqua).to receive(:logger).and_return(logger)
12
+ allow(Roqua).to receive(:stats).and_return(stats)
13
+ end
14
+
15
+ context 'when the block returns a value' do
16
+ it 'logs the start and finish lifecycle of a block' do
17
+ expect(logger).to receive(:info).with('testevent:started', {extra: "params"}).ordered
18
+ expect(logger).to receive(:info).with('testevent:finished', hash_including({extra: "params"})).ordered
19
+ expect(stats).to receive(:submit).with('testevent.finished', 1)
20
+ expect(stats).to receive(:submit).with('testevent.duration', an_instance_of(Float))
21
+
22
+ with_instrumentation('testevent', extra: 'params') { 1 + 1 }
23
+ end
24
+
25
+ it 'returns the value returned by the block' do
26
+ with_instrumentation('testevent') { 1 + 1 }.should == 2
27
+ end
28
+ end
29
+
30
+ context 'when an exception happens during the block' do
31
+ it 'logs the start and failure of a block if it raises' do
32
+ expect(logger).to receive(:info).with('testevent:started', instance_of(Hash)).ordered
33
+ expect(logger).to receive(:error).with('testevent:failed', instance_of(Hash)).ordered
34
+ expect(stats).to receive(:submit).with('testevent.failed', 1)
35
+
36
+ with_instrumentation 'testevent' do
37
+ raise StandardError, "Foo"
38
+ end rescue nil
39
+ end
40
+
41
+ it 'reraises the exception' do
42
+ expect {
43
+ with_instrumentation 'testevent' do
44
+ raise "Foo"
45
+ end
46
+ }.to raise_error('Foo')
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,4 +1,4 @@
1
- require 'roqua/support/logging'
1
+ require 'roqua/support/log_wrapper'
2
2
  require 'logger'
3
3
  require 'stringio'
4
4
 
@@ -65,24 +65,5 @@ module Roqua
65
65
  }.to raise_error('Foo')
66
66
  end
67
67
  end
68
-
69
- describe '.lifecycle' do
70
- it 'wraps given method' do
71
- ::Roqua.stub(:logger => logwrapper)
72
-
73
- test = Class.new do
74
- include Logging
75
-
76
- def foo
77
- 'bar'
78
- end
79
- log :foo, 'roqua.testevent.foo'
80
- end
81
-
82
- test.new.foo.should == 'bar'
83
- log.should include('roqua.testevent.foo:started')
84
- log.should include('roqua.testevent.foo:finished')
85
- end
86
- end
87
68
  end
88
69
  end
@@ -1,4 +1,4 @@
1
- require 'roqua/support/logging'
1
+ require 'roqua/support/log_wrapper'
2
2
  require 'roqua/support/request_logger'
3
3
  require 'active_support/notifications'
4
4
  require 'active_support/core_ext/string'
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'roqua/support/stats'
3
+
4
+ describe 'Stats' do
5
+ let(:backend) { double("StatsBackend") }
6
+ let(:stats) { Roqua::Support::Stats.new(backend) }
7
+
8
+ before do
9
+ Roqua.appname = 'appname'
10
+ end
11
+
12
+ describe 'tracking a value' do
13
+ it 'reports to backend' do
14
+ expect(backend).to receive(:submit).with('appname.data_export.duration', 2.3)
15
+ stats.submit('data_export.duration', 2.3)
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: naught
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -109,9 +123,11 @@ files:
109
123
  - lib/roqua/support.rb
110
124
  - lib/roqua/support/command_runner.rb
111
125
  - lib/roqua/support/errors.rb
126
+ - lib/roqua/support/instrumentation.rb
112
127
  - lib/roqua/support/log_wrapper.rb
113
- - lib/roqua/support/logging.rb
114
128
  - lib/roqua/support/request_logger.rb
129
+ - lib/roqua/support/stats.rb
130
+ - lib/roqua/support/stats/hosted_graphite_backend.rb
115
131
  - roqua-support.gemspec
116
132
  - spec/roqua/core_ext/active_interaction/date_time_as_unix_extension_spec.rb
117
133
  - spec/roqua/core_ext/active_interaction/duration_filter_spec.rb
@@ -123,8 +139,10 @@ files:
123
139
  - spec/roqua/responders/active_interaction_aware_responder_spec.rb
124
140
  - spec/roqua/responders/api_errors_responder_spec.rb
125
141
  - spec/roqua/support/errors_spec.rb
126
- - spec/roqua/support/logging_spec.rb
142
+ - spec/roqua/support/helpers_spec.rb
143
+ - spec/roqua/support/logwrapper_spec.rb
127
144
  - spec/roqua/support/request_logger_spec.rb
145
+ - spec/roqua/support/stats_spec.rb
128
146
  - spec/roqua/support_spec.rb
129
147
  - spec/spec_helper.rb
130
148
  homepage: https://github.com/roqua/roqua-support
@@ -162,7 +180,9 @@ test_files:
162
180
  - spec/roqua/responders/active_interaction_aware_responder_spec.rb
163
181
  - spec/roqua/responders/api_errors_responder_spec.rb
164
182
  - spec/roqua/support/errors_spec.rb
165
- - spec/roqua/support/logging_spec.rb
183
+ - spec/roqua/support/helpers_spec.rb
184
+ - spec/roqua/support/logwrapper_spec.rb
166
185
  - spec/roqua/support/request_logger_spec.rb
186
+ - spec/roqua/support/stats_spec.rb
167
187
  - spec/roqua/support_spec.rb
168
188
  - spec/spec_helper.rb
@@ -1,26 +0,0 @@
1
- require 'active_support/core_ext/module/aliasing'
2
- require 'roqua/support/log_wrapper'
3
-
4
- module Roqua
5
- module Logging
6
- def self.included(base)
7
- base.extend ClassMethods
8
- end
9
-
10
- module ClassMethods
11
- def log(method_name, message, options = {})
12
- define_method(:"#{method_name}_with_log") do |*args, &block|
13
- eventlog.lifecycle(message, options) do
14
- send(:"#{method_name}_without_log", *args, &block)
15
- end
16
- end
17
-
18
- alias_method_chain method_name, 'log'
19
- end
20
- end
21
-
22
- def eventlog
23
- Roqua.logger
24
- end
25
- end
26
- end