influxdb-rails 1.0.0.beta3 → 1.0.1.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/rubocop.yml +18 -0
  4. data/.github/workflows/spec.yml +31 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +40 -7
  7. data/CHANGELOG.md +42 -12
  8. data/README.md +277 -164
  9. data/Rakefile +0 -6
  10. data/gemfiles/Gemfile.rails-6.0.x +9 -0
  11. data/gemfiles/Gemfile.rails-6.1.x +9 -0
  12. data/influxdb-rails.gemspec +18 -9
  13. data/lib/influxdb-rails.rb +31 -81
  14. data/lib/influxdb/rails/configuration.rb +99 -194
  15. data/lib/influxdb/rails/context.rb +12 -28
  16. data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
  17. data/lib/influxdb/rails/metric.rb +39 -0
  18. data/lib/influxdb/rails/middleware/action_mailer_subscriber.rb +22 -0
  19. data/lib/influxdb/rails/middleware/active_job_subscriber.rb +67 -0
  20. data/lib/influxdb/rails/middleware/active_record_subscriber.rb +26 -0
  21. data/lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb +24 -0
  22. data/lib/influxdb/rails/middleware/render_subscriber.rb +16 -10
  23. data/lib/influxdb/rails/middleware/request_subscriber.rb +23 -30
  24. data/lib/influxdb/rails/middleware/sql_subscriber.rb +19 -15
  25. data/lib/influxdb/rails/middleware/subscriber.rb +44 -20
  26. data/lib/influxdb/rails/railtie.rb +29 -35
  27. data/lib/influxdb/rails/sql/normalizer.rb +3 -3
  28. data/lib/influxdb/rails/tags.rb +33 -0
  29. data/lib/influxdb/rails/test_client.rb +13 -0
  30. data/lib/influxdb/rails/values.rb +24 -0
  31. data/lib/influxdb/rails/version.rb +1 -1
  32. data/lib/rails/generators/influxdb/influxdb_generator.rb +1 -1
  33. data/lib/rails/generators/influxdb/templates/initializer.rb +43 -9
  34. data/sample-dashboard/Dockerfile +24 -0
  35. data/sample-dashboard/README.md +74 -0
  36. data/sample-dashboard/Rakefile +9 -0
  37. data/sample-dashboard/Ruby On Rails Performance (per Action).json +1576 -0
  38. data/sample-dashboard/Ruby On Rails Performance (per Request).json +1053 -0
  39. data/sample-dashboard/Ruby On Rails Performance.json +2041 -0
  40. data/sample-dashboard/docker-compose.yml +34 -0
  41. data/sample-dashboard/provisioning/grafana-dashboards.yml +12 -0
  42. data/sample-dashboard/provisioning/grafana-datasource.yml +10 -0
  43. data/sample-dashboard/provisioning/performance-action.json +1576 -0
  44. data/sample-dashboard/provisioning/performance-request.json +1053 -0
  45. data/sample-dashboard/provisioning/performance.json +2041 -0
  46. data/spec/requests/action_controller_metrics_spec.rb +83 -0
  47. data/spec/requests/action_mailer_deliver_metrics_spec.rb +49 -0
  48. data/spec/requests/action_view_collection_metrics_spec.rb +66 -0
  49. data/spec/requests/action_view_partial_metrics_spec.rb +62 -0
  50. data/spec/requests/action_view_template_metrics_spec.rb +62 -0
  51. data/spec/requests/active_job_enqueue_metrics_spec.rb +65 -0
  52. data/spec/requests/active_job_perform_metrics_spec.rb +68 -0
  53. data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
  54. data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
  55. data/spec/requests/block_inistrumentation_spec.rb +64 -0
  56. data/spec/requests/context_spec.rb +27 -0
  57. data/spec/requests/logger_spec.rb +10 -0
  58. data/spec/spec_helper.rb +14 -4
  59. data/spec/support/broken_client.rb +11 -0
  60. data/spec/support/rails5/app.rb +51 -12
  61. data/spec/support/rails6/app.rb +83 -0
  62. data/spec/support/views/layouts/mailer.txt.erb +1 -0
  63. data/spec/support/views/{widgets → metrics}/_item.html.erb +0 -0
  64. data/spec/support/views/{widgets → metrics}/index.html.erb +0 -0
  65. data/spec/support/views/metrics/show.html.erb +4 -0
  66. data/spec/unit/block_instrumentation_spec.rb +18 -0
  67. data/spec/unit/configuration_spec.rb +47 -65
  68. metadata +141 -61
  69. data/.travis.yml +0 -37
  70. data/gemfiles/Gemfile.rails-4.2.x +0 -7
  71. data/gemfiles/Gemfile.rails-5.0.x +0 -7
  72. data/gemfiles/Gemfile.rails-5.1.x +0 -7
  73. data/lib/influxdb/rails/air_traffic_controller.rb +0 -41
  74. data/lib/influxdb/rails/backtrace.rb +0 -44
  75. data/lib/influxdb/rails/exception_presenter.rb +0 -94
  76. data/lib/influxdb/rails/instrumentation.rb +0 -34
  77. data/lib/influxdb/rails/logger.rb +0 -16
  78. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +0 -16
  79. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +0 -31
  80. data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -46
  81. data/lib/influxdb/rails/rack.rb +0 -24
  82. data/spec/controllers/widgets_controller_spec.rb +0 -15
  83. data/spec/integration/exceptions_spec.rb +0 -37
  84. data/spec/integration/integration_helper.rb +0 -1
  85. data/spec/integration/metrics_spec.rb +0 -28
  86. data/spec/shared_examples/tags.rb +0 -42
  87. data/spec/support/rails4/app.rb +0 -44
  88. data/spec/unit/backtrace_spec.rb +0 -85
  89. data/spec/unit/context_spec.rb +0 -40
  90. data/spec/unit/exception_presenter_spec.rb +0 -23
  91. data/spec/unit/influxdb_rails_spec.rb +0 -78
  92. data/spec/unit/middleware/render_subscriber_spec.rb +0 -92
  93. data/spec/unit/middleware/request_subscriber_spec.rb +0 -91
  94. data/spec/unit/middleware/sql_subscriber_spec.rb +0 -81
