chillout 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,8 @@
1
1
  require 'forwardable'
2
2
  require 'chillout/server_side'
3
3
  require 'chillout/http_client'
4
- require 'chillout/error_filter'
5
4
  require 'chillout/dispatcher'
6
5
  require 'chillout/config'
7
- require 'chillout/error'
8
6
  require 'chillout/event_data_builder'
9
7
  require 'chillout/prefixed_logger'
10
8
  require 'chillout/worker'
@@ -14,7 +12,7 @@ module Chillout
14
12
  class Client
15
13
  extend Forwardable
16
14
 
17
- def_delegators :@dispatcher, :dispatch_error, :send_error, :send_creations
15
+ def_delegators :@dispatcher, :send_creations
18
16
 
19
17
  attr_reader :config
20
18
  attr_reader :logger
@@ -30,7 +28,6 @@ module Chillout
30
28
  @http_client = HttpClient.new(@config, logger).freeze
31
29
  @event_data_builder = EventDataBuilder.new(@config).freeze
32
30
  @server_side = ServerSide.new(@event_data_builder, @http_client).freeze
33
- @filter = ErrorFilter.new
34
31
  @dispatcher = Dispatcher.new(@filter, @server_side).freeze
35
32
  @queue = Queue.new
36
33
  end
@@ -8,17 +8,6 @@ module Chillout
8
8
  @server_side = server_side
9
9
  end
10
10
 
11
- def dispatch_error(error)
12
- if @filter.deliver_error?(error)
13
- send_error(error)
14
- end
15
- end
16
-
17
- def send_error(error)
18
- @server_side.send_error(error)
19
- rescue HttpClient::NotSent
20
- end
21
-
22
11
  def send_creations(creations)
23
12
  @server_side.send_creations(creations)
24
13
  rescue HttpClient::NotSent
@@ -4,32 +4,6 @@ module Chillout
4
4
  @config = config
5
5
  end
6
6
 
7
- def build_from_error(error, timestamp)
8
- {
9
- event: "exception",
10
- timestamp: timestamp,
11
- content: {
12
- class: error.exception_class,
13
- message: error.message,
14
- backtrace: error.backtrace,
15
- file: error.file,
16
- environment: @config.environment,
17
- context: {
18
- platform: @config.platform,
19
- controller: error.controller_name,
20
- action: error.controller_action,
21
- current_user: {
22
- id: error.current_user_id,
23
- email: error.current_user_email,
24
- full_name: error.current_user_full_name
25
- }
26
- },
27
- rack_environment: build_rack_environment(error)
28
- },
29
- notifier: build_notifier
30
- }
31
- end
32
-
33
7
  def build_from_creations_container(creations_container, timestamp)
34
8
  {
35
9
  metric: "creations",
@@ -56,11 +30,5 @@ module Chillout
56
30
  url: @config.notifier_url
57
31
  }
58
32
  end
59
-
60
- def build_rack_environment(error)
61
- Hash[error.environment.collect do |key, value|
62
- [key, value.to_s]
63
- end]
64
- end
65
33
  end
66
34
  end
@@ -3,7 +3,7 @@ require 'chillout/creation_listener'
3
3
  module Chillout
4
4
  class Railtie < Rails::Railtie
5
5
  config.chillout = ActiveSupport::OrderedOptions.new
6
- initializer "chillout.exceptions_listener_initialization" do |app|
6
+ initializer "chillout.creations_listener_initialization" do |app|
7
7
  if !app.config.chillout.empty?
8
8
  existing_option_keys = [:port, :hostname, :ssl].select{|key| app.config.chillout.has_key?(key)}
9
9
  options_list = existing_option_keys.map{|key| [key, app.config.chillout[key]]}
@@ -13,7 +13,6 @@ module Chillout
13
13
 
14
14
  ActiveRecord::Base.extend(CreationListener)
15
15
 
16
- app.middleware.use Middleware::ExceptionMonitor, client
17
16
  app.middleware.use Middleware::CreationsMonitor, client
18
17
 
19
18
  client.start_worker
@@ -9,15 +9,6 @@ module Chillout
9
9
  @event_data_builder = event_data_builder
10
10
  end
11
11
 
12
- def send_error(error)
13
- event_data = @event_data_builder.build_from_error(error, timestamp)
14
- send_event(event_data)
15
- end
16
-
17
- def send_event(data)
18
- @http_client.post('/events', data)
19
- end
20
-
21
12
  def send_creations(creations_container)
