influxdb-rails 1.0.0.beta2 → 1.0.0.beta3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7b5a411b14d5a465a1a4c503498d8c642de1c818213dfe3e437a1177eefa5d1
4
- data.tar.gz: f50dc54acb96ac4e9b758aa5be109ffd40a1396b4e43844800fc670496c1d76c
3
+ metadata.gz: c8e24e0318b414fc061b67a99de2cacebd24be2b383475367262e8538a36091e
4
+ data.tar.gz: b5f8f6bf8e22f7deeeb49412c2728ef6d0271e8ba4d987a410e3c07daf928f72
5
5
  SHA512:
6
- metadata.gz: 123a265d9418ff25a10b469cb798e9ed004af8a679fde861c40f81c5f96a20aea192576d10dfed877293afa6c59412cccb40d0b7fd14e52461aaa76c6712c092
7
- data.tar.gz: 6189e83dfce1d8812c0ce8553f3095ee0be21608f71db0375edc1e6aab4cfaf646675d481ed53144056437b853df71a9e9085009fea936384a167bdac41d0433
6
+ metadata.gz: 5d3d4fae5ac74cb363ae2eb8cb8370172ba924ef8a131320e26d48fa1517e0a8f885407eaf27210c2c8bf37a55b076b4b43c41ce5ec51e3a87b78443d8ecee90
7
+ data.tar.gz: 8b531e4b1b9a1dc3d40c6e2661a5249844f6183b86cc1f763bd51bb844642b1e51aa1cc3f363272f9a79e8148faa1b5ba3a948074341c969c9b9b63c341edd52
@@ -7,9 +7,10 @@ before_install:
7
7
  - gem update bundler --no-doc
8
8
  rvm:
9
9
  - ruby-head
10
- - 2.5.3
11
- - 2.4.5
12
- - 2.3.8
10
+ - "2.6"
11
+ - "2.5"
12
+ - "2.4"
13
+ - "2.3"
13
14
  gemfile:
14
15
  - gemfiles/Gemfile.rails-5.2.x
15
16
  - gemfiles/Gemfile.rails-5.1.x
@@ -21,12 +22,13 @@ matrix:
21
22
  allow_failures:
22
23
  - rvm: ruby-head
23
24
  include:
24
- - { rvm: "2.5.3", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
25
+ - { rvm: "2.6", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
25
26
  exclude:
26
27
  # Rails < 5 not on MRI 2.4+
27
28
  - { rvm: ruby-head, gemfile: "gemfiles/Gemfile.rails-4.2.x" }
28
- - { rvm: "2.4.5", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
29
- - { rvm: "2.5.3", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
29
+ - { rvm: "2.6", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
30
+ - { rvm: "2.5", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
31
+ - { rvm: "2.4", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
30
32
  addons:
31
33
  apt:
32
34
  packages:
@@ -3,9 +3,17 @@
3
3
  For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/master).
4
4
 
5
5
 
6
+ ## v1.0.0.beta3, released 2019-01-07
7
+
8
+ - Add dynamic tags (#62, @ChrisBr)
9
+ - Reduce cardinality of resulting InfluxDB measurement by moving
10
+ some tags to values (#63, @ChrisBr)
11
+ - Remove SCHEMA queries from SQL instrumentation (#61, @ChrisBr)
12
+
13
+
6
14
  ## v1.0.0.beta2, released 2018-12-07
7
15
 
8
- - Added `tags_middleware` config option (#47, @ @Kukunin)
16
+ - Added `tags_middleware` config option (#47, @Kukunin)
9
17
  - Removed path tag from metrics (introduced with #50), because it
10
18
  potentially produces "exceed tag value limit" (#54, @ChrisBr)
11
19
  - Added render instrumentation (#53, @ChrisBr)
data/README.md CHANGED
@@ -86,11 +86,14 @@ It is possible to disable the rendering series by setting the series_name to nil
86
86
  # config.series_name_for_render_collection = nil
87
87
  ```
88
88
 
89
- You can also call through to the underlying `InfluxDB::Client` object to write arbitrary data like this:
89
+ You can also call through to the underlying `InfluxDB::Client` object to write arbitrary data.
90
+ If you do that, it might be usefull to add the current context to these custom data points which can get
91
+ accessed with ``InfluxDB::Rails.current.location``.
92
+
90
93
 
91
94
  ``` ruby
92
95
  InfluxDB::Rails.client.write_point "events",
93
- tags: { url: "/foo", user_id: current_user.id },
96
+ tags: { url: "/foo", user_id: current_user.id, location: InfluxDB::Rails.current.location },
94
97
  values: { value: 0 }
95
98
  ```
96
99
 
@@ -113,18 +116,60 @@ InfluxDB::Rails.configure do |config|
113
116
  end
114
117
  ```
115
118
 
119
+ If you want to add dynamically tags per request, you can access the ``InfluxDB::Rails.current.tags`` to
120
+ do so. For instance, you could add the current user as tag to every data point.
121
+
122
+ ```ruby
123
+ class ApplicationController
124
+
125
+ before_action :set_influx_tags
126
+
127
+ def set_influx_tags
128
+ InfluxDB::Rails.current.tags = { user: current_user.id }
129
+ end
130
+ end
131
+
132
+ ```
133
+
116
134
  By default, the following tags are sent for *non-exception series*
117
135
  (`rails.controller`, `rails.view`, `rails.db` and `instrumentation`):
118
136
 
119
137
  ```ruby
120
138
  {
121
- method: "#{payload[:controller]}##{payload[:action]}",
122
- server: Socket.gethostname,
123
- app_name: configuration.application_name,
139
+ method: "#{payload[:controller]}##{payload[:action]}",
140
+ server: Socket.gethostname,
141
+ app_name: configuration.application_name,
142
+ http_method: payload[:method],
143
+ format: payload[:format],
144
+ status: payload[:status]
124
145
  }
125
146
  ```
147
+ For the render series (``rails.render_partial``, ``rails.render_view`` and ``rails.render_collection``)
148
+
149
+ ```ruby
150
+ server: Socket.gethostname,
151
+ app_name: configuration.application_name,
152
+ location: "#{payload[:controller]}##{payload[:action]}",
153
+ filename: payload[:identifier],
154
+ count: payload[:count],
155
+ cache_hits: payload[:cache_hits],
156
+ ```
157
+
158
+ For the SQL series (``rails.sql``, disabled by default)
159
+
160
+ ```ruby
161
+ server: Socket.gethostname,
162
+ app_name: configuration.application_name,
163
+ location: "#{payload[:controller]}##{payload[:action]}",,
164
+ operation: "SELECT",
165
+ class_name: "USER",
166
+ name: payload[:name],
167
+ ```
168
+
169
+ For more information about the payload, have a look at the [official ActiveSupport documentation](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller).
170
+
126
171
 
127
- and for the exceptions (series name `rails.exceptions`):
172
+ For the exceptions (series name `rails.exceptions`):
128
173
 
129
174
  ```ruby
130
175
  {
data/Rakefile CHANGED
@@ -21,6 +21,12 @@ task default: %i[spec rubocop]
21
21
 
22
22
  task "test:all" => :default do
23
23
  Dir.glob("gemfiles/Gemfile.rails-*.x") do |gemfile|
24
+ if RUBY_VERSION >= "2.6.0" && gemfile == "gemfiles/Gemfile.rails-4.2.x"
25
+ msg = "ignore #{gemfile} on Ruby #{RUBY_VERSION}"
26
+ puts RSpec::Core::Formatters::ConsoleCodes.wrap(msg, :yellow)
27
+ next
28
+ end
29
+
24
30
  puts RSpec::Core::Formatters::ConsoleCodes.wrap(gemfile, :cyan)
25
31
  sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "install", "--quiet", "--retry=2", "--jobs=2")
26
32
  sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "exec", "rspec")
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rdoc"
30
30
  spec.add_development_dependency "rspec"
31
31
  spec.add_development_dependency "rspec-rails", ">= 3.0.0"
32
- spec.add_development_dependency "rubocop", "~> 0.60.0"
32
+ spec.add_development_dependency "rubocop", "~> 0.61.1"
33
33
  spec.add_development_dependency "sqlite3"
34
34
  spec.add_development_dependency "tzinfo"
35
35
  end
@@ -11,6 +11,7 @@ require "influxdb/rails/logger"
11
11
  require "influxdb/rails/exception_presenter"
12
12
  require "influxdb/rails/configuration"
13
13
  require "influxdb/rails/backtrace"
14
+ require "influxdb/rails/context"
14
15
  require "influxdb/rails/rack"
15
16
 
16
17
  require "influxdb/rails/railtie" if defined?(Rails::Railtie)
@@ -60,6 +61,10 @@ module InfluxDB
60
61
  @configuration ||= InfluxDB::Rails::Configuration.new
61
62
  end
62
63
 
64
+ def current
65
+ @current ||= InfluxDB::Rails::Context.new
66
+ end
67
+
63
68
  def report_exception_unless_ignorable(ex, env = {})
64
69
  report_exception(ex, env) unless ignorable_exception?(ex)
65
70
  end
@@ -0,0 +1,42 @@
1
+ module InfluxDB
2
+ module Rails
3
+ class Context # rubocop:disable Style/Documentation
4
+ def controller
5
+ Thread.current[:_influxdb_rails_controller]
6
+ end
7
+
8
+ def controller=(value)
9
+ Thread.current[:_influxdb_rails_controller] = value
10
+ end
11
+
12
+ def action
13
+ Thread.current[:_influxdb_rails_action]
14
+ end
15
+
16
+ def action=(value)
17
+ Thread.current[:_influxdb_rails_action] = value
18
+ end
19
+
20
+ def location
21
+ [
22
+ controller,
23
+ action,
24
+ ].reject(&:blank?).join("#")
25
+ end
26
+
27
+ def reset
28
+ Thread.current[:_influxdb_rails_controller] = nil
29
+ Thread.current[:_influxdb_rails_action] = nil
30
+ Thread.current[:_influxdb_rails_tags] = nil
31
+ end
32
+
33
+ def tags
34
+ Thread.current[:_influxdb_rails_tags] || {}
35
+ end
36
+
37
+ def tags=(tags)
38
+ Thread.current[:_influxdb_rails_tags] = tags
39
+ end
40
+ end
41
+ end
42
+ end
@@ -6,13 +6,19 @@ module InfluxDB
6
6
  class RenderSubscriber < SimpleSubscriber # :nodoc:
7
7
  private
8
8
 
9
- def tags(payload)
10
- {
11
- location: location,
12
- filename: payload[:identifier],
9
+ def values(started, finished, payload)
10
+ super(started, finished, payload).merge(
13
11
  count: payload[:count],
14
- cache_hits: payload[:cache_hits],
15
- }.reject { |_, value| value.blank? }
12
+ cache_hits: payload[:cache_hits]
13
+ ).reject { |_, value| value.nil? }
14
+ end
15
+
16
+ def tags(payload)
17
+ tags = {
18
+ location: location,
19
+ filename: payload[:identifier],
20
+ }
21
+ super(tags)
16
22
  end
17
23
  end
18
24
  end
@@ -20,8 +20,7 @@ module InfluxDB
20
20
  rescue StandardError => e
21
21
  log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
22
22
  ensure
23
- Thread.current[:_influxdb_rails_controller] = nil
24
- Thread.current[:_influxdb_rails_action] = nil
23
+ InfluxDB::Rails.current.reset
25
24
  end
26
25
  end
27
26
 
@@ -36,14 +35,15 @@ module InfluxDB
36
35
  end
37
36
 
38
37
  def tags(payload)
39
- configuration.tags_middleware.call({
38
+ tags = {
40
39
  method: "#{payload[:controller]}##{payload[:action]}",
41
40
  status: payload[:status],
42
41
  format: payload[:format],
43
42
  http_method: payload[:method],
44
43
  server: Socket.gethostname,
45
44
  app_name: configuration.application_name,
46
- }.reject { |_, value| value.nil? })
45
+ }
46
+ super(tags)
47
47
  end
48
48
  end
49
49
  end
@@ -19,12 +19,13 @@ module InfluxDB
19
19
 
20
20
  def tags(payload)
21
21
  query = InfluxDB::Rails::Sql::Query.new(payload)
22
- {
22
+ tags = {
23
23
  location: location,
24
24
  operation: query.operation,
25
25
  class_name: query.class_name,
26
26
  name: query.name,
27
27
  }
28
+ super(tags)
28
29
  end
29
30
  end
30
31
  end
@@ -21,15 +21,21 @@ module InfluxDB
21
21
 
22
22
  private
23
23
 
24
+ def tags(tags)
25
+ merged_tags = tags.merge(InfluxDB::Rails.current.tags).reject { |_, value| value.nil? }
26
+ configuration.tags_middleware.call(merged_tags)
27
+ end
28
+
24
29
  def enabled?
25
30
  configuration.instrumentation_enabled? &&
26
31
  !configuration.ignore_current_environment?
27
32
  end
28
33
 
29
34
  def location
35
+ current = InfluxDB::Rails.current
30
36
  [
31
- Thread.current[:_influxdb_rails_controller],
32
- Thread.current[:_influxdb_rails_action],
37
+ current.controller,
38
+ current.action,
33
39
  ].reject(&:blank?).join("#")
34
40
  end
35
41
  end
@@ -23,8 +23,9 @@ module InfluxDB
23
23
 
24
24
  if defined?(ActiveSupport::Notifications)
25
25
  cache = lambda do |_, _, _, _, payload|
26
- Thread.current[:_influxdb_rails_controller] = payload[:controller]
27
- Thread.current[:_influxdb_rails_action] = payload[:action]
26
+ current = InfluxDB::Rails.current
27
+ current.controller = payload[:controller]
28
+ current.action = payload[:action]
28
29
  end
29
30
  ActiveSupport::Notifications.subscribe "start_processing.action_controller", &cache
30
31
 
@@ -7,14 +7,15 @@ module InfluxDB
7
7
  attr_reader :query, :name
8
8
 
9
9
  TRACKED_SQL_COMMANDS = %w[SELECT INSERT UPDATE DELETE].freeze
10
+ UNTRACKED_NAMES = %w[SCHEMA].freeze
10
11
 
11
12
  def initialize(payload)
12
- @query = payload[:sql].to_s.dup
13
+ @query = payload[:sql].to_s.dup.upcase
13
14
  @name = payload[:name].to_s.dup
14
15
  end
15
16
 
16
17
  def operation
17
- query.split.first.upcase
18
+ query.split.first
18
19
  end
19
20
 
20
21
  def class_name
@@ -22,7 +23,8 @@ module InfluxDB
22
23
  end
23
24
 
24
25
  def track?
25
- @track ||= query.start_with?(*TRACKED_SQL_COMMANDS)
26
+ @track ||= query.start_with?(*TRACKED_SQL_COMMANDS) &&
27
+ !name.upcase.start_with?(*UNTRACKED_NAMES)
26
28
  end
27
29
  end
28
30
  end
@@ -1,5 +1,5 @@
1
1
  module InfluxDB
2
2
  module Rails
3
- VERSION = "1.0.0.beta2".freeze
3
+ VERSION = "1.0.0.beta3".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.shared_examples_for "with additional tags" do |series_names|
4
+ context "when tags_middleware is overwritten" do
5
+ before do
6
+ allow(config).to receive(:tags_middleware).and_return(tags_middleware)
7
+ end
8
+
9
+ let(:tags_middleware) { ->(tags) { tags.merge(static: "value") } }
10
+
11
+ it "processes tags throught the middleware" do
12
+ tags = data[:tags].merge(static: "value")
13
+
14
+ series_names.each do |series_name|
15
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(series_name, include(tags: tags))
16
+ end
17
+
18
+ subject.call("unused", start, finish, "unused", payload)
19
+ end
20
+ end
21
+
22
+ context "when tags are set in the current context" do
23
+ let(:additional_tags) do
24
+ { another: :value }
25
+ end
26
+
27
+ after do
28
+ InfluxDB::Rails.current.reset
29
+ end
30
+
31
+ it "does include the tags" do
32
+ InfluxDB::Rails.current.tags = additional_tags
33
+ tags = data[:tags].merge(additional_tags)
34
+
35
+ series_names.each do |series_name|
36
+ expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(series_name, include(tags: tags))
37
+ end
38
+
39
+ subject.call("unused", start, finish, "unused", payload)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe InfluxDB::Rails::Context do
4
+ subject { described_class.new }
5
+
6
+ describe "#controller" do
7
+ it "does set and get" do
8
+ subject.controller = "Controller"
9
+ expect(subject.controller).to eq("Controller")
10
+ end
11
+ end
12
+
13
+ describe "#action" do
14
+ it "does get and set" do
15
+ subject.action = "action"
16
+ expect(subject.action).to eq("action")
17
+ end
18
+ end
19
+
20
+ describe "#location" do
21
+ before do
22
+ subject.controller = "Controller"
23
+ subject.action = "action"
24
+ end
25
+
26
+ it { expect(subject.location).to eq("Controller#action") }
27
+ end
28
+
29
+ describe "#reset" do
30
+ before do
31
+ subject.controller = "Controller"
32
+ subject.action = "action"
33
+ end
34
+
35
+ it "does reset the location" do
36
+ subject.reset
37
+ expect(subject.location).to be_empty
38
+ end
39
+ end
40
+ end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "shared_examples/tags"
2
3
 
3
4
  RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
4
5
  let(:config) { InfluxDB::Rails::Configuration.new }
@@ -11,21 +12,21 @@ RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
11
12
  end
12
13
 
13
14
  describe ".call" do
14
- let(:start_time) { Time.at(1_517_567_368) }
15
- let(:finish_time) { Time.at(1_517_567_370) }
15
+ let(:start) { Time.at(1_517_567_368) }
16
+ let(:finish) { Time.at(1_517_567_370) }
16
17
  let(:series_name) { "series_name" }
17
18
  let(:payload) { { identifier: "index.html", count: 43, cache_hits: 42 } }
18
- let(:result) do
19
+ let(:data) do
19
20
  {
20
21
  values: {
21
- value: 2000
22
- },
23
- tags: {
24
- filename: "index.html",
25
- location: "Foo#bar",
22
+ value: 2000,
26
23
  count: 43,
27
24
  cache_hits: 42
28
25
  },
26
+ tags: {
27
+ filename: "index.html",
28
+ location: "Foo#bar",
29
+ },
29
30
  timestamp: 1_517_567_370_000
30
31
  }
31
32
  end
@@ -33,34 +34,35 @@ RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
33
34
  subject { described_class.new(config, series_name) }
34
35
 
35
36
  before do
36
- Thread.current[:_influxdb_rails_controller] = "Foo"
37
- Thread.current[:_influxdb_rails_action] = "bar"
37
+ InfluxDB::Rails.current.controller = "Foo"
38
+ InfluxDB::Rails.current.action = "bar"
38
39
  end
39
40
 
40
41
  after do
41
- Thread.current[:_influxdb_rails_action] = nil
42
- Thread.current[:_influxdb_rails_controller] = nil
42
+ InfluxDB::Rails.current.reset
43
43
  end
44
44
 
45
45
  context "successfully" do
46
46
  it "writes to InfluxDB" do
47
47
  expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
48
- series_name, result
48
+ series_name, data
49
49
  )
50
- subject.call("name", start_time, finish_time, "id", payload)
50
+ subject.call("name", start, finish, "id", payload)
51
51
  end
52
52
 
53
- context "with empty tags" do
53
+ it_behaves_like "with additional tags", ["series_name"]
54
+
55
+ context "with an empty value" do
54
56
  before do
55
57
  payload[:count] = nil
56
- result[:tags].delete(:count)
58
+ data[:values].delete(:count)
57
59
  end
58
60
 
59
- it "does not write empty tags" do
61
+ it "does not write empty value" do
60
62
  expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
61
- series_name, result
63
+ series_name, data
62
64
  )
63
- subject.call("name", start_time, finish_time, "id", payload)
65
+ subject.call("name", start, finish, "id", payload)
64
66
  end
65
67
  end
66
68
 
@@ -69,7 +71,7 @@ RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
69
71
 
70
72
  it "does not write a data point" do
71
73
  expect_any_instance_of(InfluxDB::Client).not_to receive(:write_point)
72
- subject.call("name", start_time, finish_time, "id", payload)
74
+ subject.call("name", start, finish, "id", payload)
73
75
  end
74
76
  end
75
77
  end
@@ -83,7 +85,7 @@ RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
83
85
  it "does log exceptions" do
84
86
  allow_any_instance_of(InfluxDB::Client).to receive(:write_point).and_raise("boom")
85
87
  expect(logger).to receive(:error).with(/boom/)
86
- subject.call("name", start_time, finish_time, "id", payload)
88
+ subject.call("name", start, finish, "id", payload)
87
89
  end
88
90
  end
89
91
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "shared_examples/tags"
2
3
 
3
4
  RSpec.describe InfluxDB::Rails::Middleware::RequestSubscriber do
4
5
  let(:config) { InfluxDB::Rails::Configuration.new }
@@ -45,23 +46,7 @@ RSpec.describe InfluxDB::Rails::Middleware::RequestSubscriber do
45
46
  subject.call("unused", start, finish, "unused", payload)
46
47
  end
47
48
 
48
- context "when tags_middleware is overwritten" do
49
- before do
50
- allow(config).to receive(:tags_middleware).and_return(tags_middleware)
51
- end
52
-
53
- let(:tags_middleware) { ->(tags) { tags.merge(static: "value") } }
54
-
55
- it "processes tags throught the middleware" do
56
- tags = data[:tags].merge(static: "value")
57
-
58
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.controller", include(tags: tags))
59
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.view", include(tags: tags))
60
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.db", include(tags: tags))
61
-
62
- subject.call("unused", start, finish, "unused", payload)
63
- end
64
- end
49
+ it_behaves_like "with additional tags", ["rails.controller", "rails.view", "rails.db"]
65
50
  end
66
51
 
67
52
  context "application_name is nil" do
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "shared_examples/tags"
2
3
 
3
4
  RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
4
5
  let(:config) { InfluxDB::Rails::Configuration.new }
@@ -11,11 +12,11 @@ RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
11
12
  end
12
13
 
13
14
  describe ".call" do
14
- let(:start_time) { Time.at(1_517_567_368) }
15
- let(:finish_time) { Time.at(1_517_567_370) }
16
- let(:series_name) { "series_name" }
15
+ let(:start) { Time.at(1_517_567_368) }
16
+ let(:finish) { Time.at(1_517_567_370) }
17
+ let(:series_name) { "rails.sql" }
17
18
  let(:payload) { { sql: "SELECT * FROM POSTS WHERE id = 1", name: "Post Load", binds: %w[1 2 3] } }
18
- let(:result) do
19
+ let(:data) do
19
20
  {
20
21
  values: {
21
22
  value: 2000,
@@ -34,21 +35,20 @@ RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
34
35
  subject { described_class.new(config, series_name) }
35
36
 
36
37
  before do
37
- Thread.current[:_influxdb_rails_controller] = "Foo"
38
- Thread.current[:_influxdb_rails_action] = "bar"
38
+ InfluxDB::Rails.current.controller = "Foo"
39
+ InfluxDB::Rails.current.action = "bar"
39
40
  end
40
41
 
41
42
  after do
42
- Thread.current[:_influxdb_rails_action] = nil
43
- Thread.current[:_influxdb_rails_controller] = nil
43
+ InfluxDB::Rails.current.reset
44
44
  end
45
45
 
46
46
  context "successfully" do
47
47
  it "writes to InfluxDB" do
48
48
  expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
49
- series_name, result
49
+ series_name, data
50
50
  )
51
- subject.call("name", start_time, finish_time, "id", payload)
51
+ subject.call("name", start, finish, "id", payload)
52
52
  end
53
53
 
54
54
  context "with not relevant queries" do
@@ -58,9 +58,11 @@ RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
58
58
 
59
59
  it "does not write to InfluxDB" do
60
60
  expect_any_instance_of(InfluxDB::Client).not_to receive(:write_point)
61
- subject.call("name", start_time, finish_time, "id", payload)
61
+ subject.call("name", start, finish, "id", payload)
62
62
  end
63
63
  end
64
+
65
+ it_behaves_like "with additional tags", ["rails.sql"]
64
66
  end
65
67
 
66
68
  context "unsuccessfully" do
@@ -72,7 +74,7 @@ RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
72
74
  it "does log exceptions" do
73
75
  allow_any_instance_of(InfluxDB::Client).to receive(:write_point).and_raise("boom")
74
76
  expect(logger).to receive(:error).with(/boom/)
75
- subject.call("name", start_time, finish_time, "id", payload)
77
+ subject.call("name", start, finish, "id", payload)
76
78
  end
77
79
  end
78
80
  end
@@ -24,5 +24,6 @@ RSpec.describe InfluxDB::Rails::Sql::Query do
24
24
  it { expect(described_class.new(sql: "DELETE").track?).to be true }
25
25
  it { expect(described_class.new(sql: "SCHEMA").track?).to be false }
26
26
  it { expect(described_class.new(sql: "BEGIN").track?).to be false }
27
+ it { expect(described_class.new(sql: "SELECT", name: "SCHEMA").track?).to be false }
27
28
  end
28
29
  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.beta2
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Menke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-12-07 00:00:00.000000000 Z
12
+ date: 2019-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: influxdb
@@ -149,14 +149,14 @@ dependencies:
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.60.0
152
+ version: 0.61.1
153
153
  type: :development
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.60.0
159
+ version: 0.61.1
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: sqlite3
162
162
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +213,7 @@ files:
213
213
  - lib/influxdb/rails/air_traffic_controller.rb
214
214
  - lib/influxdb/rails/backtrace.rb
215
215
  - lib/influxdb/rails/configuration.rb
216
+ - lib/influxdb/rails/context.rb
216
217
  - lib/influxdb/rails/exception_presenter.rb
217
218
  - lib/influxdb/rails/instrumentation.rb
218
219
  - lib/influxdb/rails/logger.rb
@@ -234,6 +235,7 @@ files:
234
235
  - spec/integration/exceptions_spec.rb
235
236
  - spec/integration/integration_helper.rb
236
237
  - spec/integration/metrics_spec.rb
238
+ - spec/shared_examples/tags.rb
237
239
  - spec/spec_helper.rb
238
240
  - spec/support/rails4/app.rb
239
241
  - spec/support/rails5/app.rb
@@ -241,6 +243,7 @@ files:
241
243
  - spec/support/views/widgets/index.html.erb
242
244
  - spec/unit/backtrace_spec.rb
243
245
  - spec/unit/configuration_spec.rb
246
+ - spec/unit/context_spec.rb
244
247
  - spec/unit/exception_presenter_spec.rb
245
248
  - spec/unit/influxdb_rails_spec.rb
246
249
  - spec/unit/middleware/render_subscriber_spec.rb
@@ -267,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
270
  - !ruby/object:Gem::Version
268
271
  version: 1.3.1
269
272
  requirements: []
270
- rubyforge_project:
271
- rubygems_version: 2.7.6
273
+ rubygems_version: 3.0.1
272
274
  signing_key:
273
275
  specification_version: 4
274
276
  summary: InfluxDB bindings for Ruby on Rails.
@@ -277,6 +279,7 @@ test_files:
277
279
  - spec/integration/exceptions_spec.rb
278
280
  - spec/integration/integration_helper.rb
279
281
  - spec/integration/metrics_spec.rb
282
+ - spec/shared_examples/tags.rb
280
283
  - spec/spec_helper.rb
281
284
  - spec/support/rails4/app.rb
282
285
  - spec/support/rails5/app.rb
@@ -284,6 +287,7 @@ test_files:
284
287
  - spec/support/views/widgets/index.html.erb
285
288
  - spec/unit/backtrace_spec.rb
286
289
  - spec/unit/configuration_spec.rb
290
+ - spec/unit/context_spec.rb
287
291
  - spec/unit/exception_presenter_spec.rb
288
292
  - spec/unit/influxdb_rails_spec.rb
289
293
  - spec/unit/middleware/render_subscriber_spec.rb