data/Rakefile CHANGED
@@ -21,12 +21,6 @@ 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
-
30
24
  puts RSpec::Core::Formatters::ConsoleCodes.wrap(gemfile, :cyan)
31
25
  sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "install", "--quiet", "--retry=2", "--jobs=2")
32
26
  sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle", "exec", "rspec")
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'actionpack', '~> 6.0.0'
4
+ gem 'activesupport', '~> 6.0.0'
5
+ gem 'activemodel', '~> 6.0.0'
6
+ gem 'sqlite3', '~> 1.4'
7
+ gem 'rspec-rails'
8
+
9
+ gemspec :path => '../'
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'actionpack', '~> 6.1.0'
4
+ gem 'activesupport', '~> 6.1.0'
5
+ gem 'activemodel', '~> 6.1.0'
6
+ gem 'sqlite3', '~> 1.4'
7
+ gem 'rspec-rails'
8
+
9
+ gemspec :path => '../'
@@ -4,32 +4,41 @@ require "influxdb/rails/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
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
7
  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."
8
+ spec.description = "This gem instruments your Ruby on Rails application using InfluxDB."
9
+ spec.version = InfluxDB::Rails::VERSION
10
+ spec.authors = ["Christian Bruckmayer", "Henne Vogelsang"]
11
+ spec.email = ["christian@bruckmayer.net", "hvogel@hennevogel.de"]
14
12
  spec.licenses = ["MIT"]
13
+ spec.homepage = "https://influxdata.com"
14
+ spec.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
+ }
15
20
 
16
21
  spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars
17
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/})
18
23
  spec.require_paths = ["lib"]
