influxdb-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +95 -0
  4. data/README.md +3 -0
  5. data/Rakefile +34 -0
  6. data/config.ru +7 -0
  7. data/gemfiles/Gemfile.rails-3.0.x +8 -0
  8. data/gemfiles/Gemfile.rails-3.0.x.lock +94 -0
  9. data/gemfiles/Gemfile.rails-3.1.x +8 -0
  10. data/gemfiles/Gemfile.rails-3.1.x.lock +121 -0
  11. data/gemfiles/Gemfile.rails-3.2.x +8 -0
  12. data/gemfiles/Gemfile.rails-3.2.x.lock +104 -0
  13. data/gemfiles/Gemfile.rails-4.0.x +8 -0
  14. data/gemfiles/Gemfile.rails-4.0.x.lock +109 -0
  15. data/generators/influxdb/influxdb_generator.rb +48 -0
  16. data/generators/influxdb/templates/initializer.rb +5 -0
  17. data/influxdb-rails.gemspec +33 -0
  18. data/lib/influxdb-rails.rb +82 -0
  19. data/lib/influxdb/rails/air_traffic_controller.rb +39 -0
  20. data/lib/influxdb/rails/backtrace.rb +44 -0
  21. data/lib/influxdb/rails/configuration.rb +117 -0
  22. data/lib/influxdb/rails/exception_presenter.rb +90 -0
  23. data/lib/influxdb/rails/instrumentation.rb +27 -0
  24. data/lib/influxdb/rails/logger.rb +13 -0
  25. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +21 -0
  26. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +32 -0
  27. data/lib/influxdb/rails/rack.rb +28 -0
  28. data/lib/influxdb/rails/rails.rb +39 -0
  29. data/lib/influxdb/rails/railtie.rb +67 -0
  30. data/lib/influxdb/rails/version.rb +5 -0
  31. data/lib/rails/generators/influxdb/influxdb_generator.rb +52 -0
  32. data/lib/rails/generators/influxdb/templates/initializer.rb +4 -0
  33. data/spec/controllers/widgets_controller_spec.rb +15 -0
  34. data/spec/integration/exceptions_spec.rb +37 -0
  35. data/spec/integration/integration_helper.rb +1 -0
  36. data/spec/spec_helper.rb +29 -0
  37. data/spec/suite.sh +42 -0
  38. data/spec/support/rails3/app.rb +24 -0
  39. data/spec/support/rails3/log/test.log +1120 -0
  40. data/spec/support/rails4/app.rb +27 -0
  41. data/spec/unit/backtrace_spec.rb +88 -0
  42. data/spec/unit/configuration_spec.rb +29 -0
  43. data/spec/unit/exception_presenter_spec.rb +69 -0
  44. data/spec/unit/influxdb_rails_spec.rb +67 -0
  45. metadata +226 -0
