asklytics-influxdb-rails 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +78 -0
  5. data/.travis.yml +37 -0
  6. data/CHANGELOG.md +127 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +291 -0
  10. data/Rakefile +34 -0
  11. data/config.ru +7 -0
  12. data/gemfiles/Gemfile.rails-4.2.x +7 -0
  13. data/gemfiles/Gemfile.rails-5.0.x +7 -0
  14. data/gemfiles/Gemfile.rails-5.1.x +7 -0
  15. data/gemfiles/Gemfile.rails-5.2.x +7 -0
  16. data/influxdb-rails.gemspec +52 -0
  17. data/lib/httplog.rb +8 -0
  18. data/lib/influxdb-rails.rb +134 -0
  19. data/lib/influxdb/rails/air_traffic_controller.rb +41 -0
  20. data/lib/influxdb/rails/backtrace.rb +44 -0
  21. data/lib/influxdb/rails/configuration.rb +263 -0
  22. data/lib/influxdb/rails/context.rb +42 -0
  23. data/lib/influxdb/rails/exception_presenter.rb +94 -0
  24. data/lib/influxdb/rails/httplog/adapters/ethon.rb +62 -0
  25. data/lib/influxdb/rails/httplog/adapters/excon.rb +67 -0
  26. data/lib/influxdb/rails/httplog/adapters/http.rb +64 -0
  27. data/lib/influxdb/rails/httplog/adapters/httpclient.rb +76 -0
  28. data/lib/influxdb/rails/httplog/adapters/net_http.rb +53 -0
  29. data/lib/influxdb/rails/httplog/adapters/patron.rb +44 -0
  30. data/lib/influxdb/rails/httplog/helpers/al_helper.rb +12 -0
  31. data/lib/influxdb/rails/httplog/http_configuration.rb +55 -0
  32. data/lib/influxdb/rails/httplog/http_log.rb +332 -0
  33. data/lib/influxdb/rails/instrumentation.rb +34 -0
  34. data/lib/influxdb/rails/logger.rb +16 -0
  35. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +16 -0
  36. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +31 -0
  37. data/lib/influxdb/rails/middleware/render_subscriber.rb +28 -0
  38. data/lib/influxdb/rails/middleware/request_subscriber.rb +69 -0
  39. data/lib/influxdb/rails/middleware/simple_subscriber.rb +71 -0
  40. data/lib/influxdb/rails/middleware/sql_subscriber.rb +35 -0
  41. data/lib/influxdb/rails/middleware/subscriber.rb +44 -0
  42. data/lib/influxdb/rails/rack.rb +39 -0
  43. data/lib/influxdb/rails/railtie.rb +52 -0
  44. data/lib/influxdb/rails/sql/normalizer.rb +27 -0
  45. data/lib/influxdb/rails/sql/query.rb +32 -0
  46. data/lib/influxdb/rails/version.rb +5 -0
  47. data/lib/rails/generators/influxdb/influxdb_generator.rb +15 -0
  48. data/lib/rails/generators/influxdb/templates/initializer.rb +11 -0
  49. data/spec/controllers/widgets_controller_spec.rb +15 -0
  50. data/spec/integration/exceptions_spec.rb +37 -0
  51. data/spec/integration/integration_helper.rb +1 -0
  52. data/spec/integration/metrics_spec.rb +28 -0
  53. data/spec/shared_examples/tags.rb +42 -0
  54. data/spec/spec_helper.rb +31 -0
  55. data/spec/support/rails4/app.rb +44 -0
  56. data/spec/support/rails5/app.rb +44 -0
  57. data/spec/support/views/widgets/_item.html.erb +1 -0
  58. data/spec/support/views/widgets/index.html.erb +5 -0
  59. data/spec/unit/backtrace_spec.rb +85 -0
  60. data/spec/unit/configuration_spec.rb +125 -0
  61. data/spec/unit/context_spec.rb +40 -0
  62. data/spec/unit/exception_presenter_spec.rb +23 -0
  63. data/spec/unit/influxdb_rails_spec.rb +78 -0
  64. data/spec/unit/middleware/render_subscriber_spec.rb +92 -0
  65. data/spec/unit/middleware/request_subscriber_spec.rb +91 -0
  66. data/spec/unit/middleware/sql_subscriber_spec.rb +81 -0
  67. data/spec/unit/sql/normalizer_spec.rb +15 -0
  68. data/spec/unit/sql/query_spec.rb +29 -0
  69. metadata +487 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fe872e433dd52c51fe55f64ffc79e67f5d07dd2bd716e80391b76c5ae7acd878