19
24
 
20
- spec.required_ruby_version = ">= 2.3.0"
25
+ spec.required_ruby_version = ">= 2.4.0"
21
26
 
22
27
  spec.add_runtime_dependency "influxdb", "~> 0.6", ">= 0.6.4"
23
- spec.add_runtime_dependency "railties", ">= 4.2"
28
+ spec.add_runtime_dependency "railties", ">= 5.0"
24
29
 
30
+ spec.add_development_dependency "actionmailer"
31
+ spec.add_development_dependency "activejob"
25
32
  spec.add_development_dependency "activerecord"
26
33
  spec.add_development_dependency "bundler", ">= 1.0.0"
27
34
  spec.add_development_dependency "fakeweb"
35
+ spec.add_development_dependency "launchy"
36
+ spec.add_development_dependency "pry"
28
37
  spec.add_development_dependency "rake"
29
38
  spec.add_development_dependency "rdoc"
30
39
  spec.add_development_dependency "rspec"
31
40
  spec.add_development_dependency "rspec-rails", ">= 3.0.0"
32
- spec.add_development_dependency "rubocop", "~> 0.61.1"
41
+ spec.add_development_dependency "rubocop", "~> 1.7.0"
33
42
  spec.add_development_dependency "sqlite3"
34
43
  spec.add_development_dependency "tzinfo"
35
44
  end
@@ -2,17 +2,17 @@ require "net/http"
2
2
  require "net/https"
3
3
  require "rubygems"
4
4
  require "socket"
5
+ require "influxdb/rails/middleware/block_instrumentation_subscriber"
5
6
  require "influxdb/rails/middleware/render_subscriber"
6
7
  require "influxdb/rails/middleware/request_subscriber"
7
8
  require "influxdb/rails/middleware/sql_subscriber"
9
+ require "influxdb/rails/middleware/active_record_subscriber"
10
+ require "influxdb/rails/middleware/active_job_subscriber"
11
+ require "influxdb/rails/middleware/action_mailer_subscriber"
8
12
  require "influxdb/rails/sql/query"
9
13
  require "influxdb/rails/version"
10
- require "influxdb/rails/logger"
11
- require "influxdb/rails/exception_presenter"
12
14
  require "influxdb/rails/configuration"
13
- require "influxdb/rails/backtrace"
14
15
  require "influxdb/rails/context"
15
- require "influxdb/rails/rack"
16
16
 
17
17
  require "influxdb/rails/railtie" if defined?(Rails::Railtie)
18
18
 
@@ -21,41 +21,38 @@ module InfluxDB
21
21
  # InfluxDB and Rails. This is a singleton class.
22
22
  module Rails
23
23
  class << self
24
- include InfluxDB::Rails::Logger
24
+ attr_writer :configuration, :client
25
25
 
26
- attr_writer :configuration
27
- attr_writer :client
26
+ def configure
27
+ return configuration unless block_given?
28
28
 
29
- def configure(_silent = false)
30
- yield(configuration)
31
-
32
- # if we change configuration, reload the client
33
- self.client = nil
34
-
35
- InfluxDB::Logging.logger = configuration.logger unless configuration.logger.nil?
29
+ yield configuration
30
+ self.client = nil # if we change configuration, reload the client
36
31
  end
37
32
 
38
33
  # rubocop:disable Metrics/MethodLength
39
- # rubocop:disable Metrics/AbcSize
40
34
 
41
35
  def client