@@ -0,0 +1,27 @@
1
+ require 'action_controller/railtie'
2
+
3
+ app = Class.new(Rails::Application)
4
+ app.config.secret_token = '1234567890abcdef1234567890abcdef'
5
+ app.config.session_store :cookie_store, :key => '_myapp_session'
6
+ app.config.active_support.deprecation = :log
7
+ app.config.eager_load = false
8
+ app.config.root = File.dirname(__FILE__)
9
+ Rails.backtrace_cleaner.remove_silencers!
10
+ app.initialize!
11
+
12
+ app.routes.draw do
13
+ resources :widgets
14
+ end
15
+
16
+ InfluxDB::Rails.configure do |config|
17
+ config.api_key = "f123-e456-d789c012"
18
+ config.application_id = "b12r8c72"
19
+ end
20
+
21
+ class ApplicationController < ActionController::Base; end
22
+ class WidgetsController < ApplicationController
23
+ def index; render :nothing => true; end
24
+ def new; return 1/0; end
25
+ end
26
+
27
+ Object.const_set(:ApplicationHelper, Module.new)
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe InfluxDB::Rails::Backtrace do
4
+ before do
5
+ @raw_backtrace = [
6
+ "/var/www/current/app/models/foo.rb:10:in `bar'",
7
+ "/var/www/current/app/models/foo.rb:19:in `baz'",
8
+ "/var/www/current/app/models/foo.rb:32:in `<main>'"
9
+ ]
10
+
11
+ @backtrace = InfluxDB::Rails::Backtrace.new(@raw_backtrace)
12
+ end
13
+
14
+ it "should accept an exception into the initializer" do
15
+ @backtrace.lines.should_not be_empty
16
+ @backtrace.lines.count.should == 3
17
+ end
18
+
19
+ it "should correctly parse lines into their elements" do
20
+ line = @backtrace.lines.first
21
+
22
+ line.file.should == "/var/www/current/app/models/foo.rb"
23
+ line.number.should == "10"
24
+ line.method.should == "bar"
25
+ end
26
+
27
+ describe "#to_a" do
28
+ it "should return an array of lines" do
29
+ @backtrace.to_a.is_a?(Array).should be_true
30
+ end
31
+ end
32
+
33
+ context "nil backtrace" do
34
+ before do
35
+ @raw_backtrace = nil
36
+
37
+ @backtrace = InfluxDB::Rails::Backtrace.new(@raw_backtrace)
38
+ end
39
+
40
+ it "should accept an exception into the initializer" do
41
+ @backtrace.lines.should be_empty
42
+ @backtrace.lines.count.should == 0
43
+ end
44
+
45
+ describe "#to_a" do
46
+ it "should return an array of lines" do
47
+ @backtrace.to_a.is_a?(Array).should be_true
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ describe "backtrace filters" do
54
+ before do
55
+ InfluxDB::Rails.configure do |config|
56
+ config.application_root = "/var/www/current"
57
+ end
58
+ end
59
+
60
+ it "should apply a single default backtrace filter correctly" do
61
+ filtered_backtrace = InfluxDB::Rails::Backtrace.new(@raw_backtrace)
62
+
63
+ line = filtered_backtrace.lines.first
64
+ line.file.should == "[APP_ROOT]/app/models/foo.rb"
65
+ end
66
+
67
+ it "should all default backtrace filters correctly" do
68
+ extended_backtrace = @raw_backtrace.dup
69
+ extended_backtrace << "#{Gem.path.first}/lib/foo_gem.rb:1:in `blah'"
70
+
71
+ filtered_backtrace = InfluxDB::Rails::Backtrace.new(extended_backtrace)
72
+ filtered_backtrace.lines.first.file.should == "[APP_ROOT]/app/models/foo.rb"
73
+ filtered_backtrace.lines.last.file.should == "[GEM_ROOT]/lib/foo_gem.rb"
74
+ end
75
+
76
+ it "should allow the addition of custom backtrace filters" do
77
+ InfluxDB::Rails.configure do |config|
78
+ config.backtrace_filters << lambda { |line| line.gsub(/foo/, "F00") }
79
+ end
80
+
81
+ filtered_backtrace = InfluxDB::Rails::Backtrace.new(@raw_backtrace)
82
+
83
+ line = filtered_backtrace.lines.first
84
+ line.file.should == "[APP_ROOT]/app/models/F00.rb"
85
+ end
86
+ end
87
+ end
88
+
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe InfluxDB::Rails::Configuration do
4
+ before do
5
+ @configuration = InfluxDB::Rails::Configuration.new
6
+ end
7
+
8
+ describe "#ignore_user_agent?" do
9
+ it "should be true for user agents that have been set as ignorable" do
10
+ @configuration.ignored_user_agents = %w{Googlebot}
11
+ @configuration.ignore_user_agent?("Googlebot/2.1").should be_true
12
+ end
13
+
14
+ it "should be false for user agents that have not been set as ignorable" do
15
+ @configuration.ignored_user_agents = %w{Googlebot}
16
+ @configuration.ignore_user_agent?("Mozilla/5.0").should be_false
17
+ end
18
+
19
+ it "should be false if the ignored user agents list is empty" do
20
+ @configuration.ignored_user_agents = []
21
+ @configuration.ignore_user_agent?("Googlebot/2.1").should be_false
22
+ end
23
+
24
+ it "should be false if the ignored user agents list is inadvertently set to nil" do
25
+ @configuration.ignored_user_agents = nil
26
+ @configuration.ignore_user_agent?("Googlebot/2.1").should be_false
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe InfluxDB::Rails::ExceptionPresenter do
4
+ before do
5
+ begin
6
+ 1/0
7
+ rescue Exception => e
8
+ @exception = e
9
+ end
10
+ end
11
+
12
+ describe ".new" do
13
+ it "should create a new ExceptionPresenter" do
14
+ exception_presenter = InfluxDB::Rails::ExceptionPresenter.new(@exception)
15
+ exception_presenter.should be_a(InfluxDB::Rails::ExceptionPresenter)
16
+ end
17
+
18
+ it "should accept an exception as a parameter" do
19
+ exception_presenter = InfluxDB::Rails::ExceptionPresenter.new(@exception)
20
+ exception_presenter.should_not be_nil
21
+ end
22
+ end
23
+
24
+ # describe "#to_json" do
25
+ # it "should return a JSON string" do
26
+ # exception_presenter = InfluxDB::ExceptionPresenter.new(@exception)
27
+ # json = JSON.parse(exception_presenter.to_json)
28
+
29
+ # json["message"].should == "divided by 0"
30
+ # json["time"].should_not be_nil
31
+ # json["backtrace"].should_not be_nil
32
+ # end
33
+
34
+ # it "should include a custom hash if defined in the influxdb config" do
35
+ # InfluxDB.configure do |config|
36
+ # config.define_custom_exception_data do |exception_presenter|
37
+ # if exception_presenter.exception.class == ZeroDivisionError
38
+ # exception_presenter.hash = "some_hash"
39
+ # exception_presenter.custom_data[:extra_info] = "blah"
40
+ # end
41
+ # end
42
+ # end
43
+
44
+ # exception_presenter = InfluxDB::ExceptionPresenter.new(@exception)
45
+ # json = JSON.parse(exception_presenter.to_json)
46
+ # json["hash"].should == "some_hash"
47
+ # json["custom_data"]["extra_info"].should == "blah"
48
+ # end
49
+
50
+ # describe "environment variables" do
51
+ # it "should be filtered based on the contents of environment_variable_filters" do
52
+ # InfluxDB.configure do |config|
53
+ # config.environment_variable_filters = [/password/i]
54
+ # end
55
+
56
+ # exception_presenter = InfluxDB::ExceptionPresenter.new(
57
+ # :exception => @exception,
58
+ # :environment_variables => {
59
+ # "IMPORTANT_PASSWORD" => "sesame",
60
+ # "EDITOR" => "vim"
61
+ # })
62
+
63
+ # json = JSON.parse(exception_presenter.to_json)
64
+ # json["environment_variables"].size.should == 1
65
+ # json["environment_variables"].should == {"EDITOR" => "vim"}
66
+ # end
67
+ # end
68
+ # end
69
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe InfluxDB::Rails do
4
+ before do
5
+ InfluxDB::Rails.configure { |config| config.ignored_environments = [] }
6
+ end
7
+
8
+ describe ".ignorable_exception?" do
9
+ it "should be true for exception types specified in the configuration" do
10
+ class DummyException < Exception; end
11
+ exception = DummyException.new
12
+
13
+ InfluxDB::Rails.configure do |config|
14
+ config.ignored_exceptions << 'DummyException'
15
+ end
16
+
17
+ InfluxDB::Rails.ignorable_exception?(exception).should be_true
18
+ end
19
+
20
+ it "should be true for exception types specified in the configuration" do
21
+ exception = ActionController::RoutingError.new("foo")
22
+ InfluxDB::Rails.ignorable_exception?(exception).should be_true
23
+ end
24
+
25
+ it "should be false for valid exceptions" do
26
+ exception = ZeroDivisionError.new
27
+ InfluxDB::Rails.ignorable_exception?(exception).should be_false
28
+ end
29
+ end
30
+
31
+ describe 'rescue' do
32
+ it "should transmit an exception when passed" do
33
+ InfluxDB::Rails.configure do |config|
34
+ config.ignored_environments = []
35
+ config.instrumentation_enabled = false
36
+ end
37
+
38
+ InfluxDB::Rails.client.should_receive(:write_point)
39
+
40
+ InfluxDB::Rails.rescue do
41
+ raise ArgumentError.new('wrong')
42
+ end
43
+ end
44
+
45
+ it "should also raise the exception when in an ignored environment" do
46
+ InfluxDB::Rails.configure { |config| config.ignored_environments = %w{development test} }
47
+
48
+ expect {
49
+ InfluxDB::Rails.rescue do
50
+ raise ArgumentError.new('wrong')
51
+ end
52
+ }.to raise_error(ArgumentError)
53
+ end
54
+ end
55
+
56
+ describe "rescue_and_reraise" do
57
+ it "should transmit an exception when passed" do
58
+ InfluxDB::Rails.configure { |config| config.ignored_environments = [] }
59
+
60
+ InfluxDB::Rails.client.should_receive(:write_point)
61
+
62
+ expect {
63
+ InfluxDB::Rails.rescue_and_reraise { raise ArgumentError.new('wrong') }
64
+ }.to raise_error(ArgumentError)
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: influxdb-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Todd Persen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: influxdb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: tzinfo
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This gem automatically instruments your Ruby on Rails 3.x/4.x applications
140
+ using InfluxDB for storage.
141
+ email:
142
+ - todd@influxdb.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - config.ru
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - gemfiles/Gemfile.rails-3.0.x
151
+ - gemfiles/Gemfile.rails-3.0.x.lock
152
+ - gemfiles/Gemfile.rails-3.1.x
153
+ - gemfiles/Gemfile.rails-3.1.x.lock
154
+ - gemfiles/Gemfile.rails-3.2.x
155
+ - gemfiles/Gemfile.rails-3.2.x.lock
156
+ - gemfiles/Gemfile.rails-4.0.x
157
+ - gemfiles/Gemfile.rails-4.0.x.lock
158
+ - generators/influxdb/influxdb_generator.rb
159
+ - generators/influxdb/templates/initializer.rb
160
+ - influxdb-rails.gemspec
161
+ - lib/influxdb/rails/air_traffic_controller.rb
162
+ - lib/influxdb/rails/backtrace.rb
163
+ - lib/influxdb/rails/configuration.rb
164
+ - lib/influxdb/rails/exception_presenter.rb
165
+ - lib/influxdb/rails/instrumentation.rb
166
+ - lib/influxdb/rails/logger.rb
167
+ - lib/influxdb/rails/middleware/hijack_render_exception.rb
168
+ - lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb
169
+ - lib/influxdb/rails/rack.rb
170
+ - lib/influxdb/rails/rails.rb
171
+ - lib/influxdb/rails/railtie.rb
172
+ - lib/influxdb/rails/version.rb
173
+ - lib/influxdb-rails.rb
174
+ - lib/rails/generators/influxdb/influxdb_generator.rb
175
+ - lib/rails/generators/influxdb/templates/initializer.rb
176
+ - Rakefile
177
+ - README.md
178
+ - spec/controllers/widgets_controller_spec.rb
179
+ - spec/integration/exceptions_spec.rb
180
+ - spec/integration/integration_helper.rb
181
+ - spec/spec_helper.rb
182
+ - spec/suite.sh
183
+ - spec/support/rails3/app.rb
184
+ - spec/support/rails3/log/test.log
185
+ - spec/support/rails4/app.rb
186
+ - spec/unit/backtrace_spec.rb
187
+ - spec/unit/configuration_spec.rb
188
+ - spec/unit/exception_presenter_spec.rb
189
+ - spec/unit/influxdb_rails_spec.rb
190
+ homepage: http://influxdb.com
191
+ licenses:
192
+ - MIT
193
+ metadata: {}
194
+ post_install_message:
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ! '>='
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubyforge_project: influxdb-rails
210
+ rubygems_version: 2.1.11
211
+ signing_key:
212
+ specification_version: 4
213
+ summary: InfluxDB bindings for Ruby on Rails.
214
+ test_files:
215
+ - spec/controllers/widgets_controller_spec.rb
216
+ - spec/integration/exceptions_spec.rb
217
+ - spec/integration/integration_helper.rb
218
+ - spec/spec_helper.rb
219
+ - spec/suite.sh
220
+ - spec/support/rails3/app.rb
221
+ - spec/support/rails3/log/test.log
222
+ - spec/support/rails4/app.rb
223
+ - spec/unit/backtrace_spec.rb
224
+ - spec/unit/configuration_spec.rb
225
+ - spec/unit/exception_presenter_spec.rb
226
+ - spec/unit/influxdb_rails_spec.rb