influxdb-rails 0.4.999 → 1.0.0.beta1

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.
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  RSpec.describe InfluxDB::Rails::ExceptionPresenter do
4
4
  before do
5
5
  begin
6
- 1/0
7
- rescue Exception => e
6
+ 1 / 0
7
+ rescue ZeroDivisionError => e
8
8
  @exception = e
9
9
  end
10
10
  end
@@ -1,66 +1,119 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  RSpec.describe InfluxDB::Rails do
4
4
  before do
5
- InfluxDB::Rails.configure { |config| config.ignored_environments = [] }
5
+ InfluxDB::Rails.configure do |config|
6
+ config.application_name = "my-rails-app"
7
+ config.ignored_environments = []
8
+ config.time_precision = "ms"
9
+ end
6
10
  end
7
11
 
8
- describe '.convert_timestamp' do
9
- let(:sometime) { Time.parse('2017-12-11 16:20:29.111222333 UTC') }
10
- let(:configuration) { double("Configuration") }
11
- before { allow(InfluxDB::Rails).to receive(:configuration).and_return configuration }
12
-
13
- it "should return the timestamp in nanoseconds when precision is 'ns'" do
14
- allow(configuration).to receive(:time_precision).and_return('ns')
15
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(1513009229111222272)
16
- end
17
- it "should return the timestamp in nanoseconds when precision is nil" do
18
- allow(configuration).to receive(:time_precision)
19
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(1513009229111222272)
20
- end
21
- it "should return the timestamp in microseconds when precision is u" do
22
- allow(configuration).to receive(:time_precision).and_return('u')
23
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(1513009229111222)
24
- end
25
- it "should return the timestamp in milliseconds when precision is ms" do
26
- allow(configuration).to receive(:time_precision).and_return('ms')
27
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(1513009229111)
12
+ describe ".handle_action_controller_metrics" do
13
+ let(:start) { Time.at(1_517_567_368) }
14
+ let(:finish) { Time.at(1_517_567_370) }
15
+ let(:payload) { { view_runtime: 2, db_runtime: 2, controller: "MyController", action: "show", method: "GET", format: "*/*", path: "/posts", status: 200 } }
16
+ let(:data) do
17
+ {
18
+ values: {
19
+ value: 2
20
+ },
21
+ tags: {
22
+ method: "MyController#show",
23
+ status: 200,
24
+ format: "*/*",
25
+ http_method: "GET",
26
+ path: "/posts",
27
+ server: Socket.gethostname,
28
+ app_name: "my-rails-app",
29
+ },
30
+ timestamp: 1_517_567_370_000
31
+ }
28
32
  end
29
- it "should return the timestamp in seconds when precision is s" do
30
- allow(configuration).to receive(:time_precision).and_return('s')
31
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(1513009229)
33
+
34
+ context "application_name is set" do
35
+ it "sends metrics with taggings and timestamps" do
36
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
37
+ "rails.controller", data.merge(values: { value: 2000 })
38
+ )
39
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.view", data)
40
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.db", data)
41
+
42
+ described_class.handle_action_controller_metrics("unused", start, finish, "unused", payload)
43
+ end
32
44
  end
33
- it "should return the timestamp in minutes when precision is m" do
34
- allow(configuration).to receive(:time_precision).and_return('m')
35
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(25216820)
45
+
46
+ context "application_name is nil" do
47
+ before do
48
+ InfluxDB::Rails.configure do |config|
49
+ config.application_name = nil
50
+ end
51
+ end
52
+
53
+ it "does not add the app_name tag to metrics" do
54
+ tags = {
55
+ method: "MyController#show",
56
+ status: 200,
57
+ format: "*/*",
58
+ http_method: "GET",
59
+ path: "/posts",
60
+ server: Socket.gethostname,
61
+ }
62
+
63
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
64
+ "rails.controller", data.merge(values: { value: 2000 }, tags: tags)
65
+ )
66
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.view", data.merge(tags: tags))
67
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.db", data.merge(tags: tags))
68
+
69
+ described_class.handle_action_controller_metrics("unused", start, finish, "unused", payload)
70
+ end
36
71
  end
37
- it "should return the timestamp in hours when precision is h" do
38
- allow(configuration).to receive(:time_precision).and_return('h')
39
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(420280)
72
+ end
73
+
74
+ describe ".convert_timestamp" do
75
+ let(:sometime) { Time.parse("2017-12-11 16:20:29.111222333 UTC") }
76
+ let(:configuration) { double("Configuration") }
77
+ before { allow(InfluxDB::Rails).to receive(:configuration).and_return configuration }
78
+
79
+ {
80
+ "ns" => 1_513_009_229_111_222_333,
81
+ nil => 1_513_009_229_111_222_333,
82
+ "u" => 1_513_009_229_111_222,
83
+ "ms" => 1_513_009_229_111,
84
+ "s" => 1_513_009_229,
85
+ "m" => 25_216_820,
86
+ "h" => 420_280,
87
+ }.each do |precision, converted_value|
88
+ it "should return the timestamp in nanoseconds when precision is #{precision.inspect}" do
89
+ allow(configuration).to receive(:time_precision).and_return(precision)
90
+ expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(converted_value)
91
+ end
40
92
  end