22
13
  event_data = @event_data_builder.build_from_creations_container(creations_container, timestamp)
23
14
  send_metric(event_data)
@@ -1,3 +1,3 @@
1
1
  module Chillout
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/chillout.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  require "chillout/version"
2
2
  require "chillout/config"
3
- require "chillout/middleware/exception_monitor"
4
3
  require "chillout/middleware/creations_monitor"
5
- require "chillout/error"
6
4
  require "chillout/dispatcher"
7
- require "chillout/error_filter"
8
5
  require "chillout/server_side"
9
6
  require "chillout/http_client"
10
7
  require "chillout/client"
@@ -1,51 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class DispatcherTest < ChilloutTestCase
4
-
5
- def test_error_dispatch
6
- exception = build_exception(NameError)
7
- env = {
8
- "HTTP_USER_AGENT" => "Mozzila/4.0",
9
- "rack.session" => {}
10
- }
11
- error = Chillout::Error.new(exception, env)
12
-
13
- filter = mock("Filter")
14
- filter.expects(:deliver_error?).with(error).returns(true)
15
-
16
- server_side = mock("ServerSide")
17
- server_side.expects(:send_error).with(error)
18
-
19
- dispatcher = Chillout::Dispatcher.new(filter, server_side)
20
- dispatcher.dispatch_error(error)
21
- end
22
-
23
- def test_ignored_error_dispatch
24
- exception = build_exception(NameError)
25
- env = {
26
- "HTTP_USER_AGENT" => "Mozzila/4.0",
27
- "rack.session" => {}
28
- }
29
- error = Chillout::Error.new(exception, env)
30
-
31
- filter = mock("Filter")
32
- filter.expects(:deliver_error?).with(error).returns(false)
33
-
34
- server_side = mock("ServerSide")
35
-
36
- dispatcher = Chillout::Dispatcher.new(filter, server_side)
37
- dispatcher.dispatch_error(error)
38
- end
39
-
40
- def test_send_error_ignore_not_sent_exception
41
- server_side = stub()
42
- server_side.stubs(:send_error).raises(Chillout::HttpClient::NotSent.new(:http_error))
43
-
44
- dispatcher = Chillout::Dispatcher.new(mock, server_side)
45
-
46
- assert_nil dispatcher.send_error(:error)
47
- end
48
-
49
4
  def test_send_creations
50
5
  filter = mock("Filter")
51
6
 
@@ -18,99 +18,6 @@ module Chillout
18
18
  @timestamp = Time.now.iso8601
19
19
  end
20
20
 
21
- context "build from error" do
22
- setup do
23
- @event_data_builder = EventDataBuilder.new(@config)
24
-
25
- @controller = mock("Controller")
26
- @controller.stubs(:controller_name).returns("UsersController")
27
- @controller.stubs(:action_name).returns("index")
28
-
29
- @current_user = mock("User")
30
- @current_user.stubs(:id).returns(123)
31
- @current_user.stubs(:email).returns("john@example.com")
32
- @current_user.stubs(:full_name).returns("john doe")
33
-
34
- @exception = build_exception(NameError, "FooBar does not exists")
35
- @env = {
36
- 'HTTP_USER_AGENT' => 'Mozilla/4.0',
37
- 'action_controller.instance' => @controller,
38
- 'current_user' => @current_user
39
- }
40
- @error = Chillout::Error.new(@exception, @env)
41
- @event_data = @event_data_builder.build_from_error(@error, @timestamp)
42
- end
43
-
44
- def test_event_type
45
- assert_param :event, 'exception'
46
- end
47
-
48
- def test_timestamp
49
- assert_param :timestamp, @timestamp
50
- end
51
-
52
- def test_exception_class
53
- assert_content :class, 'NameError'
54
- end
55
-
56
- def test_exception_message
57
- assert_content :message, 'FooBar does not exists'
58
- end
59
-
60
- def test_backtrace
61
- assert_content :backtrace, @exception.backtrace
62
- end
63
-
64
- def test_file
65
- assert_content :file, @error.file
66
- end
67
-
68
- def test_environment
69
- assert_content :environment, "development"
70
- end
71
-
72
- def test_platform
73
- assert_context :platform, "rails"
74
- end
75
-
76
- def test_controller
77
- assert_context :controller, "UsersController"
78
- end
79
-
80
- def test_action
81
- assert_context :controller, "UsersController"
82
- end
83
-
84
- def test_current_user_id
85
- assert_current_user :id, 123
86
- end
87
-
88
- def test_current_user_email
89
- assert_current_user :email, "john@example.com"
90
- end
91
-
92
- def test_current_user_full_name
93
- assert_current_user :full_name, "john doe"
94
- end
95
-
96
- def test_rack_environment
97
- expected_value = Hash[@env.collect { |k,v| [k, v.to_s] }]
98
- assert_content :rack_environment, expected_value
99
- end
100
-
101
- def test_notifier_name
102
- assert_notifier :name, "chillout"
103
- end
104
-
105
- def test_notifier_version
106
- assert_notifier :version, "0.1"
107
- end
108
-
109
- def test_notifier_url
110
- assert_notifier :url, "http://github.com/arkency/chillout"
111
- end
112
- end
113
-
114
21
  context "build from creations container" do
