influxdb-rails 1.0.0 → 1.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +1 -1
  5. data/.travis.yml +4 -7
  6. data/CHANGELOG.md +17 -0
  7. data/README.md +47 -5
  8. data/Rakefile +0 -6
  9. data/gemfiles/Gemfile.rails-5.0.x +2 -0
  10. data/gemfiles/Gemfile.rails-6.0.x +10 -0
  11. data/influxdb-rails.gemspec +5 -3
  12. data/lib/influxdb-rails.rb +11 -0
  13. data/lib/influxdb/rails/configuration.rb +8 -12
  14. data/lib/influxdb/rails/context.rb +6 -40
  15. data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
  16. data/lib/influxdb/rails/metric.rb +39 -0
  17. data/lib/influxdb/rails/middleware/active_job_subscriber.rb +67 -0
  18. data/lib/influxdb/rails/middleware/active_record_subscriber.rb +26 -0
  19. data/lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb +24 -0
  20. data/lib/influxdb/rails/middleware/render_subscriber.rb +15 -16
  21. data/lib/influxdb/rails/middleware/request_subscriber.rb +16 -21
  22. data/lib/influxdb/rails/middleware/sql_subscriber.rb +18 -18
  23. data/lib/influxdb/rails/middleware/subscriber.rb +40 -27
  24. data/lib/influxdb/rails/railtie.rb +15 -18
  25. data/lib/influxdb/rails/tags.rb +33 -0
  26. data/lib/influxdb/rails/test_client.rb +13 -0
  27. data/lib/influxdb/rails/values.rb +24 -0
  28. data/lib/influxdb/rails/version.rb +1 -1
  29. data/sample-dashboard/README.md +1 -1
  30. data/spec/requests/action_controller_metrics_spec.rb +83 -0
  31. data/spec/requests/action_view_collection_metrics_spec.rb +66 -0
  32. data/spec/requests/action_view_partial_metrics_spec.rb +62 -0
  33. data/spec/requests/action_view_template_metrics_spec.rb +62 -0
  34. data/spec/requests/active_job_enqueue_metrics_spec.rb +65 -0
  35. data/spec/requests/active_job_perform_metrics_spec.rb +68 -0
  36. data/spec/requests/active_job_perform_start_metrics_spec.rb +68 -0
  37. data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
  38. data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
  39. data/spec/requests/block_inistrumentation_spec.rb +64 -0
  40. data/spec/requests/context_spec.rb +27 -0
  41. data/spec/requests/logger_spec.rb +10 -0
  42. data/spec/spec_helper.rb +10 -4
  43. data/spec/support/broken_client.rb +11 -0
  44. data/spec/support/rails5/app.rb +32 -10
  45. data/spec/support/rails6/app.rb +70 -0
  46. data/spec/support/views/{widgets → metrics}/_item.html.erb +0 -0
  47. data/spec/support/views/{widgets → metrics}/index.html.erb +0 -0
  48. data/spec/support/views/metrics/show.html.erb +4 -0
  49. data/spec/unit/block_instrumentation_spec.rb +18 -0
  50. metadata +87 -37
  51. data/gemfiles/Gemfile.rails-4.2.x +0 -7
  52. data/lib/influxdb/rails/instrumentation.rb +0 -34
  53. data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -33
  54. data/spec/controllers/widgets_controller_spec.rb +0 -15
  55. data/spec/integration/integration_helper.rb +0 -1
  56. data/spec/integration/metrics_spec.rb +0 -27
  57. data/spec/shared_examples/data.rb +0 -61
  58. data/spec/support/rails4/app.rb +0 -48
  59. data/spec/unit/context_spec.rb +0 -40
  60. data/spec/unit/middleware/render_subscriber_spec.rb +0 -96
  61. data/spec/unit/middleware/request_subscriber_spec.rb +0 -103
  62. data/spec/unit/middleware/sql_subscriber_spec.rb +0 -108