93
+
41
94
  it "should raise an excpetion when precision is unrecognized" do
42
- allow(configuration).to receive(:time_precision).and_return('whatever')
43
- expect{InfluxDB::Rails.convert_timestamp(sometime)}.
44
- to raise_exception /invalid time precision.*whatever/i
95
+ allow(configuration).to receive(:time_precision).and_return("whatever")
96
+ expect { InfluxDB::Rails.convert_timestamp(sometime) }
97
+ .to raise_exception(/invalid time precision.*whatever/i)
45
98
  end
46
99
  end
47
100
 
48
- describe '.current_timestamp' do
101
+ describe ".current_timestamp" do
49
102
  it "should return the current timestamp in the configured precision" do
50
- now = Time.parse('2017-12-11 16:20:29.111222333 UTC')
103
+ now = Time.parse("2017-12-11 16:20:29.111222333 UTC")
51
104
  allow(Time).to receive(:now).and_return(now)
52
- InfluxDB::Rails.configure {|config| config.time_precision = 'ms'}
53
- expect(InfluxDB::Rails.current_timestamp).to eq(1513009229111)
105
+ InfluxDB::Rails.configure { |config| config.time_precision = "ms" }
106
+ expect(InfluxDB::Rails.current_timestamp).to eq(1_513_009_229_111)
54
107
  end
55
108
  end
56
109
 
57
110
  describe ".ignorable_exception?" do
58
111
  it "should be true for exception types specified in the configuration" do
59
- class DummyException < Exception; end
112
+ class DummyException < RuntimeError; end
60
113
  exception = DummyException.new
61
114
 
62
115
  InfluxDB::Rails.configure do |config|
63
- config.ignored_exceptions << 'DummyException'
116
+ config.ignored_exceptions << "DummyException"
64
117
  end
65
118
 
66
119
  expect(InfluxDB::Rails.ignorable_exception?(exception)).to be_truthy
@@ -77,40 +130,35 @@ RSpec.describe InfluxDB::Rails do
77
130
  end
78
131
  end
79
132
 
80
- describe 'rescue' do
133
+ describe "rescue" do
81
134
  it "should transmit an exception when passed" do
82
- InfluxDB::Rails.configure do |config|
83
- config.ignored_environments = []
84
- config.instrumentation_enabled = false
85
- end
86
-
87
135
  expect(InfluxDB::Rails.client).to receive(:write_point)
88
136
 
89
137
  InfluxDB::Rails.rescue do
90
- raise ArgumentError.new('wrong')
138
+ raise ArgumentError, "wrong"
91
139
  end
92
140
  end
93
141
 
94
142
  it "should also raise the exception when in an ignored environment" do
95
- InfluxDB::Rails.configure { |config| config.ignored_environments = %w{development test} }
143
+ InfluxDB::Rails.configure do |config|
144
+ config.ignored_environments = %w[development test]
145
+ end
96
146
 
97
- expect {
147
+ expect do
98
148
  InfluxDB::Rails.rescue do
99
- raise ArgumentError.new('wrong')
149
+ raise ArgumentError, "wrong"
100
150
  end
101
- }.to raise_error(ArgumentError)
151
+ end.to raise_error(ArgumentError)
102
152
  end
103
153
  end
104
154
 
105
155
  describe "rescue_and_reraise" do
106
156
  it "should transmit an exception when passed" do
107
- InfluxDB::Rails.configure { |config| config.ignored_environments = [] }
108
-
109
157
  expect(InfluxDB::Rails.client).to receive(:write_point)
110
158
 
111
- expect {
112
- InfluxDB::Rails.rescue_and_reraise { raise ArgumentError.new('wrong') }
113
- }.to raise_error(ArgumentError)
159
+ expect do
160
+ InfluxDB::Rails.rescue_and_reraise { raise ArgumentError, "wrong" }
161
+ end.to raise_error(ArgumentError)
114
162
  end
115
163
  end
116
164
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.999
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
- - Christian Bruckmayer
8
- - Henne Vogelsang
7
+ - Dominik Menke
8
+ - Todd Persen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-02 00:00:00.000000000 Z
12
+ date: 2018-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: influxdb
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: 3.0.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 0.60.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.60.0
126
140
  - !ruby/object:Gem::Dependency
127
141
  name: tzinfo
128
142
  requirement: !ruby/object:Gem::Requirement
@@ -137,17 +151,18 @@ dependencies:
137
151
  - - ">="
138
152
  - !ruby/object:Gem::Version
139
153
  version: '0'
140
- description: This gem automatically instruments your Ruby on Rails application using
141
- InfluxDB.
154
+ description: This gem automatically instruments your Ruby on Rails 4.2/5.x applications
155
+ using InfluxDB for storage.
142
156
  email:
143
- - christian@bruckmayer.net
144
- - hvogel@hennevogel.de
157
+ - dominik.menke@gmail.com
158
+ - todd@influxdb.com
145
159
  executables: []
146
160
  extensions: []
147
161
  extra_rdoc_files: []
148
162
  files:
149
163
  - ".gitignore"
150
164
  - ".rspec"
165
+ - ".rubocop.yml"
151
166
  - ".travis.yml"
152
167
  - CHANGELOG.md
153
168
  - Gemfile
@@ -155,11 +170,10 @@ files:
155
170
  - README.md
156
171
  - Rakefile
157
172
  - config.ru
158
- - gemfiles/Gemfile.rails-4.0.x
159
- - gemfiles/Gemfile.rails-4.1.x
160
173
  - gemfiles/Gemfile.rails-4.2.x
161
174
  - gemfiles/Gemfile.rails-5.0.x
162
175
  - gemfiles/Gemfile.rails-5.1.x
176
+ - gemfiles/Gemfile.rails-5.2.x
163
177
  - influxdb-rails.gemspec
164
178
  - lib/influxdb-rails.rb
165
179
  - lib/influxdb/rails/air_traffic_controller.rb
@@ -181,29 +195,16 @@ files:
181
195
  - spec/integration/metrics_spec.rb
182
196
  - spec/spec_helper.rb
183
197
  - spec/support/rails4/app.rb
184
- - spec/support/rails4/log/test.log
185
198
  - spec/support/rails5/app.rb
186
- - spec/support/rails5/log/development.log
187
- - spec/support/rails5/log/test.log
188
199
  - spec/unit/backtrace_spec.rb
189
200
  - spec/unit/configuration_spec.rb
190
201
  - spec/unit/exception_presenter_spec.rb
191
202
  - spec/unit/influxdb_rails_spec.rb
192
- homepage: http://influxdb.com
203
+ homepage: https://influxdata.com
193
204
  licenses:
194
205
  - MIT
195
- metadata:
196
- bug_tracker_uri: https://github.com/influxdata/influxdb-rails/issues
197
- changelog_uri: https://github.com/influxdata/influxdb-rails/blob/master/CHANGELOG.md
198
- documentation_uri: https://github.com/influxdata/influxdb-rails/blob/master/README.md
199
- source_code_uri: https://github.com/influxdata/influxdb-rails
200
- post_install_message: |2+
201
-
202
- This is the last supported version of influxdb-rails in the 0.4 series. The
203
- next release will be 1.0 with quite a lot of breaking changes. For details:
204
-
205
- https://github.com/influxdata/influxdb-rails/wiki/1.0-Upgrade-Guide
206
-
206
+ metadata: {}
207
+ post_install_message:
207
208
  rdoc_options: []
208
209
  require_paths:
209
210
  - lib
@@ -211,29 +212,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
212
  requirements:
212
213
  - - ">="
213
214
  - !ruby/object:Gem::Version
214
- version: '0'
215
+ version: 2.3.0
215
216
  required_rubygems_version: !ruby/object:Gem::Requirement
216
217
  requirements:
217
- - - ">="
218
+ - - ">"
218
219
  - !ruby/object:Gem::Version
219
- version: '0'
220
+ version: 1.3.1
220
221
  requirements: []
221
- rubygems_version: 3.0.1
222
+ rubyforge_project:
223
+ rubygems_version: 2.7.6
222
224
  signing_key:
223
225
  specification_version: 4
224
226
  summary: InfluxDB bindings for Ruby on Rails.
225
227
  test_files:
226
- - spec/spec_helper.rb
227
- - spec/unit/influxdb_rails_spec.rb
228
- - spec/unit/backtrace_spec.rb
229
- - spec/unit/configuration_spec.rb
230
- - spec/unit/exception_presenter_spec.rb
228
+ - spec/controllers/widgets_controller_spec.rb
231
229
  - spec/integration/exceptions_spec.rb
232
230
  - spec/integration/integration_helper.rb
233
231
  - spec/integration/metrics_spec.rb
232
+ - spec/spec_helper.rb
234
233
  - spec/support/rails4/app.rb
235
- - spec/support/rails4/log/test.log
236
234
  - spec/support/rails5/app.rb
237
- - spec/support/rails5/log/test.log
238
- - spec/support/rails5/log/development.log
239
- - spec/controllers/widgets_controller_spec.rb
235
+ - spec/unit/backtrace_spec.rb
236
+ - spec/unit/configuration_spec.rb
237
+ - spec/unit/exception_presenter_spec.rb
238
+ - spec/unit/influxdb_rails_spec.rb
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'actionpack', '~> 4.0.0'
4
- gem 'activesupport', '~> 4.0.0'
5
- gem 'activemodel', '~> 4.0.0'
6
- gem 'rspec-rails', '>= 2.0'
7
-
8
- gemspec :path => '../'
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'actionpack', '~> 4.1.0'
4
- gem 'activesupport', '~> 4.1.0'
5
- gem 'activemodel', '~> 4.1.0'
6
-
7
- gemspec :path => '../'