4
+ data.tar.gz: 39e51208e5948f76bcae86e332d05ae77a448cb0e6c8a521232b4e721b34d3f7
5
+ SHA512:
6
+ metadata.gz: 3861a4cb9b6aa2c1c5cdec19c9496a77c1d2433d9040371d0dae62c907ebdfd7205d16a938e3d801568ebf8d406eace171d0bba253b862473975513d80aae6bd
7
+ data.tar.gz: 84e9d9dfda18099c4e5278fe168f05b21adc880a4190cfcac0039580e53f97b94f58242306704ff4dbbe50e21d8978fe350e03bc1aaeebea5b93ae8ee439e05f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .bundle
2
+ .rvmrc
3
+ *.gem
4
+ Gemfile.lock
5
+ Gemfile.local
6
+ gemfiles/*.lock
7
+ pkg/*
8
+ spec/support/rails*/log/*
9
+ .ruby-*
10
+ vendor/bundle
11
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,78 @@
1
+ AllCops:
2
+ Include:
3
+ - 'Rakefile'
4
+ - '*.gemspec'
5
+ - 'lib/**/*.rb'
6
+ - 'spec/**/*.rb'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'smoke/**/*'
10
+ - 'Gemfile'
11
+ - 'vendor/bundle/**/*'
12
+ DisplayCopNames: true
13
+ StyleGuideCopsOnly: false
14
+ TargetRubyVersion: 2.3
15
+
16
+ Rails:
17
+ Enabled: false
18
+
19
+ Layout/EmptyLinesAroundArguments:
20
+ Enabled: false
21
+
22
+ Layout/SpaceBeforeBlockBraces:
23
+ EnforcedStyleForEmptyBraces: space
24
+
25
+ Layout/AlignHash:
26
+ EnforcedColonStyle: table
27
+ EnforcedHashRocketStyle: table
28
+
29
+ Metrics/AbcSize:
30
+ Max: 20
31
+
32
+ Metrics/BlockLength:
33
+ Exclude:
34
+ - 'spec/**/*.rb'
35
+
36
+ Metrics/LineLength:
37
+ Max: 100
38
+ Exclude:
39
+ - 'spec/**/*.rb'
40
+
41
+ Metrics/ModuleLength:
42
+ CountComments: false # count full line comments?
43
+ Max: 120
44
+
45
+ Metrics/ParameterLists:
46
+ Max: 6
47
+
48
+ Naming/UncommunicativeMethodParamName:
49
+ AllowedNames: [io, id, db, ex]
50
+
51
+ Naming/FileName:
52
+ Exclude:
53
+ - lib/influxdb-rails.rb
54
+
55
+ Style/FormatStringToken:
56
+ Enabled: false
57
+
58
+ Style/FrozenStringLiteralComment:
59
+ Enabled: false
60
+
61
+ Style/NumericPredicate:
62
+ Enabled: false
63
+
64
+ Style/RescueModifier:
65
+ Enabled: false
66
+
67
+ Style/StringLiterals:
68
+ EnforcedStyle: double_quotes
69
+
70
+ Style/TrailingCommaInArrayLiteral:
71
+ EnforcedStyleForMultiline: comma
72
+ Exclude:
73
+ - "spec/**/*.rb"
74
+
75
+ Style/TrailingCommaInHashLiteral:
76
+ EnforcedStyleForMultiline: comma
77
+ Exclude:
78
+ - "spec/**/*.rb"
data/.travis.yml ADDED
@@ -0,0 +1,37 @@
1
+ sudo: required
2
+ dist: trusty
3
+ language: ruby
4
+ before_install:
5
+ - gem update --system --no-doc
6
+ - gem install bundler --no-doc
7
+ - gem update bundler --no-doc
8
+ rvm:
9
+ - ruby-head
10
+ - "2.6"
11
+ - "2.5"
12
+ - "2.4"
13
+ - "2.3"
14
+ gemfile:
15
+ - gemfiles/Gemfile.rails-5.2.x
16
+ - gemfiles/Gemfile.rails-5.1.x
17
+ - gemfiles/Gemfile.rails-5.0.x
18
+ - gemfiles/Gemfile.rails-4.2.x
19
+ env:
20
+ - TEST_TASK=spec
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: ruby-head
24
+ include:
25
+ - { rvm: "2.6", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
26
+ exclude:
27
+ # Rails < 5 not on MRI 2.4+
28
+ - { rvm: ruby-head, 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" }
32
+ addons:
33
+ apt:
34
+ packages:
35
+ - haveged
36
+ - libgmp-dev
37
+ script: bundle exec rake $TEST_TASK
data/CHANGELOG.md ADDED
@@ -0,0 +1,127 @@
1
+ # Changelog
2
+
3
+ For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/master).
4
+
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
+
14
+ ## v1.0.0.beta2, released 2018-12-07
15
+
16
+ - Added `tags_middleware` config option (#47, @Kukunin)
17
+ - Removed path tag from metrics (introduced with #50), because it
18
+ potentially produces "exceed tag value limit" (#54, @ChrisBr)
19
+ - Added render instrumentation (#53, @ChrisBr)
20
+ - Added SQL instrumentation (#55, @ChrisBr)
21
+
22
+ ## v1.0.0.beta1, released 2018-11-22
23
+
24
+ - Added app name to the measurement's tag sets (#44, @stefanhorning)
25
+ - Added config parameters for additional series:
26
+ - `InfluxDB::Rails::Configuration#series_name_for_instrumentation`
27
+ - `InfluxDB::Rails::Configuration#series_name_for_exceptions`
28
+ - Added method, status and format tags to metrics (#50, @ChrisBr)
29
+
30
+ ### Breaking changes
31
+
32
+ - Support for Ruby <= 2.2.x has been removed
33
+ - Support for Rails <= 4.1.x has been removed
34
+ - Changed keys for exceptions (#43, @vassilevsky & @kkentzo)
35
+ - Exception message and backtrace are now InfluxDB values (changed from tags).
36
+ - The keys changed from `message` to `exception_message` and from
37
+ `backtrace` to `exception_backtrace`, since a single shard does not
38
+ allow for tags and values to share the same key
39
+ - To convert existing exception traces into the new format for
40
+ consistency, see [this gist][migrate].
41
+ - Removed `time` key from InfluxDB::Rails::ExceptionPresenter#context`
42
+ - use `InfluxDB::Rails.current_timestamp` directly
43
+ - Removed previously deprecated methods:
44
+ - `InfluxDB::Rails::Configuration#reraise_global_exceptions`
45
+ - `InfluxDB::Rails::Configuration#database_name`
46
+ - `InfluxDB::Rails::Configuration#application_id`
47
+
48
+ [migrate]: https://gist.github.com/dmke/2d0f4ccf9f43faf82e732dc041e90ca2
49
+
50
+ ## v0.4.3, released 2017-12-12
51
+
52
+ - Added `time_precision` config option (#42, @kkentzo)
53
+
54
+ ## v0.4.2, released 2017-11-28
55
+
56
+ - Added `open_timeout`, `read_timeout`, and `max_delay` config options
57
+ (#41, @emaxi)
58
+ - Deprecate unused method (`#reraise_global_exceptions` in
59
+ `InfluxDB::Rails::Configuration`, #37, @vassilevsky)
60
+
61
+ ## v0.4.1, released 2017-10-23
62
+
63
+ - Bump `influx` version dependency (#40, @rockclimber73)
64
+
65
+ ## v0.4.0, released 2017-08-19
66
+
67
+ - Drop support for Rails 3, Ruby < 2.2
68
+ - Sync version with `influxdb` gem
69
+
70
+ ## v0.1.12, released 2017-06-06
71
+
72
+ - Added Rails 5.1 compatibility (#31, @djgould).
73
+ - Added `retry` config option (#17, @scambra and #18, @bcantin).
74
+
75
+ ## v0.1.11, released 2016-11-24
76
+
77
+ - Bumped `influxdb` Rubygem dependency (#28, #32, @agx).
78
+
79
+ **Note:** The real changelog starts here. Previous entries are reconstructed
80
+ from the commit history by correlating release version with Git tags, which
81
+ may or may not reflect what was really released.
82
+
83
+ ## v0.1.10, released 2014-10-08
84
+
85
+ - Lazy loading of `InfluxDB::Client` (#15, @chingo13).
86
+ - Various test fixes.
87
+
88
+ ## v0.1.9, released 2014-06-18
89
+
90
+ - v0.1.8 was yanked
91
+ - Initializer now allows multiple hosts.
92
+
93
+ ## v0.1.7, released 2014-04-09
94
+
95
+ - Added logger.
96
+
97
+ ## v0.1.6, released 2014-04-08
98
+
99
+ - No changes (?)
100
+
101
+ ## v0.1.5, released 2014-04-02
102
+
103
+ - No changes (?)
104
+
105
+ ## v0.1.4, released 2014-03-26
106
+
107
+ - Added docs
108
+ - Made `async` option default to `true`.
109
+
110
+ ## v0.1.3, released 2014-02-11
111
+
112
+ - Set series name defaults.
113
+ - Fixed a configuration bug.
114
+
115
+ ## v0.1.2, released 2014-02-11
116
+
117
+ - Graceful handling of authentication errors.
118
+ - Fixes in documentation.
119
+
120
+ ## v0.1.1, released 2014-02-06
121
+
122
+ - Refactoring of `ActiveSupport::Notification` handling.
123
+ - Added more initializer options.
124
+
125
+ ## v0.1.0, released 2014-02-06
126
+
127
+ - Larger refactoring.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ local_gemfile = 'Gemfile.local'
6
+
7
+ if File.exist?(local_gemfile)
8
+ eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Todd Persen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,291 @@
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
+ > for an online version.
5
+
6
+ # influxdb-rails
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/influxdb-rails.svg)](https://badge.fury.io/rb/influxdb-rails)
9
+ [![Build Status](https://travis-ci.org/influxdata/influxdb-rails.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-rails)
10
+
11
+ Automatically instrument your Ruby on Rails applications and write the
12
+ metrics directly into [InfluxDB](http://influxdb.org/).
13
+
14
+ This gem is designed for Rails 4.2+, Ruby 2.3+ and InfluxDB 0.9+.
15
+
16
+
17
+ ## Installation
18
+
19
+ ```
20
+ $ [sudo] gem install influxdb-rails
21
+ ```
22
+
23
+ Or add it to your `Gemfile`, etc.
24
+
25
+
26
+ ## Usage
27
+
28
+ To get things set up, just create an initializer:
29
+
30
+ ```
31
+ $ cd /to/you/rails/application
32
+ $ touch config/initializers/influxdb_rails.rb
33
+ ```
34
+
35
+ In this file, you can configure the `InfluxDB::Rails` adapter. The default
36
+ config should look something like this:
37
+
38
+ ``` ruby
39
+ InfluxDB::Rails.configure do |config|
40
+ config.influxdb_database = "rails"
41
+ config.influxdb_username = "root"
42
+ config.influxdb_password = "root"
43
+ config.influxdb_hosts = ["localhost"]
44
+ config.influxdb_port = 8086
45
+
46
+ # config.retry = false
47
+ # config.async = false
48
+ # config.open_timeout = 5
49
+ # config.read_timeout = 30
50
+ # config.max_delay = 300
51
+ # config.time_precision = 'ms'
52
+
53
+ # config.tags_middleware = ->(tags) { tags }
54
+
55
+ # config.series_name_for_controller_runtimes = "rails.controller"
56
+ # config.series_name_for_view_runtimes = "rails.view"
57
+ # config.series_name_for_db_runtimes = "rails.db"
58
+ # config.series_name_for_render_template = "rails.render_template"
59
+ # config.series_name_for_render_partial = "rails.render_partial"
60
+ # config.series_name_for_render_collection = "rails.render_collection"
61
+ # config.series_name_for_sql = nil
62
+ # config.series_name_for_exceptions = "rails.exceptions"
63
+ # config.series_name_for_instrumentation = "instrumentation"
64
+
65
+ # Set the application name to something meaningful, by default we
66
+ # infer the app name from the Rails.application class name.
67
+ # config.application_name = Rails.application.class.parent_name
68
+ end
69
+ ```
70
+
71
+ To see all default values, take a look into `InfluxDB::Rails::Configuration::DEFAULTS`,
72
+ defined in `lib/influxdb/rails/configuration.rb`
73
+
74
+ Out of the box, you'll automatically get reporting of your controller,
75
+ view, and db runtimes and rendering of template, partial and collection for each request.
76
+ Reporting of SQL queries is disabled by default because it is still in experimental mode
77
+ and currently requires String parsing which might cause performance issues on query
78
+ intensive applications. You can enable it by setting the `series_name_for_sql`
79
+ configuration.
80
+
81
+ It is possible to disable the rendering series by setting the series_name to nil.
82
+
83
+ ```ruby
84
+ # config.series_name_for_render_template = nil
85
+ # config.series_name_for_render_partial = nil
86
+ # config.series_name_for_render_collection = nil
87
+ ```
88
+
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
+
93
+
94
+ ``` ruby
95
+ InfluxDB::Rails.client.write_point "events",
96
+ tags: { url: "/foo", user_id: current_user.id, location: InfluxDB::Rails.current.location },
97
+ values: { value: 0 }
98
+ ```
99
+
100
+ Additional documentation for `InfluxDB::Client` lives in the
101
+ [influxdb-ruby](http://github.com/influxdata/influxdb-ruby) repo.
102
+
103
+
104
+ ### Tags
105
+
106
+ You can modify the tags sent to InfluxDB by defining a middleware, which
107
+ receives the current tag set (`Hash` with `Symbol` keys and `String`
108
+ values) as argument and returns a hash in the same form. The middleware
109
+ can be any object, as long it responds to `#call` (like a `Proc`):
110
+
111
+ ```ruby
112
+ InfluxDB::Rails.configure do |config|
113
+ config.tags_middleware = lambda do |tags|
114
+ tags.merge(env: Rails.env)
115
+ end
116
+ end
117
+ ```
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
+
134
+ By default, the following tags are sent for *non-exception series*
135
+ (`rails.controller`, `rails.view`, `rails.db` and `instrumentation`):
136
+
137
+ ```ruby
138
+ {
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]
145
+ }
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
+
171
+
172
+ For the exceptions (series name `rails.exceptions`):
173
+
174
+ ```ruby
175
+ {
176
+ application_name: InfluxDB::Rails.configuration.application_name,
177
+ application_root: InfluxDB::Rails.configuration.application_root,
178
+ framework: InfluxDB::Rails.configuration.framework,
179
+ framework_version: InfluxDB::Rails.configuration.framework_version,
180
+ language: "Ruby",
181
+ language_version: "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
182
+ custom_data: @custom_data,
183
+ class: @exception.class.to_s,
184
+ method: "#{@controller}##{@action}",
185
+ filename: File.basename(@backtrace.lines.first.try(:file)),
186
+ server: Socket.gethostname,
187
+ status: "open",
188
+ }
189
+ ```
190
+
191
+
192
+ ## Frequently Asked Questions
193
+
194
+
195
+ **Q: I'm seeing far less requests recorded in InfluxDB than my logs suggest.**
196
+
197
+ By default, this gem only sends data points with *second time precision*
198
+ to the InfluxDB server. If you experience multiple requests per second,
199
+ **only the last** point (with the same tag set) is stored.
200
+
201
+ See [InfluxDB server docs][duplicate-points] for further details.
202
+ To work around this limitation, set the `config.time_precision` to one
203
+ of `"ms"` (milliseconds, 1·10<sup>-3</sup>s), `"us"` (microseconds,
204
+ 1·10<sup>-6</sup>s) or `"ns"` (nanoseconds, 1·10<sup>-9</sup>s).
205
+
206
+ [duplicate-points]: https://docs.influxdata.com/influxdb/v1.4/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
207
+
208
+
209
+ **Q: How does the measurement influence the response time?**
210
+
211
+ This gem subscribes to the `process_action.action_controller` controller
212
+ notification (via `ActiveSupport::Notifications` · [guide][arn-guide] ·
213
+ [docs][arn-docs] · [impl][arn-impl]), i.e. it runs *after* a controller
214
+ action has finished.
215
+
216
+ The thread processing incoming HTTP requests however is blocked until
217
+ the notification is processed. By default, this means calculating and
218
+ enqueueing some data points for later processing (`config.async = true`),
219
+ which usually is negligible. The asynchronuous sending happens in a seperate
220
+ thread, which batches multiple data points.
221
+
222
+ If you, however, use a synchronous client (`config.async = false`), the
223
+ data points are immediately sent to the InfluxDB server. Depending on
224
+ the network link, this might cause the HTTP thread to block a lot longer.
225
+
226
+ [arn-guide]: http://guides.rubyonrails.org/v5.1/active_support_instrumentation.html#process-action-action-controller
227
+ [arn-docs]: http://api.rubyonrails.org/v5.1/classes/ActiveSupport/Notifications.html
228
+ [arn-impl]: https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_controller/metal/instrumentation.rb#L30-L38
229
+
230
+
231
+ **Q: How does this gem handle an unreachable InfluxDB server?**
232
+
233
+ By default, the InfluxDB client will retry indefinetly, until a write
234
+ succeedes (see [client docs][] for details). This has two important
235
+ implcations, depending on the value of `config.async`:
236
+
237
+ - if the client runs asynchronously (i.e. in a seperate thread), the queue
238
+ might fill up with hundrets of megabytes of data points
239
+ - if the client runs synchronously (i.e. inline in the request/response
240
+ cycle), it might block all available request threads
241
+
242
+ In both cases, your application server might become inresponsive and needs
243
+ to be restarted (which can happen automatically in `cgroups` contexts).
244
+
245
+ If you setup a maximum retry value (`Integer === config.retry`), the
246
+ client will try upto that amount of times to send the data to the server
247
+ and (on final error) log an error and discard the values.
248
+
249
+ [client docs]: https://github.com/influxdata/influxdb-ruby#retry
250
+
251
+
252
+ **Q: What happens with unwritten points, when the application restarts?**
253
+
254
+ The data points are simply discarded.
255
+
256
+
257
+ **Q: What happens, when the InfluxDB client or this gem throws an exception? Will the user see 500 errors?**
258
+
259
+ No. The controller instrumentation is wrapped in a `rescue StandardError`
260
+ clause, i.e. this gem will only write the error to the `client.logger`
261
+ (`Rails.logger` by default) and not disturb the user experience.
262
+
263
+
264
+ ## Testing
265
+
266
+ ```
267
+ git clone git@github.com:influxdata/influxdb-rails.git
268
+ cd influxdb-rails
269
+ bundle
270
+ bundle exec rake
271
+ ```
272
+
273
+
274
+ ## Contributing
275
+
276
+ - Fork this repository on GitHub.
277
+ - Make your changes.
278
+ - Add tests.
279
+ - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top.
280
+ - Run the tests:
281
+ - Either run them manually:
282
+ ```console
283
+ $ rake test:all
284
+ ```
285
+ - or wait for [Travis][travis-pr] to pick up your changes, *after*
286
+ you made a pull request.
287
+ - Send a pull request.
288
+ - Please rebase against the master branch.
289
+ - If your changes look good, we'll merge them.
290
+
291
+ [travis-pr]: https://travis-ci.org/influxdata/influxdb-rails/pull_requests