@@ -0,0 +1,70 @@
1
+ require "action_controller/railtie"
2
+ require "active_record/railtie"
3
+ require "active_job"
4
+
5
+ app = Class.new(Rails::Application)
6
+ app.config.secret_key_base = "1234567890abcdef1234567890abcdef"
7
+ app.config.secret_token = "1234567890abcdef1234567890abcdef"
8
+ app.config.session_store :cookie_store, key: "_myapp_session"
9
+ app.config.active_support.deprecation = :log
10
+ app.config.eager_load = false
11
+ app.config.root = __dir__
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+ ActiveJob::Base.logger = Rails.logger
14
+ app.initialize!
15
+
16
+ app.routes.draw do
17
+ resources :metrics, only: %i[index show]
18
+ resources :exceptions, only: :index
19
+ end
20
+
21
+ InfluxDB::Rails.configure do |config|
22
+ end
23
+
24
+ ENV["DATABASE_URL"] = "sqlite3::memory:"
25
+ ActiveRecord::Schema.define do
26
+ create_table :metrics, force: true do |t|
27
+ t.string :name
28
+
29
+ t.timestamps
30
+ end
31
+ end
32
+
33
+ class MetricJob < ActiveJob::Base
34
+ queue_as :default
35
+
36
+ def perform
37
+ # Do something later
38
+ end
39
+ end
40
+
41
+ class Metric < ActiveRecord::Base; end
42
+ class ApplicationController < ActionController::Base; end
43
+ class MetricsController < ApplicationController
44
+ prepend_view_path File.join(__dir__, "..", "views")
45
+
46
+ before_action do
47
+ InfluxDB::Rails.current.values = { additional_value: :value }
48
+ InfluxDB::Rails.current.tags = { additional_tag: :value }
49
+ end
50
+
51
+ def index
52
+ InfluxDB::Rails.instrument "name", tags: { block_tag: :block_tag }, values: { block_value: :block_value } do
53
+ 1 + 1
54
+ end
55
+ MetricJob.perform_later
56
+ Metric.create!(name: "name")
57
+ end
58
+
59
+ def show
60
+ @metric = Metric.find_by(name: "name")
61
+ end
62
+ end
63
+
64
+ class ExceptionsController < ApplicationController
65
+ def index
66
+ 1 / 0
67
+ end
68
+ end
69
+
70
+ Object.const_set(:ApplicationHelper, Module.new)
@@ -0,0 +1,4 @@
1
+ <h1>Show</h1>
2
+ <div>
3
+ <%= @metric.name %>
4
+ </div>
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe InfluxDB::Rails do
4
+ describe ".instrument" do
5
+ it "supports calling wihout a block" do
6
+ InfluxDB::Rails.instrument "name", values: { value: 1 }
7
+
8
+ expect_metric(
9
+ values: a_hash_including(value: 1),
10
+ tags: a_hash_including(
11
+ hook: "block_instrumentation",
12
+ server: Socket.gethostname,
13
+ location: :raw
14
+ )
15
+ )
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Bruckmayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-23 00:00:00.000000000 Z
12
+ date: 2020-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: influxdb
@@ -37,14 +37,28 @@ dependencies:
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: '5.0'
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.2'
47
+ version: '5.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: activejob
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: activerecord
50
64
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +101,20 @@ dependencies:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: launchy
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
90
118
  - !ruby/object:Gem::Dependency
91
119
  name: pry
92
120
  requirement: !ruby/object:Gem::Requirement
@@ -175,16 +203,16 @@ dependencies:
175
203
  name: sqlite3
176
204
  requirement: !ruby/object:Gem::Requirement
177
205
  requirements:
178
- - - '='
206
+ - - ">="
179
207
  - !ruby/object:Gem::Version
180
- version: 1.3.13
208
+ version: '0'
181
209
  type: :development
182
210
  prerelease: false
183
211
  version_requirements: !ruby/object:Gem::Requirement
184
212
  requirements:
185
- - - '='
213
+ - - ">="
186
214
  - !ruby/object:Gem::Version
187
- version: 1.3.13
215
+ version: '0'
188
216
  - !ruby/object:Gem::Dependency
189
217
  name: tzinfo
190
218
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +235,7 @@ executables: []
207
235
  extensions: []
208
236
  extra_rdoc_files: []
209
237
  files:
238
+ - ".github/dependabot.yml"
210
239
  - ".gitignore"
211
240
  - ".rspec"
212
241
  - ".rubocop.yml"
@@ -217,23 +246,29 @@ files:
217
246
  - README.md
218
247
  - Rakefile
219
248
  - config.ru
220
- - gemfiles/Gemfile.rails-4.2.x
221
249
  - gemfiles/Gemfile.rails-5.0.x
222
250
  - gemfiles/Gemfile.rails-5.1.x
223
251
  - gemfiles/Gemfile.rails-5.2.x
252
+ - gemfiles/Gemfile.rails-6.0.x
224
253
  - influxdb-rails.gemspec
225
254
  - lib/influxdb-rails.rb
226
255
  - lib/influxdb/rails/configuration.rb
227
256
  - lib/influxdb/rails/context.rb
228
- - lib/influxdb/rails/instrumentation.rb
257
+ - lib/influxdb/rails/helpers/rspec_matchers.rb
258
+ - lib/influxdb/rails/metric.rb
259
+ - lib/influxdb/rails/middleware/active_job_subscriber.rb
260
+ - lib/influxdb/rails/middleware/active_record_subscriber.rb
261
+ - lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb
229
262
  - lib/influxdb/rails/middleware/render_subscriber.rb