42
- @client ||= InfluxDB::Client.new \
43
- database: configuration.influxdb_database,
44
- username: configuration.influxdb_username,
45
- password: configuration.influxdb_password,
46
- hosts: configuration.influxdb_hosts,
47
- port: configuration.influxdb_port,
48
- async: configuration.async,
49
- use_ssl: configuration.use_ssl,
50
- retry: configuration.retry,
51
- open_timeout: configuration.open_timeout,
52
- read_timeout: configuration.read_timeout,
53
- max_delay: configuration.max_delay,
54
- time_precision: configuration.time_precision
36
+ @client ||= begin
37
+ cfg = configuration.client
38
+ InfluxDB::Client.new \
39
+ database: cfg.database,
40
+ username: cfg.username,
41
+ password: cfg.password,
42
+ auth_method: cfg.auth_method,
43
+ hosts: cfg.hosts,
44
+ port: cfg.port,
45
+ async: cfg.async,
46
+ use_ssl: cfg.use_ssl,
47
+ retry: cfg.retry,
48
+ open_timeout: cfg.open_timeout,
49
+ read_timeout: cfg.read_timeout,
50
+ max_delay: cfg.max_delay,
51
+ time_precision: cfg.time_precision
52
+ end
55
53
  end
56
54
 
57
55
  # rubocop:enable Metrics/MethodLength
58
- # rubocop:enable Metrics/AbcSize
59
56
 
60
57
  def configuration
61
58
  @configuration ||= InfluxDB::Rails::Configuration.new
@@ -65,58 +62,11 @@ module InfluxDB
65
62
  @current ||= InfluxDB::Rails::Context.new
66
63
  end
67
64
 
68
- def report_exception_unless_ignorable(ex, env = {})
69
- report_exception(ex, env) unless ignorable_exception?(ex)
70
- end
71
- alias transmit_unless_ignorable report_exception_unless_ignorable
72
-
73
- # rubocop:disable Metrics/MethodLength
74
- # rubocop:disable Metrics/AbcSize
75
-
76
- def report_exception(ex, env = {})
77
- timestamp = InfluxDB::Rails.current_timestamp
78
- env = influxdb_request_data if env.empty? && defined? influxdb_request_data
79
- exception_presenter = ExceptionPresenter.new(ex, env)
80
- log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
81
- tags = configuration.tags_middleware.call(
82
- exception_presenter.context.merge(exception_presenter.dimensions)
83
- )
84
-
85
- client.write_point \
86
- configuration.series_name_for_exceptions,
87
- values: exception_presenter.values.merge(ts: timestamp),
88
- tags: tags,
89
- timestamp: timestamp
90
- rescue StandardError => ex
91
- log :info, "[InfluxDB::Rails] Something went terribly wrong." \
92
- " Exception failed to take off! #{ex.class}: #{ex.message}"
93
- end
94
- alias transmit report_exception
95
-
96
- # rubocop:enable Metrics/MethodLength
97
- # rubocop:enable Metrics/AbcSize
98
-
99
- def current_timestamp
100
- InfluxDB.now(configuration.time_precision)
101
- end
102
-
103
- def ignorable_exception?(ex)
104
- configuration.ignore_current_environment? || configuration.ignore_exception?(ex)
105
- end
106
-
107
- def rescue
108
- yield
109
- rescue StandardError => ex
110
- raise ex if configuration.ignore_current_environment?
111
-
112
- transmit_unless_ignorable(ex)
113
- end
114
-
115
- def rescue_and_reraise
116
- yield
117
- rescue StandardError => ex
118
- transmit_unless_ignorable(ex)
119
- raise ex
65
+ def instrument(name, options = {})
66
+ ActiveSupport::Notifications.instrument "block_instrumentation.influxdb_rails",
67
+ **options.merge(name: name) do
68
+ yield if block_given?
69
+ end
120
70
  end
121
71
  end
122
72
  end
@@ -1,211 +1,116 @@
1
+ require "active_support/concern"
2
+
1
3
  module InfluxDB
2
4
  module Rails
