influxdb-rails 0.4.999 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2ff414e8cae6402df105a81f2c74f85c4a54bbf891b8be50c1038c04e834700
4
- data.tar.gz: b0487d28207ca60c4b25ef5db6c725c0aeca4d6cbf0c06d74f19ea5507b9da1e
3
+ metadata.gz: 68333c3962daf87c05e1ff1b221accc5854e4c7d671f0d0441a5c789b2322cee
4
+ data.tar.gz: 56017328de99c335fd4c590fe80c2d9de1b9132f39a7d3ac6d07b87b551597f9
5
5
  SHA512:
6
- metadata.gz: 312c37ab1718fb18b54b322de99a298ed3adab60d6649052e73a0f48b9b3a8aabd9cef9edc9ab8d4ebd2741fddce111987db1cf831578b8dc86f82f1f8d431d2
7
- data.tar.gz: 4ce0755f4b739c487f46e95d9140066fd693e9dd277f7a42b5b3d750d6749ffc4eafd502b23016fd4b27f9921f66937eb869416ccb531804c6f217e1c3622c09
6
+ metadata.gz: e6c6087522e487aaefabe377698d2275270070c0e9d70eb7110fd90000f2160fc03b127879e39481ca0ff7f1f6bc5010075c4d9fe64bd30ecebd9b04b7e98df6
7
+ data.tar.gz: baf2150e6140c85119da580cb89b06204a0372277c6adf7c57f15b89c214e41d80f05e0b47447df939eecc26dfb27115787750d92a22ae3ced38a047448f97bc
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ gemfiles/*.lock
6
6
  pkg/*
7
7
  spec/support/rails*/log/*
8
8
  .ruby-*
9
+ vendor/bundle
data/.rubocop.yml ADDED
@@ -0,0 +1,77 @@
1
+ AllCops:
2
+ Include:
3
+ - 'Rakefile'
4
+ - '*.gemspec'
5
+ - 'lib/**/*.rb'
6
+ - 'spec/**/*.rb'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'smoke/**/*'
10
+ - 'Gemfile'
11
+ DisplayCopNames: true
12
+ StyleGuideCopsOnly: false
13
+ TargetRubyVersion: 2.3
14
+
15
+ Rails:
16
+ Enabled: false
17
+
18
+ Layout/EmptyLinesAroundArguments:
19
+ Enabled: false
20
+
21
+ Layout/SpaceBeforeBlockBraces:
22
+ EnforcedStyleForEmptyBraces: space
23
+
24
+ Layout/AlignHash:
25
+ EnforcedColonStyle: table
26
+ EnforcedHashRocketStyle: table
27
+
28
+ Metrics/AbcSize:
29
+ Max: 20
30
+
31
+ Metrics/BlockLength:
32
+ Exclude:
33
+ - 'spec/**/*.rb'
34
+
35
+ Metrics/LineLength:
36
+ Max: 100
37
+ Exclude:
38
+ - 'spec/**/*.rb'
39
+
40
+ Metrics/ModuleLength:
41
+ CountComments: false # count full line comments?
42
+ Max: 120
43
+
44
+ Metrics/ParameterLists:
45
+ Max: 6
46
+
47
+ Naming/UncommunicativeMethodParamName:
48
+ AllowedNames: [io, id, db, ex]
49
+
50
+ Naming/FileName:
51
+ Exclude:
52
+ - lib/influxdb-rails.rb
53
+
54
+ Style/FormatStringToken:
55
+ Enabled: false
56
+
57
+ Style/FrozenStringLiteralComment:
58
+ Enabled: false
59
+
60
+ Style/NumericPredicate:
61
+ Enabled: false
62
+
63
+ Style/RescueModifier:
64
+ Enabled: false
65
+
66
+ Style/StringLiterals:
67
+ EnforcedStyle: double_quotes
68
+
69
+ Style/TrailingCommaInArrayLiteral:
70
+ EnforcedStyleForMultiline: comma
71
+ Exclude:
72
+ - "spec/**/*.rb"
73
+
74
+ Style/TrailingCommaInHashLiteral:
75
+ EnforcedStyleForMultiline: comma
76
+ Exclude:
77
+ - "spec/**/*.rb"
data/.travis.yml CHANGED
@@ -4,25 +4,32 @@ language: ruby
4
4
  before_install:
5
5
  - gem update --system --no-doc
6
6
  - gem install bundler --no-doc
7
+ - gem update bundler --no-doc
7
8
  rvm:
8
- - 2.4.2
9
- - 2.3.5
9
+ - ruby-head
10
+ - 2.5.3
11
+ - 2.4.5
12
+ - 2.3.8
10
13
  gemfile:
14
+ - gemfiles/Gemfile.rails-5.2.x
11
15
  - gemfiles/Gemfile.rails-5.1.x
12
16
  - gemfiles/Gemfile.rails-5.0.x
13
17
  - gemfiles/Gemfile.rails-4.2.x
14
- - gemfiles/Gemfile.rails-4.1.x
15
- - gemfiles/Gemfile.rails-4.0.x
18
+ env:
19
+ - TEST_TASK=spec
16
20
  matrix:
21
+ allow_failures:
22
+ - rvm: ruby-head
23
+ include:
24
+ - { rvm: "2.5.3", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
17
25
  exclude:
18
- # Rails < 5 not on MRI 2.4
19
- - { rvm: "2.4.2", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
20
- - { rvm: "2.4.2", gemfile: "gemfiles/Gemfile.rails-4.1.x" }
21
- - { rvm: "2.4.2", gemfile: "gemfiles/Gemfile.rails-4.0.x" }
22
-
23
- notifications:
24
- email:
25
- - pilots@errplane.com
26
- on_success: change
27
- on_failure: always
26
+ # Rails < 5 not on MRI 2.4+
27
+ - { 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" }
30
+ addons:
31
+ apt:
32
+ packages:
33
+ - haveged
34
+ - libgmp-dev
28
35
  script: bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -3,14 +3,33 @@
3
3
  For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/master).
4
4
 
5
5
 
6
- ## Unreleased changes
7
-
8
- - None.
9
-
10
- ## v0.4.99, released 2017-12-12
11
-
12
- - No code changes, just inform people about 1.0 in the
13
- gem post install message
6
+ ## v1.0.0.beta1, released 2018-11-22
7
+
8
+ - Added app name to the measurement's tag sets (#44, @stefanhorning)
9
+ - Added config parameters for additional series:
10
+ - `InfluxDB::Rails::Configuration#series_name_for_instrumentation`
11
+ - `InfluxDB::Rails::Configuration#series_name_for_exceptions`
12
+ - Added method, status and format tags to metrics (#50, @ChrisBr)
13
+
14
+ ### Breaking changes
15
+
16
+ - Support for Ruby <= 2.2.x has been removed
17
+ - Support for Rails <= 4.1.x has been removed
18
+ - Changed keys for exceptions (#43, @vassilevsky & @kkentzo)
19
+ - Exception message and backtrace are now InfluxDB values (changed from tags).
20
+ - The keys changed from `message` to `exception_message` and from
21
+ `backtrace` to `exception_backtrace`, since a single shard does not
22
+ allow for tags and values to share the same key
23
+ - To convert existing exception traces into the new format for
24
+ consistency, see [this gist][migrate].
25
+ - Removed `time` key from InfluxDB::Rails::ExceptionPresenter#context`
26
+ - use `InfluxDB::Rails.current_timestamp` directly
27
+ - Removed previously deprecated methods:
28
+ - `InfluxDB::Rails::Configuration#reraise_global_exceptions`
29
+ - `InfluxDB::Rails::Configuration#database_name`
30
+ - `InfluxDB::Rails::Configuration#application_id`
31
+
32
+ [migrate]: https://gist.github.com/dmke/2d0f4ccf9f43faf82e732dc041e90ca2
14
33
 
15
34
  ## v0.4.3, released 2017-12-12
16
35
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- > You are looking at the `README` for the 0.4.x releases of this gem
2
- > (`stable-04` branch). The current development version lives in the
3
- > `master` branch, [see here](https://github.com/influxdata/influxdb-rails#readme)
1
+ > You are looking at the README for the master branch of this gem.
2
+ > The latest released version lives in the stable-04 branch,
3
+ > [see here](https://github.com/influxdata/influxdb-rails/tree/stable-04#readme)
4
4
  > for an online version.
5
5
 
6
6
  # influxdb-rails
@@ -9,7 +9,7 @@
9
9
  [![Build Status](https://travis-ci.org/influxdata/influxdb-rails.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-rails)
10
10
 
11
11
  Automatically instrument your Ruby on Rails applications and write the
12
- metrics directly into [InfluxDB](https://www.influxdata.com/time-series-platform/influxdb/).
12
+ metrics directly into [InfluxDB](http://influxdb.org/).
13
13
 
14
14
  This gem is designed for Rails 4.0+, Ruby 2.2+ and InfluxDB 0.9+.
15
15
 
@@ -27,7 +27,7 @@ To get things set up, just create an initializer:
27
27
 
28
28
  ```
29
29
  $ cd /to/you/rails/application
30
- $ touch config/initializers/influxdb-rails.rb
30
+ $ touch config/initializers/influxdb_rails.rb
31
31
  ```
32
32
 
33
33
  In this file, you can configure the `InfluxDB::Rails` adapter. The default
@@ -51,9 +51,18 @@ InfluxDB::Rails.configure do |config|
51
51
  # config.series_name_for_controller_runtimes = "rails.controller"
52
52
  # config.series_name_for_view_runtimes = "rails.view"
53
53
  # config.series_name_for_db_runtimes = "rails.db"
54
+ # config.series_name_for_exceptions = "rails.exceptions"
55
+ # config.series_name_for_instrumentation = "instrumentation"
56
+
57
+ # Set the application name to something meaningful, by default we
58
+ # infer the app name from the Rails.application class name.
59
+ # config.application_name = Rails.application.class.parent_name
54
60
  end
55
61
  ```
56
62
 
63
+ To see all default values, take a look into `InfluxDB::Rails::Configuration::DEFAULTS`,
64
+ defined in `lib/influxdb/rails/configuration.rb`
65
+
57
66
  Out of the box, you'll automatically get reporting of your controller,
58
67
  view, and db runtimes for each request. You can also call through to the
59
68
  underlying `InfluxDB::Client` object to write arbitrary data like this:
@@ -81,10 +90,6 @@ To work around this limitation, set the `config.time_precision` to one
81
90
  of `"ms"` (milliseconds, 1·10<sup>-3</sup>s), `"us"` (microseconds,
82
91
  1·10<sup>-6</sup>s) or `"ns"` (nanoseconds, 1·10<sup>-9</sup>s).
83
92
 
84
- **Please note:** The default value for the time precision is going to
85
- change with version 1.0 of this gem, although the final value is not
86
- determined yet.
87
-
88
93
  [duplicate-points]: https://docs.influxdata.com/influxdb/v1.4/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
89
94
 
90
95
 
data/Rakefile CHANGED
@@ -1,14 +1,13 @@
1
- # encoding: utf-8
2
-
3
- require 'bundler'
4
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+ require "rubocop/rake_task"
3
+ RuboCop::RakeTask.new
5
4
 
6
5
  begin
7
6
  targeted_files = ARGV.drop(1)
8
- file_pattern = targeted_files.empty? ? 'spec/**/*_spec.rb' : targeted_files
7
+ file_pattern = targeted_files.empty? ? "spec/**/*_spec.rb" : targeted_files
9
8
 
10
- require 'rspec/core'
11
- require 'rspec/core/rake_task'
9
+ require "rspec/core"
10
+ require "rspec/core/rake_task"
12
11
 
13
12
  RSpec::Core::RakeTask.new(:spec) do |t|
14
13
  t.pattern = FileList[file_pattern]
@@ -19,7 +18,7 @@ begin
19
18
  config.formatter = :documentation
20
19
  end
21
20
  rescue LoadError
22
- require 'spec/rake/spectask'
21
+ require "spec/rake/spectask"
23
22
 
24
23
  puts file_pattern
25
24
 
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'actionpack', '~> 5.2.0'
4
+ gem 'activesupport', '~> 5.2.0'
5
+ gem 'activemodel', '~> 5.2.0'
6
+
7
+ gemspec :path => '../'
@@ -1,44 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "influxdb/rails/version"
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = "influxdb-rails"
7
- s.summary = %q{InfluxDB bindings for Ruby on Rails.}
8
- s.description = %q{This gem automatically instruments your Ruby on Rails application using InfluxDB.}
9
- s.version = InfluxDB::Rails::VERSION
10
- s.authors = ['Christian Bruckmayer', 'Henne Vogelsang']
11
- s.email = ['christian@bruckmayer.net', 'hvogel@hennevogel.de']
12
- s.licenses = ['MIT']
13
- s.homepage = "http://influxdb.com"
14
- s.metadata = {
15
- "bug_tracker_uri" => "https://github.com/influxdata/influxdb-rails/issues",
16
- "changelog_uri" => "https://github.com/influxdata/influxdb-rails/blob/master/CHANGELOG.md",
17
- "documentation_uri" => "https://github.com/influxdata/influxdb-rails/blob/master/README.md",
18
- "source_code_uri" => "https://github.com/influxdata/influxdb-rails"
19
- }
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "influxdb-rails"
7
+ spec.version = InfluxDB::Rails::VERSION
8
+ spec.authors = ["Dominik Menke", "Todd Persen"]
9
+ spec.email = ["dominik.menke@gmail.com", "todd@influxdb.com"]
10
+ spec.homepage = "https://influxdata.com"
11
+ spec.summary = "InfluxDB bindings for Ruby on Rails."
12
+ spec.description = "This gem automatically instruments your Ruby on Rails" \
13
+ " 4.2/5.x applications using InfluxDB for storage."
14
+ spec.licenses = ["MIT"]
20
15
 
21
- s.files = `git ls-files`.split($/)
22
- s.test_files = Dir.glob('test/**/*') + Dir.glob('spec/**/*') + Dir.glob('features/**/*')
23
- s.executables = Dir.glob('bin/**/*').map {|f| File.basename(f)}
24
- s.require_paths = ["lib"]
16
+ spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/})
18
+ spec.require_paths = ["lib"]
25
19
 
26
- s.add_runtime_dependency 'influxdb', '~> 0.5.0'
27
- s.add_runtime_dependency 'railties', '> 3'
20
+ spec.required_ruby_version = ">= 2.3.0"
28
21
 
29
- s.add_development_dependency 'bundler', ['>= 1.0.0']
30
- s.add_development_dependency 'fakeweb', ['>= 0']
31
- s.add_development_dependency 'rake', ['>= 0']
32
- s.add_development_dependency 'rdoc', ['>= 0']
33
- s.add_development_dependency 'rspec', ['>= 0']
34
- s.add_development_dependency 'rspec-rails', ['>= 3.0.0']
35
- s.add_development_dependency 'tzinfo', ['>= 0']
22
+ spec.add_runtime_dependency "influxdb", "~> 0.5.0"
23
+ spec.add_runtime_dependency "railties", "> 3"
36
24
 
37
- s.post_install_message = %q{
38
- This is the last supported version of influxdb-rails in the 0.4 series. The
39
- next release will be 1.0 with quite a lot of breaking changes. For details:
40
-
41
- https://github.com/influxdata/influxdb-rails/wiki/1.0-Upgrade-Guide
42
-
43
- }
25
+ spec.add_development_dependency "bundler", ">= 1.0.0"
26
+ spec.add_development_dependency "fakeweb"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rdoc"
29
+ spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "rspec-rails", ">= 3.0.0"
31
+ spec.add_development_dependency "rubocop", "~> 0.60.0"
32
+ spec.add_development_dependency "tzinfo"
44
33
  end
@@ -2,8 +2,6 @@ require "net/http"
2
2
  require "net/https"
3
3
  require "rubygems"
4
4
  require "socket"
5
- require "thread"
6
-
7
5
  require "influxdb/rails/version"
8
6
  require "influxdb/rails/logger"
9
7
  require "influxdb/rails/exception_presenter"
@@ -14,6 +12,8 @@ require "influxdb/rails/rack"
14
12
  require "influxdb/rails/railtie" if defined?(Rails::Railtie)
15
13
 
16
14
  module InfluxDB
15
+ # InfluxDB::Rails contains the glue code needed to integrate with
16
+ # InfluxDB and Rails. This is a singleton class.
17
17
  module Rails
18
18
  class << self
19
19
  include InfluxDB::Rails::Logger
@@ -21,7 +21,7 @@ module InfluxDB
21
21
  attr_writer :configuration
22
22
  attr_writer :client
23
23
 
24
- def configure(silent = false)
24
+ def configure(_silent = false)
25
25
  yield(configuration)
26
26
 
27
27
  # if we change configuration, reload the client
@@ -30,151 +30,126 @@ module InfluxDB
30
30
  InfluxDB::Logging.logger = configuration.logger unless configuration.logger.nil?
31
31
  end
32
32
 
33
+ # rubocop:disable Metrics/MethodLength
34
+ # rubocop:disable Metrics/AbcSize
35
+
33
36
  def client
34
- @client ||= InfluxDB::Client.new configuration.influxdb_database,
35
- :username => configuration.influxdb_username,
36
- :password => configuration.influxdb_password,
37
- :hosts => configuration.influxdb_hosts,
38
- :port => configuration.influxdb_port,
39
- :async => configuration.async,
40
- :use_ssl => configuration.use_ssl,
41
- :retry => configuration.retry,
42
- :open_timeout => configuration.open_timeout,
43
- :read_timeout => configuration.read_timeout,
44
- :max_delay => configuration.max_delay,
45
- :time_precision => configuration.time_precision
37
+ @client ||= InfluxDB::Client.new \
38
+ database: configuration.influxdb_database,
39
+ username: configuration.influxdb_username,
40
+ password: configuration.influxdb_password,
41
+ hosts: configuration.influxdb_hosts,
42
+ port: configuration.influxdb_port,
43
+ async: configuration.async,
44
+ use_ssl: configuration.use_ssl,
45
+ retry: configuration.retry,
46
+ open_timeout: configuration.open_timeout,
47
+ read_timeout: configuration.read_timeout,
48
+ max_delay: configuration.max_delay,
49
+ time_precision: configuration.time_precision
46
50
  end
47
51
 
52
+ # rubocop:enable Metrics/MethodLength
53
+ # rubocop:enable Metrics/AbcSize
54
+
48
55
  def configuration
49
56
  @configuration ||= InfluxDB::Rails::Configuration.new
50
57
  end
51
58
 
52
- def report_exception_unless_ignorable(e, env = {})
53
- report_exception(e, env) unless ignorable_exception?(e)
59
+ def report_exception_unless_ignorable(ex, env = {})
60
+ report_exception(ex, env) unless ignorable_exception?(ex)
54
61
  end
55
- alias_method :transmit_unless_ignorable, :report_exception_unless_ignorable
56
-
57
- def report_exception(e, env = {})
58
- begin
59
- env = influxdb_request_data if env.empty? && defined? influxdb_request_data
60
- exception_presenter = ExceptionPresenter.new(e, env)
61
- log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
62
-
63
- ex_data = exception_presenter.context.merge(exception_presenter.dimensions)
64
- timestamp = ex_data.delete(:time)
65
-
66
- client.write_point "rails.exceptions", {
67
- values: {
68
- ts: timestamp,
69
- },
70
- tags: ex_data,
71
- timestamp: timestamp,
72
- }
73
- rescue => e
74
- log :info, "[InfluxDB::Rails] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}"
75
- end
62
+ alias transmit_unless_ignorable report_exception_unless_ignorable
63
+
64
+ # rubocop:disable Metrics/MethodLength
65
+ # rubocop:disable Metrics/AbcSize
66
+
67
+ def report_exception(ex, env = {})
68
+ timestamp = InfluxDB::Rails.current_timestamp
69
+ env = influxdb_request_data if env.empty? && defined? influxdb_request_data
70
+ exception_presenter = ExceptionPresenter.new(ex, env)
71
+ log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
72
+
73
+ client.write_point \
74
+ configuration.series_name_for_exceptions,
75
+ values: exception_presenter.values.merge(ts: timestamp),
76
+ tags: exception_presenter.context.merge(exception_presenter.dimensions),
77
+ timestamp: timestamp
78
+ rescue StandardError => ex
79
+ log :info, "[InfluxDB::Rails] Something went terribly wrong." \
80
+ " Exception failed to take off! #{ex.class}: #{ex.message}"
76
81
  end
77
- alias_method :transmit, :report_exception
82
+ alias transmit report_exception
78
83
 
79
- def handle_action_controller_metrics(name, start, finish, id, payload)
80
- timestamp = convert_timestamp(finish.utc)
81
- controller_runtime = ((finish - start)*1000).ceil
82
- view_runtime = (payload[:view_runtime] || 0).ceil
83
- db_runtime = (payload[:db_runtime] || 0).ceil
84
- method = "#{payload[:controller]}##{payload[:action]}"
85
- hostname = Socket.gethostname
84
+ def handle_action_controller_metrics(_name, start, finish, _id, payload)
85
+ tags = {
86
+ method: "#{payload[:controller]}##{payload[:action]}",
87
+ status: payload[:status],
88
+ format: payload[:format],
89
+ http_method: payload[:method],
90
+ path: payload[:path],
91
+ server: Socket.gethostname,
92
+ app_name: configuration.application_name,
93
+ }.reject { |_, value| value.nil? }
94
+
95
+ ts = convert_timestamp(finish.utc)
86
96
 
87
97
  begin
88
- client.write_point configuration.series_name_for_controller_runtimes, {
89
- values: {
90
- value: controller_runtime,
91
- },
92
- tags: {
93
- method: method,
94
- server: hostname,
95
- },
96
- timestamp: timestamp,
97
- }
98
-
99
- client.write_point configuration.series_name_for_view_runtimes, {
100
- values: {
101
- value: view_runtime,
102
- },
103
- tags: {
104
- method: method,
105
- server: hostname,
106
- },
107
- timestamp: timestamp,
108
- }
109
-
110
- client.write_point configuration.series_name_for_db_runtimes, {
111
- values: {
112
- value: db_runtime,
113
- },
114
- tags: {
115
- method: method,
116
- server: hostname,
117
- },
118
- timestamp: timestamp,
119
- }
120
- rescue => e
98
+ {
99
+ configuration.series_name_for_controller_runtimes => ((finish - start) * 1000).ceil,
100
+ configuration.series_name_for_view_runtimes => (payload[:view_runtime] || 0).ceil,
101
+ configuration.series_name_for_db_runtimes => (payload[:db_runtime] || 0).ceil,
102
+ }.each do |series_name, value|
103
+ client.write_point series_name, values: { value: value }, tags: tags, timestamp: ts
104
+ end
105
+ rescue StandardError => e
121
106
  log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
122
107
  end
123
108
  end
124
109
 
125
- def convert_timestamp(ts)
126
- case configuration.time_precision
127
- when 'ns', nil
128
- (ts.to_r * 1e9).to_i
129
- when 'u'
130
- (ts.to_r * 1e6).to_i
131
- when 'ms'
132
- (ts.to_r * 1e3).to_i
133
- when 's'
134
- ts.to_i
135
- when 'm'
136
- ts.to_i / 60
137
- when 'h'
138
- ts.to_i / 60 / 60
139
- else
110
+ # rubocop:enable Metrics/MethodLength
111
+ # rubocop:enable Metrics/AbcSize
112
+
113
+ TIMESTAMP_CONVERSIONS = {
114
+ "ns" => 1e9.to_r,
115
+ nil => 1e9.to_r,
116
+ "u" => 1e6.to_r,
117
+ "ms" => 1e3.to_r,
118
+ "s" => 1.to_r,
119
+ "m" => 1.to_r / 60,
120
+ "h" => 1.to_r / 60 / 60,
121
+ }.freeze
122
+ private_constant :TIMESTAMP_CONVERSIONS
123
+
124
+ def convert_timestamp(time)
125
+ conv = TIMESTAMP_CONVERSIONS.fetch(configuration.time_precision) do
140
126
  raise "Invalid time precision: #{configuration.time_precision}"
141
127
  end
128
+
129
+ (time.to_r * conv).to_i
142
130
  end
143
131
 
144
132
  def current_timestamp
145
133
  convert_timestamp(Time.now.utc)
146
134
  end
147
135
 
148
- def ignorable_exception?(e)
149
- configuration.ignore_current_environment? ||
150
- !!configuration.ignored_exception_messages.find{ |msg| /.*#{msg}.*/ =~ e.message } ||
151
- configuration.ignored_exceptions.include?(e.class.to_s)
136
+ def ignorable_exception?(ex)
137
+ configuration.ignore_current_environment? || configuration.ignore_exception?(ex)
152
138
  end
153
139
 
154
- def rescue(&block)
155
- block.call
156
- rescue StandardError => e
157
- if configuration.ignore_current_environment?
158
- raise(e)
159
- else
160
- transmit_unless_ignorable(e)
161
- end
162
- end
140
+ def rescue
141
+ yield
142
+ rescue StandardError => ex
143
+ raise ex if configuration.ignore_current_environment?
163
144
 
164
- def rescue_and_reraise(&block)
165
- block.call
166
- rescue StandardError => e
167
- transmit_unless_ignorable(e)
168
- raise(e)
145
+ transmit_unless_ignorable(ex)
169
146
  end
170
147
 
171
- def safely_prepend(module_name, opts = {})
172
- return if opts[:to].nil? || opts[:from].nil?
173
- if opts[:to].respond_to?(:prepend, true)
174
- opts[:to].send(:prepend, opts[:from].const_get(module_name))
175
- else
176
- opts[:to].send(:include, opts[:from].const_get("Old" + module_name))
177
- end
148
+ def rescue_and_reraise
149
+ yield
150
+ rescue StandardError => ex
151
+ transmit_unless_ignorable(ex)
152
+ raise ex
178
153
  end
179
154
  end
180
155
  end