230
263
  - lib/influxdb/rails/middleware/request_subscriber.rb
231
- - lib/influxdb/rails/middleware/simple_subscriber.rb
232
264
  - lib/influxdb/rails/middleware/sql_subscriber.rb
233
265
  - lib/influxdb/rails/middleware/subscriber.rb
234
266
  - lib/influxdb/rails/railtie.rb
235
267
  - lib/influxdb/rails/sql/normalizer.rb
236
268
  - lib/influxdb/rails/sql/query.rb
269
+ - lib/influxdb/rails/tags.rb
270
+ - lib/influxdb/rails/test_client.rb
271
+ - lib/influxdb/rails/values.rb
237
272
  - lib/influxdb/rails/version.rb
238
273
  - lib/rails/generators/influxdb/influxdb_generator.rb
239
274
  - lib/rails/generators/influxdb/templates/initializer.rb
@@ -249,20 +284,27 @@ files:
249
284
  - sample-dashboard/provisioning/performance-action.json
250
285
  - sample-dashboard/provisioning/performance-request.json
251
286
  - sample-dashboard/provisioning/performance.json
252
- - spec/controllers/widgets_controller_spec.rb
253
- - spec/integration/integration_helper.rb
254
- - spec/integration/metrics_spec.rb
255
- - spec/shared_examples/data.rb
287
+ - spec/requests/action_controller_metrics_spec.rb
288
+ - spec/requests/action_view_collection_metrics_spec.rb
289
+ - spec/requests/action_view_partial_metrics_spec.rb
290
+ - spec/requests/action_view_template_metrics_spec.rb
291
+ - spec/requests/active_job_enqueue_metrics_spec.rb
292
+ - spec/requests/active_job_perform_metrics_spec.rb
293
+ - spec/requests/active_job_perform_start_metrics_spec.rb
294
+ - spec/requests/active_record_instantiation_metrics_spec.rb
295
+ - spec/requests/active_record_sql_metrics_spec.rb
296
+ - spec/requests/block_inistrumentation_spec.rb
297
+ - spec/requests/context_spec.rb
298
+ - spec/requests/logger_spec.rb
256
299
  - spec/spec_helper.rb
257
- - spec/support/rails4/app.rb
300
+ - spec/support/broken_client.rb
258
301
  - spec/support/rails5/app.rb
259
- - spec/support/views/widgets/_item.html.erb
260
- - spec/support/views/widgets/index.html.erb
302
+ - spec/support/rails6/app.rb
303
+ - spec/support/views/metrics/_item.html.erb
304
+ - spec/support/views/metrics/index.html.erb
305
+ - spec/support/views/metrics/show.html.erb
306
+ - spec/unit/block_instrumentation_spec.rb
261
307
  - spec/unit/configuration_spec.rb
262
- - spec/unit/context_spec.rb
263
- - spec/unit/middleware/render_subscriber_spec.rb
264
- - spec/unit/middleware/request_subscriber_spec.rb
265
- - spec/unit/middleware/sql_subscriber_spec.rb
266
308
  - spec/unit/sql/normalizer_spec.rb
267
309
  - spec/unit/sql/query_spec.rb
268
310
  homepage: https://influxdata.com
@@ -281,31 +323,39 @@ required_ruby_version: !ruby/object:Gem::Requirement
281
323
  requirements:
282
324
  - - ">="
283
325
  - !ruby/object:Gem::Version
284
- version: 2.3.0
326
+ version: 2.4.0
285
327
  required_rubygems_version: !ruby/object:Gem::Requirement
286
328
  requirements:
287
- - - ">="
329
+ - - ">"
288
330
  - !ruby/object:Gem::Version
289
- version: '0'
331
+ version: 1.3.1
290
332
  requirements: []
291
- rubygems_version: 3.0.3
333
+ rubyforge_project:
334
+ rubygems_version: 2.7.6.2
292
335
  signing_key:
293
336
  specification_version: 4
294
337
  summary: InfluxDB bindings for Ruby on Rails.
295
338
  test_files:
296
- - spec/controllers/widgets_controller_spec.rb
297
- - spec/integration/integration_helper.rb
298
- - spec/integration/metrics_spec.rb
299
- - spec/shared_examples/data.rb
339
+ - spec/requests/action_controller_metrics_spec.rb
340
+ - spec/requests/action_view_collection_metrics_spec.rb
341
+ - spec/requests/action_view_partial_metrics_spec.rb
342
+ - spec/requests/action_view_template_metrics_spec.rb
343
+ - spec/requests/active_job_enqueue_metrics_spec.rb
344
+ - spec/requests/active_job_perform_metrics_spec.rb
345
+ - spec/requests/active_job_perform_start_metrics_spec.rb
346
+ - spec/requests/active_record_instantiation_metrics_spec.rb
347
+ - spec/requests/active_record_sql_metrics_spec.rb
348
+ - spec/requests/block_inistrumentation_spec.rb
349
+ - spec/requests/context_spec.rb
350
+ - spec/requests/logger_spec.rb
300
351
  - spec/spec_helper.rb