3
- # rubocop:disable Metrics/ClassLength
4
-
5
- class Configuration # rubocop:disable Style/Documentation
6
- attr_accessor :influxdb_hosts
7
- attr_accessor :influxdb_port
8
- attr_accessor :influxdb_username
9
- attr_accessor :influxdb_password
10
- attr_accessor :influxdb_database
11
- attr_accessor :async
12
- attr_accessor :use_ssl
13
- attr_accessor :retry
14
- attr_accessor :open_timeout
15
- attr_accessor :read_timeout
16
- attr_accessor :max_delay
17
- attr_accessor :time_precision
18
-
19
- attr_accessor :series_name_for_controller_runtimes
20
- attr_accessor :series_name_for_view_runtimes
21
- attr_accessor :series_name_for_db_runtimes
22
- attr_accessor :series_name_for_exceptions
23
- attr_accessor :series_name_for_instrumentation
24
- attr_accessor :series_name_for_render_template
25
- attr_accessor :series_name_for_render_partial
26
- attr_accessor :series_name_for_render_collection
27
- attr_accessor :series_name_for_sql
28
-
29
- attr_accessor :tags_middleware
30
- attr_accessor :rails_app_name
31
-
32
- attr_accessor :application_name
33
- attr_accessor :application_root
34
-
35
- attr_accessor :logger
36
- attr_accessor :environment
37
- attr_accessor :framework
38
- attr_accessor :framework_version
39
- attr_accessor :language
40
- attr_accessor :language_version
41
- attr_accessor :ignored_exceptions
42
- attr_accessor :ignored_exception_messages
43
- attr_accessor :ignored_reports
44
- attr_accessor :ignored_environments
45
- attr_accessor :ignored_user_agents
46
- attr_accessor :backtrace_filters
47
- attr_accessor :aggregated_exception_classes
48
- attr_accessor :environment_variables
49
- attr_accessor :environment_variable_filters
50
-
51
- attr_accessor :instrumentation_enabled
52
- attr_accessor :debug
53
-
54
- DEFAULTS = {
55
- influxdb_hosts: ["localhost"].freeze,
56
- influxdb_port: 8086,
57
- influxdb_username: "root".freeze,
58
- influxdb_password: "root".freeze,
59
- influxdb_database: nil,
60
- async: true,
61
- use_ssl: false,
62
- retry: nil,
63
- open_timeout: 5,
64
- read_timeout: 300,
65
- max_delay: 30,
66
- time_precision: "s".freeze,
67
-
68
- series_name_for_controller_runtimes: "rails.controller".freeze,
69
- series_name_for_view_runtimes: "rails.view".freeze,
70
- series_name_for_db_runtimes: "rails.db".freeze,
71
- series_name_for_exceptions: "rails.exceptions".freeze,
72
- series_name_for_instrumentation: "instrumentation".freeze,
73
- series_name_for_render_template: "rails.render_template".freeze,
74
- series_name_for_render_partial: "rails.render_partial".freeze,
75
- series_name_for_render_collection: "rails.render_collection".freeze,
76
- series_name_for_sql: nil,
77
-
78
- tags_middleware: ->(tags) { tags },
79
- rails_app_name: nil,
80
-
81
- ignored_exceptions: %w[
82
- ActiveRecord::RecordNotFound
83
- ActionController::RoutingError
84
- ].freeze,
85
-
86
- ignored_exception_messages: [].freeze,
87
- ignored_reports: [].freeze,
88
- ignored_environments: %w[test cucumber selenium].freeze,
89
- ignored_user_agents: %w[GoogleBot].freeze,
90
- environment_variable_filters: [
91
- /password/i,
92
- /key/i,
93
- /secret/i,
94
- /ps1/i,
95
- /rvm_.*_clr/i,
96
- /color/i,
97
- ].freeze,
98
-
99
- backtrace_filters: [
100
- ->(line) { line.gsub(%r{^\./}, "") },
101
- lambda { |line|
102
- return line if InfluxDB::Rails.configuration.application_root.to_s.empty?
103
-
104
- line.gsub(/#{InfluxDB::Rails.configuration.application_root}/, "[APP_ROOT]")
105
- },
106
- lambda { |line|
107
- if defined?(Gem) && !Gem.path.nil? && !Gem.path.empty?
108
- Gem.path.each { |path| line = line.gsub(/#{path}/, "[GEM_ROOT]") }
109
- end
110
- line
111
- },
112
- ].freeze,
113
- }.freeze
114
-
115
- # rubocop:disable Metrics/MethodLength
116
- # rubocop:disable Metrics/AbcSize
117
-
118
- def initialize
119
- @influxdb_hosts = DEFAULTS[:influxdb_hosts]
120
- @influxdb_port = DEFAULTS[:influxdb_port]
121
- @influxdb_username = DEFAULTS[:influxdb_username]
122
- @influxdb_password = DEFAULTS[:influxdb_password]
123
- @influxdb_database = DEFAULTS[:influxdb_database]
124
- @async = DEFAULTS[:async]
125
- @use_ssl = DEFAULTS[:use_ssl]
126
- @retry = DEFAULTS[:retry]
127
- @open_timeout = DEFAULTS[:open_timeout]
128
- @read_timeout = DEFAULTS[:read_timeout]
129
- @max_delay = DEFAULTS[:max_delay]
130
- @time_precision = DEFAULTS[:time_precision]
131
-
132
- @series_name_for_controller_runtimes = DEFAULTS[:series_name_for_controller_runtimes]
133
- @series_name_for_view_runtimes = DEFAULTS[:series_name_for_view_runtimes]
134
- @series_name_for_db_runtimes = DEFAULTS[:series_name_for_db_runtimes]
135
- @series_name_for_exceptions = DEFAULTS[:series_name_for_exceptions]
136
- @series_name_for_instrumentation = DEFAULTS[:series_name_for_instrumentation]
137
- @series_name_for_render_template = DEFAULTS[:series_name_for_render_template]
138
- @series_name_for_render_partial = DEFAULTS[:series_name_for_render_partial]
139
- @series_name_for_render_collection = DEFAULTS[:series_name_for_render_collection]
140
- @series_name_for_sql = DEFAULTS[:series_name_for_sql]
141
-
142
- @tags_middleware = DEFAULTS[:tags_middleware]
143
- @rails_app_name = DEFAULTS[:rails_app_name]
144
-
145
- @ignored_exceptions = DEFAULTS[:ignored_exceptions].dup
146
- @ignored_exception_messages = DEFAULTS[:ignored_exception_messages].dup
147
- @ignored_reports = DEFAULTS[:ignored_reports].dup
148
- @ignored_environments = DEFAULTS[:ignored_environments].dup
149
- @ignored_user_agents = DEFAULTS[:ignored_user_agents].dup
150
- @backtrace_filters = DEFAULTS[:backtrace_filters].dup
151
- @environment_variable_filters = DEFAULTS[:environment_variable_filters]
152
- @aggregated_exception_classes = []
153
-
154
- @debug = false
155
- @rescue_global_exceptions = false
156
- @instrumentation_enabled = true
5
+ module Configurable
6
+ extend ActiveSupport::Concern
7
+
8
+ class_methods do
9
+ def defaults
10
+ @defaults ||= {}
11
+ end
12
+
13
+ def set_defaults(**values) # rubocop:disable Naming/AccessorMethodName:
14
+ defaults.merge! values
15
+ attr_accessor(*defaults.keys)
16
+ end
157
17
  end
158
18
 
159
- # rubocop:enable Metrics/MethodLength
160
- # rubocop:enable Metrics/AbcSize
161
-
162
- def debug?
163
- !!@debug # rubocop:disable Style/DoubleNegation
19
+ def load_defaults
20
+ self.class.defaults.each do |key, value|
21
+ val = value.dup rescue value
22
+ public_send "#{key}=", val
23
+ end
164
24
  end
25
+ end
26
+ private_constant :Configurable
27
+
28
+ class ClientConfig
29
+ include Configurable
30
+
31
+ set_defaults(
32
+ hosts: ["localhost"].freeze,
33
+ port: 8086,
34
+ username: "root".freeze,
35
+ password: "root".freeze,
36
+ database: nil,
37
+ auth_method: "params".freeze,
38
+ async: true,
39
+ use_ssl: false,
40
+ retry: nil,
41
+ open_timeout: 5,
42
+ read_timeout: 300,
43
+ max_delay: 30,
44
+ time_precision: "s".freeze
45
+ )
165
46
 
166
- def instrumentation_enabled?
167
- !!@instrumentation_enabled # rubocop:disable Style/DoubleNegation
47
+ def initialize
48
+ load_defaults
168
49
  end
50
+ end
51
+ private_constant :ClientConfig
52
+
53
+ class Configuration
54
+ include Configurable
55
+
56
+ set_defaults(
57
+ measurement_name: "rails".freeze,
58
+ ignored_hooks: [].freeze,
59
+ tags_middleware: ->(tags) { tags },
60
+ rails_app_name: nil,
61
+ ignored_environments: %w[test cucumber selenium].freeze,
62
+ environment: ::Rails.env,
63
+ debug: false
64
+ )
65
+
66
+ # config option set after_initialize
67
+ attr_accessor(:environment, :application_name)
68
+
69
+ # configuration passed to InfluxDB::Client
70
+ attr_reader :client
71
+
72
+ # FIXME: Old configuration options, remove this in 1.0.1
73
+ attr_writer \
74
+ :series_name_for_controller_runtimes,
75
+ :series_name_for_view_runtimes,
76
+ :series_name_for_db_runtimes,
77
+ :series_name_for_render_template,
78
+ :series_name_for_render_partial,
79
+ :series_name_for_render_collection,
80
+ :series_name_for_sql,
81
+ :series_name_for_exceptions,
82
+ :series_name_for_instrumentation,
83
+ :ignored_exceptions,
84
+ :ignored_exception_messages,
85
+ :ignored_user_agents,
86
+ :application_root,
87
+ :environment_variable_filters,
88
+ :backtrace_filters,
89
+ :influxdb_database,
90
+ :influxdb_username,
91
+ :influxdb_password,
92
+ :influxdb_hosts,
93
+ :influxdb_port,
94
+ :async,
95
+ :use_ssl,
96
+ :retry,
97
+ :open_timeout,
98
+ :read_timeout,
99
+ :max_delay,
100
+ :time_precision
169
101
 
170
- def ignore_user_agent?(incoming_user_agent)
171
- return false if ignored_user_agents.nil?
102
+ def initialize
103
+ @client = ClientConfig.new
104
+ load_defaults
105
+ end
172
106
 
173
- ignored_user_agents.any? { |agent| incoming_user_agent =~ /#{agent}/ }
107
+ def debug?
108
+ @debug
174
109
  end
175
110
 
176
111
  def ignore_current_environment?
177
112
  ignored_environments.include?(environment)
178
113
  end
179
-
180
- def ignore_exception?(ex)
181
- !ignored_exception_messages.find { |msg| /.*#{msg}.*/ =~ ex.message }.nil? ||
182
- ignored_exceptions.include?(ex.class.to_s)
183
- end
184
-
185
- def define_custom_exception_data(&block)
186
- @custom_exception_data_handler = block
187
- end
188
-
189
- def add_custom_exception_data(exception_presenter)
190
- @custom_exception_data_handler&.call(exception_presenter)
191
- end
192
-
193
- def load_rails_defaults
194
- @logger ||= ::Rails.logger
195
- @environment ||= ::Rails.env
196
- @application_root ||= ::Rails.root
197
- @application_name ||= ::Rails.application.class.parent_name
198
- @framework = "Rails"
199
- @framework_version = ::Rails.version
200
- end
201
-
202
- private
203
-
204
- def initialize_http_connection
205
- Net::HTTP.new(@app_host, "80")
206
- end
207
114
  end
208
-
209
- # rubocop:enable Metrics/ClassLength
210
115
  end
211
116
  end