115
22
  setup do
116
23
  @creations_container = CreationsContainer.new
@@ -166,18 +73,10 @@ module Chillout
166
73
  assert_equal value, event_data[:content][key]
167
74
  end
168
75
 
169
- def assert_context(key, value)
170
- assert_equal value, event_data[:content][:context][key]
171
- end
172
-
173
76
  def assert_creations(key, value)
174
77
  assert_equal value, event_data[:content][:creations][key]
175
78
  end
176
79
 
177
- def assert_current_user(key, value)
178
- assert_equal value, event_data[:content][:context][:current_user][key]
179
- end
180
-
181
80
  def assert_notifier(key, value)
182
81
  assert_equal value, event_data[:notifier][key]
183
82
  end
@@ -9,18 +9,6 @@ class ServerSideTest < ChilloutTestCase
9
9
  @server_side = Chillout::ServerSide.new(@event_data_builder, @http_client)
10
10
  end
11
11
 
12
- def test_send_error_use_event_data_builder
13
- @event_data_builder.expects(:build_from_error).with(:error, anything).returns(:event_data_from_builder)
14
- @http_client.stubs(:post)
15
- @server_side.send_error(:error)
16
- end
17
-
18
- def test_send_error_use_http_client
19
- @event_data_builder.stubs(:build_from_error).returns(:event_data_from_builder)
20
- @http_client.expects(:post).with('/events', :event_data_from_builder)
21
- @server_side.send_error(:error)
22
- end
23
-
24
12
  def test_send_creations_use_event_data_builder
25
13
  @event_data_builder.expects(:build_from_creations_container).with(:creations_container, anything).returns(:event_data_from_builder)
26
14
  @http_client.stubs(:post)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chillout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-14 00:00:00.000000000 Z
13
+ date: 2013-03-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest
@@ -129,12 +129,9 @@ files:
129
129
  - lib/chillout/creation_listener.rb
130
130
  - lib/chillout/creations_container.rb
131
131
  - lib/chillout/dispatcher.rb
132
- - lib/chillout/error.rb
133
- - lib/chillout/error_filter.rb
134
132
  - lib/chillout/event_data_builder.rb
135
133
  - lib/chillout/http_client.rb
136
134
  - lib/chillout/middleware/creations_monitor.rb
137
- - lib/chillout/middleware/exception_monitor.rb
138
135
  - lib/chillout/prefixed_logger.rb
139
136
  - lib/chillout/railtie.rb
140
137
  - lib/chillout/server_side.rb
@@ -144,13 +141,10 @@ files:
144
141
  - test/config_test.rb
145
142
  - test/creations_container_test.rb
146
143
  - test/dispatcher_test.rb
147
- - test/error_test.rb
148
144
  - test/event_data_builder_test.rb
149
145
  - test/http_client_test.rb
150
146
  - test/integration/creations_monitor_rack_test.rb
151
- - test/integration/exception_monitor_rack_test.rb
152
147
  - test/middleware/creations_monitor_test.rb
153
- - test/middleware/exception_monitor_test.rb
154
148
  - test/prefixed_logger_test.rb
155
149
  - test/server_side_test.rb
156
150
  - test/test_helper.rb
@@ -169,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
163
  version: '0'
170
164
  segments:
171
165
  - 0
172
- hash: 111791620312850416
166
+ hash: 4186506627613896564
173
167
  required_rubygems_version: !ruby/object:Gem::Requirement
174
168
  none: false
175
169
  requirements:
@@ -178,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
172
  version: '0'
179
173
  segments:
180
174
  - 0
181
- hash: 111791620312850416
175
+ hash: 4186506627613896564
182
176
  requirements: []
183
177
  rubyforge_project:
184
178
  rubygems_version: 1.8.25