301
- - spec/support/rails4/app.rb
352
+ - spec/support/broken_client.rb
302
353
  - spec/support/rails5/app.rb
303
- - spec/support/views/widgets/_item.html.erb
304
- - spec/support/views/widgets/index.html.erb
354
+ - spec/support/rails6/app.rb
355
+ - spec/support/views/metrics/_item.html.erb
356
+ - spec/support/views/metrics/index.html.erb
357
+ - spec/support/views/metrics/show.html.erb
358
+ - spec/unit/block_instrumentation_spec.rb
305
359
  - spec/unit/configuration_spec.rb
306
- - spec/unit/context_spec.rb
307
- - spec/unit/middleware/render_subscriber_spec.rb
308
- - spec/unit/middleware/request_subscriber_spec.rb
309
- - spec/unit/middleware/sql_subscriber_spec.rb
310
360
  - spec/unit/sql/normalizer_spec.rb
311
361
  - spec/unit/sql/query_spec.rb
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'actionpack', '~> 4.2.0'
4
- gem 'activesupport', '~> 4.2.0'
5
- gem 'activemodel', '~> 4.2.0'
6
-
7
- gemspec :path => '../'
@@ -1,34 +0,0 @@
1
- module InfluxDB
2
- module Rails
3
- module Instrumentation
4
- def benchmark_for_instrumentation # rubocop:disable Metrics/MethodLength
5
- start = Time.now
6
- yield
7
-
8
- c = InfluxDB::Rails.configuration
9
- return if c.ignore_current_environment?
10
-
11
- InfluxDB::Rails.client.write_point \
12
- "instrumentation".freeze,
13
- values: {
14
- value: ((Time.now - start) * 1000).ceil,
15
- },
16
- tags: c.tags_middleware.call(
17
- method: "#{controller_name}##{action_name}",
18
- server: Socket.gethostname
19
- )
20
- end
21
-
22
- def self.included(base)
23
- base.extend(ClassMethods)
24
- end
25
-
26
- module ClassMethods
27
- def instrument(methods = [])
28
- methods = [methods] unless methods.is_a?(Array)
29
- around_filter :benchmark_for_instrumentation, only: methods
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- require "influxdb/rails/middleware/subscriber"
2
-
3
- module InfluxDB
4
- module Rails
5
- module Middleware
6
- # Subscriber acts as base class for different *Subscriber classes,
7
- # which are intended as ActiveSupport::Notifications.subscribe
8
- # consumers.
9
- class SimpleSubscriber < Subscriber
10
- def call(_name, started, finished, _id, payload)
11
- return unless enabled?
12
-
13
- InfluxDB::Rails.client.write_point \
14
- configuration.measurement_name,
15
- values: values(started, finished, payload),
16
- tags: tags(payload),
17
- timestamp: timestamp(finished)
18
- rescue StandardError => e
19
- ::Rails.logger.error("[InfluxDB::Rails] Unable to write points: #{e.message}")
20
- end
21
-
22
- private
23
-
24
- def values(started, finished, _payload)
25
- result = { value: ((finished - started) * 1000).ceil }
26
- result.merge(InfluxDB::Rails.current.values).reject do |_, value|
27
- value.nil? || value == ""
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe WidgetsController, type: :controller do
4
- describe "#new" do
5
- it "should raise an exception" do
6
- expect { get :new }.to raise_error(ZeroDivisionError)
7
- end
8
- end
9
-
10
- describe "#index" do
11
- it "should not raise an exception" do
12
- expect { get :index }.to_not raise_error
13
- end
14
- end
15
- end
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
@@ -1,27 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/integration_helper")
2
-
3
- RSpec.describe "User visits widgets", type: :request do
4
- before do
5
- allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development])
6
- end
7
-
8
- describe "in a normal request" do
9
- it "should result in attempts to write metrics via the client" do
10
- expect(InfluxDB::Rails.client).to receive(:write_point).exactly(5).times
11
- get "/widgets"
12
- end
13
-
14
- context "additional values" do
15
- it "should result in attempts to write metrics via the client" do
16
- allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
17
- expect(InfluxDB::Rails.client).to receive(:write_point).with(
18
- "rails", a_hash_including(
19
- tags: a_hash_including(method: "WidgetsController#index", hook: "process_action"),
20
- values: a_hash_including(request_id: :request_id, key: :value)
21
- )
22
- )
23
- get "/widgets"
24
- end
25
- end
26
- end
27
- end