@@ -190,13 +184,10 @@ test_files:
190
184
  - test/config_test.rb
191
185
  - test/creations_container_test.rb
192
186
  - test/dispatcher_test.rb
193
- - test/error_test.rb
194
187
  - test/event_data_builder_test.rb
195
188
  - test/http_client_test.rb
196
189
  - test/integration/creations_monitor_rack_test.rb
197
- - test/integration/exception_monitor_rack_test.rb
198
190
  - test/middleware/creations_monitor_test.rb
199
- - test/middleware/exception_monitor_test.rb
200
191
  - test/prefixed_logger_test.rb
201
192
  - test/server_side_test.rb
202
193
  - test/test_helper.rb
@@ -1,60 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Chillout
4
- class Error
5
-
6
- attr_reader :exception
7
- attr_reader :environment
8
-
9
- def initialize(exception, environment = {})
10
- @exception = exception
11
- @environment = environment
12
- @nullObject = OpenStruct.new
13
- end
14
-
15
- def exception_class
16
- exception.class.name
17
- end
18
-
19
- def message
20
- exception.message
21
- end
22
-
23
- def backtrace
24
- exception.backtrace
25
- end
26
-
27
- def file
28
- backtrace.first.split(":").first rescue nil
29
- end
30
-
31
- def controller
32
- environment['action_controller.instance'] || @nullObject
33
- end
34
-
35
- def controller_name
36
- controller.controller_name
37
- end
38
-
39
- def controller_action
40
- controller.action_name
41
- end
42
-
43
- def current_user
44
- environment['current_user'] || @nullObject
45
- end
46
-
47
- def current_user_id
48
- current_user.id if current_user.respond_to?(:id)
49
- end
50
-
51
- def current_user_email
52
- current_user.email if current_user.respond_to?(:email)
53
- end
54
-
55
- def current_user_full_name
56
- current_user.full_name if current_user.respond_to?(:full_name)
57
- end
58
-
59
- end
60
- end
@@ -1,9 +0,0 @@
1
- module Chillout
2
- class ErrorFilter
3
-
4
- def deliver_error?(error)
5
- true
6
- end
7
-
8
- end
9
- end
@@ -1,25 +0,0 @@
1
- module Chillout
2
- module Middleware
3
- class ExceptionMonitor
4
- def initialize(app, client)
5
- @app = app
6
- @client = client
7
- end
8
-
9
- def call(env)
10
- begin
11
- response = @app.call(env)
12
- rescue Exception => exception
13
- @client.dispatch_error(Chillout::Error.new(exception, env))
14
- raise exception
15
- end
16
-
17
- if env['rack.exception']
18
- @client.dispatch_error(Chillout::Error.new(env['rack.exception'], env))
19
- end
20
-
21
- response
22
- end
23
- end
24
- end
25
- end
data/test/error_test.rb DELETED
@@ -1,115 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ErrorTest < ChilloutTestCase
4
-
5
- def setup
6
- @exception = build_exception(ArgumentError)
7
- @env = { 'charset' => 'utf-8' }
8
- @error = Chillout::Error.new(@exception, @env)
9
- end
10
-
11
- def test_exception_class
12
- assert_equal "ArgumentError", @error.exception_class
13
- end
14
-
15
- def test_backtrace
16
- assert_kind_of Array, @error.backtrace
17
- end
18
-
19
- def test_file
20
- file = File.expand_path('../test_helper.rb', __FILE__)
21
- assert_equal file, @error.file
22
- end
23
-
24
- context "controller is not given" do
25
-
26
- def test_controller_name
27
- assert_nil @error.controller_name
28
- end
29
-
30
- def test_controller_action
31
- assert_nil @error.controller_action
32
- end
33
-
34
- end
35
-
36
- context "controller is given" do
37
-
38
- setup do
39
- @controller = mock("controller")
40
- @env['action_controller.instance'] = @controller
41
- end
42
-
43
- def test_controller_action_when_controller_is_set
44
- @controller.expects(:action_name).returns("index")
45
- assert_equal "index", @error.controller_action
46
- end
47
-
48
- def test_controller_name_when_controller_is_set
49
- @controller.expects(:controller_name).returns("ApplicationController")
50
- assert_equal "ApplicationController", @error.controller_name
51
- end
52
-
53
- end
54
-
55
- context "current user is not given" do
56
-
57
- def test_current_user_id
58
- assert_nil @error.current_user_id
59
- end
60
-
61
- def test_current_user_email
62
- assert_nil @error.current_user_email
63
- end
64
-
65
- def test_current_user_full_name
66
- assert_nil @error.current_user_full_name
67
- end
68
-
69
- end
70
-
71
- context "current user is given" do
72
-
73
- setup do
74
- @user = mock("user")
75
- @env['current_user'] = @user
76
- end
77
-
78
- def test_current_user_id
79
- @user.expects(:id).returns(123)
80
- assert_equal 123, @error.current_user_id
81
- end
82
-
83
- def test_current_user_email
84
- @user.expects(:email).returns("john@example.net")
85
- assert_equal "john@example.net", @error.current_user_email
86
- end
87
-
88
- def test_current_user_full_name
89
- @user.expects(:full_name).returns("john doe")
90
- assert_equal "john doe", @error.current_user_full_name
91
- end
92
- end
93
-
94
- context "current user is given but does not respond to expected methods" do
95
-
96
- setup do
97
- @user = mock("user")
98
- @env['current_user'] = @user
99
- end
100
-
101
- def test_current_user_id
102
- assert_nil @error.current_user_id
103
- end
104
-
105
- def test_current_user_email
106
- assert_nil @error.current_user_email
107
- end
108
-
109
- def test_current_user_full_name
110
- assert_nil @error.current_user_full_name
111
- end
112
-
113
- end
114
-
115
- end
@@ -1,51 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ExceptionMonitorRackTest < ChilloutTestCase
4
- include Rack::Test::Methods
5
-
6
- def setup
7
- api_key = "xyz123"
8
- stub_api_request(api_key, "events")
9
- @config = Chillout::Config.new(api_key)
10
- @config.ssl = false
11
- @client = Chillout::Client.new(@config)
12
- end
13
-
14
- def app
15
- client = @client # Only local variable can be passed to the block below
16
- Rack::Builder.new do
17
- use Chillout::Middleware::ExceptionMonitor, client
18
- run(lambda { |env| raise ChilloutTestException.new("Something went wrong") })
19
- end
20
- end
21
-
22
- def test_exception_class
23
- trigger_error
24
- assert_equal "ChilloutTestException", request_body["content"]["class"]
25
- end
26
-
27
- def test_exception_message
28
- trigger_error
29
- assert_equal "Something went wrong", request_body["content"]["message"]
30
- end
31
-
32
- def test_rack_environment
33
- trigger_error
34
- assert_request_body "events" do |body|
35
- assert_equal last_request.env.keys, body["content"]["rack_environment"].keys
36
- end
37
- end
38
-
39
- private
40
- def trigger_error
41
- begin
42
- get "/"
43
- rescue ChilloutTestException
44
- end
45
- end
46
-
47
- def request_body
48
- assert_request_body("events"){ |body| return body }
49
- end
50
-
51
- end
@@ -1,54 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Chillout
4
- module Middleware
5
- class ExceptionMonitorTest < ChilloutTestCase
6
-
7
- class DummyError < StandardError; end
8
-
9
- def test_behaves_like_rack_middleware
10
- env = { 'HOST' => 'example.net' }
11
- app = lambda { |env| [200, env, ['hello']] }
12
- middleware = ExceptionMonitor.new(app, mock)
13
-
14
- response = middleware.call(env)
15
-
16
- assert_equal [200, env, ['hello']], response
17
- end
18
-
19
- def test_exception_is_raised
20
- exception = build_exception(DummyError)
21
- env = { 'HOST' => 'example.net' }
22
- app = lambda do |env|
23
- raise exception
24
- end
25
- dispatcher = mock("Dispatcher")
26
- dispatcher.expects(:dispatch_error).with do |error|
27
- error.exception == exception && error.environment == env
28
- end
29
-
30
- middleware = ExceptionMonitor.new(app, dispatcher)
31
- assert_raises DummyError do
32
- middleware.call(env)
33
- end
34
- end
35
-
36
- def test_exception_is_found_in_rack_environment
37
- exception = build_exception(DummyError)
38
- env = { 'HOST' => 'example.net' }
39
- app = lambda do |env|
40
- env['rack.exception'] = exception
41
- [200, env, ['hello']]
42
- end
43
- dispatcher = mock("Dispatcher")
44
- dispatcher.expects(:dispatch_error).with do |error|
45
- error.exception == exception && error.environment == env
46
- end
47
-
48
- middleware = ExceptionMonitor.new(app, dispatcher)
49
- middleware.call(env)
50
- end
51
-
52
- end
53
- end
54
- end