experimental-influxdb-rails 1.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +78 -0
  5. data/.travis.yml +37 -0
  6. data/CHANGELOG.md +133 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +292 -0
  10. data/Rakefile +34 -0
  11. data/config.ru +7 -0
  12. data/experimental-influxdb-rails.gemspec +35 -0
  13. data/gemfiles/Gemfile.rails-4.2.x +7 -0
  14. data/gemfiles/Gemfile.rails-5.0.x +7 -0
  15. data/gemfiles/Gemfile.rails-5.1.x +7 -0
  16. data/gemfiles/Gemfile.rails-5.2.x +7 -0
  17. data/lib/experimental-influxdb-rails.rb +123 -0
  18. data/lib/influxdb/rails/air_traffic_controller.rb +41 -0
  19. data/lib/influxdb/rails/backtrace.rb +44 -0
  20. data/lib/influxdb/rails/configuration.rb +211 -0
  21. data/lib/influxdb/rails/context.rb +51 -0
  22. data/lib/influxdb/rails/exception_presenter.rb +94 -0
  23. data/lib/influxdb/rails/instrumentation.rb +34 -0
  24. data/lib/influxdb/rails/logger.rb +16 -0
  25. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +16 -0
  26. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +31 -0
  27. data/lib/influxdb/rails/middleware/render_subscriber.rb +26 -0
  28. data/lib/influxdb/rails/middleware/request_subscriber.rb +59 -0
  29. data/lib/influxdb/rails/middleware/simple_subscriber.rb +49 -0
  30. data/lib/influxdb/rails/middleware/sql_subscriber.rb +38 -0
  31. data/lib/influxdb/rails/middleware/subscriber.rb +48 -0
  32. data/lib/influxdb/rails/rack.rb +24 -0
  33. data/lib/influxdb/rails/railtie.rb +51 -0
  34. data/lib/influxdb/rails/sql/normalizer.rb +27 -0
  35. data/lib/influxdb/rails/sql/query.rb +32 -0
  36. data/lib/influxdb/rails/version.rb +5 -0
  37. data/lib/rails/generators/influxdb/influxdb_generator.rb +15 -0
  38. data/lib/rails/generators/influxdb/templates/initializer.rb +11 -0
  39. data/spec/controllers/widgets_controller_spec.rb +15 -0
  40. data/spec/integration/exceptions_spec.rb +37 -0
  41. data/spec/integration/integration_helper.rb +1 -0
  42. data/spec/integration/metrics_spec.rb +28 -0
  43. data/spec/shared_examples/data.rb +67 -0
  44. data/spec/shared_examples/tags.rb +45 -0
  45. data/spec/spec_helper.rb +31 -0
  46. data/spec/support/rails4/app.rb +44 -0
  47. data/spec/support/rails5/app.rb +44 -0
  48. data/spec/support/views/widgets/_item.html.erb +1 -0
  49. data/spec/support/views/widgets/index.html.erb +5 -0
  50. data/spec/unit/backtrace_spec.rb +85 -0
  51. data/spec/unit/configuration_spec.rb +125 -0
  52. data/spec/unit/context_spec.rb +40 -0
  53. data/spec/unit/exception_presenter_spec.rb +23 -0
  54. data/spec/unit/influxdb_rails_spec.rb +78 -0
  55. data/spec/unit/middleware/render_subscriber_spec.rb +92 -0
  56. data/spec/unit/middleware/request_subscriber_spec.rb +94 -0
  57. data/spec/unit/middleware/sql_subscriber_spec.rb +95 -0
  58. data/spec/unit/sql/normalizer_spec.rb +15 -0
  59. data/spec/unit/sql/query_spec.rb +29 -0
  60. metadata +300 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a954571f679bcc769801cba122d184de5cec35a9e5a41f148f7a0cef447fcae
4
+ data.tar.gz: 49d45ca15c6dd1e0e63985e30715c6e0369f97f56cd87cb4cb31b0f4a609f9d9
5
+ SHA512:
6
+ metadata.gz: 6621fb5502ac68ef2d7e8f303a7abe04172d41ba37edc26f61778b1522ff30624a98fb9f3ff1a20c554fd6705bad5c9cf13461ba19ce9f16882554fdf6ffaec5
7
+ data.tar.gz: 2bfc11c99880dd8d68f38ad56ad0d61b8f076c4bf6c692a2136caa80f113d5411f70d13d16c656676c4dab2d03d4dcb0a21d65bc8c1fbae7714d517000bb6820
data/.gitignore ADDED
@@ -0,0 +1,10 @@
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
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,133 @@
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.beta4, released 2019-01-13
7
+ - Remove empty tags (#64 @ChrisBr)
8
+ - Add default location :raw to SQL subscriber (#64 @ChrisBr)
9
+ - Add dynamic values (#65 @ChrisBr)
10
+ - Add start time value to request subscriber (#65 @ChrisBr)
11
+
12
+ ## v1.0.0.beta3, released 2019-01-07
13
+
14
+ - Add dynamic tags (#62, @ChrisBr)
15
+ - Reduce cardinality of resulting InfluxDB measurement by moving
16
+ some tags to values (#63, @ChrisBr)
17
+ - Remove SCHEMA queries from SQL instrumentation (#61, @ChrisBr)
18
+
19
+
20
+ ## v1.0.0.beta2, released 2018-12-07
21
+
22
+ - Added `tags_middleware` config option (#47, @Kukunin)
23
+ - Removed path tag from metrics (introduced with #50), because it
24
+ potentially produces "exceed tag value limit" (#54, @ChrisBr)
25
+ - Added render instrumentation (#53, @ChrisBr)
26
+ - Added SQL instrumentation (#55, @ChrisBr)
27
+
28
+ ## v1.0.0.beta1, released 2018-11-22
29
+
30
+ - Added app name to the measurement's tag sets (#44, @stefanhorning)
31
+ - Added config parameters for additional series:
32
+ - `InfluxDB::Rails::Configuration#series_name_for_instrumentation`
33
+ - `InfluxDB::Rails::Configuration#series_name_for_exceptions`
34
+ - Added method, status and format tags to metrics (#50, @ChrisBr)
35
+
36
+ ### Breaking changes
37
+
38
+ - Support for Ruby <= 2.2.x has been removed
39
+ - Support for Rails <= 4.1.x has been removed
40
+ - Changed keys for exceptions (#43, @vassilevsky & @kkentzo)
41
+ - Exception message and backtrace are now InfluxDB values (changed from tags).
42
+ - The keys changed from `message` to `exception_message` and from
43
+ `backtrace` to `exception_backtrace`, since a single shard does not
44
+ allow for tags and values to share the same key
45
+ - To convert existing exception traces into the new format for
46
+ consistency, see [this gist][migrate].
47
+ - Removed `time` key from InfluxDB::Rails::ExceptionPresenter#context`
48
+ - use `InfluxDB::Rails.current_timestamp` directly
49
+ - Removed previously deprecated methods:
50
+ - `InfluxDB::Rails::Configuration#reraise_global_exceptions`
51
+ - `InfluxDB::Rails::Configuration#database_name`
52
+ - `InfluxDB::Rails::Configuration#application_id`
53
+
54
+ [migrate]: https://gist.github.com/dmke/2d0f4ccf9f43faf82e732dc041e90ca2
55
+
56
+ ## v0.4.3, released 2017-12-12
57
+
58
+ - Added `time_precision` config option (#42, @kkentzo)
59
+
60
+ ## v0.4.2, released 2017-11-28
61
+
62
+ - Added `open_timeout`, `read_timeout`, and `max_delay` config options
63
+ (#41, @emaxi)
64
+ - Deprecate unused method (`#reraise_global_exceptions` in
65
+ `InfluxDB::Rails::Configuration`, #37, @vassilevsky)
66
+
67
+ ## v0.4.1, released 2017-10-23
68
+
69
+ - Bump `influx` version dependency (#40, @rockclimber73)
70
+
71
+ ## v0.4.0, released 2017-08-19
72
+
73
+ - Drop support for Rails 3, Ruby < 2.2
74
+ - Sync version with `influxdb` gem
75
+
76
+ ## v0.1.12, released 2017-06-06
77
+
78
+ - Added Rails 5.1 compatibility (#31, @djgould).
79
+ - Added `retry` config option (#17, @scambra and #18, @bcantin).
80
+
81
+ ## v0.1.11, released 2016-11-24
82
+
83
+ - Bumped `influxdb` Rubygem dependency (#28, #32, @agx).
84
+
85
+ **Note:** The real changelog starts here. Previous entries are reconstructed
86
+ from the commit history by correlating release version with Git tags, which
87
+ may or may not reflect what was really released.
88
+
89
+ ## v0.1.10, released 2014-10-08
90
+
91
+ - Lazy loading of `InfluxDB::Client` (#15, @chingo13).
92
+ - Various test fixes.
93
+
94
+ ## v0.1.9, released 2014-06-18
95
+
96
+ - v0.1.8 was yanked
97
+ - Initializer now allows multiple hosts.
98
+
99
+ ## v0.1.7, released 2014-04-09
100
+
101
+ - Added logger.
102
+
103
+ ## v0.1.6, released 2014-04-08
104
+
105
+ - No changes (?)
106
+
107
+ ## v0.1.5, released 2014-04-02
108
+
109
+ - No changes (?)
110
+
111
+ ## v0.1.4, released 2014-03-26
112
+
113
+ - Added docs
114
+ - Made `async` option default to `true`.
115
+
116
+ ## v0.1.3, released 2014-02-11
117
+
118
+ - Set series name defaults.
119
+ - Fixed a configuration bug.
120
+
121
+ ## v0.1.2, released 2014-02-11
122
+
123
+ - Graceful handling of authentication errors.
124
+ - Fixes in documentation.
125
+
126
+ ## v0.1.1, released 2014-02-06
127
+
128
+ - Refactoring of `ActiveSupport::Notification` handling.
129
+ - Added more initializer options.
130
+
131
+ ## v0.1.0, released 2014-02-06
132
+
133
+ - 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,292 @@
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 or fields per request, you can access ``InfluxDB::Rails.current`` to
120
+ do so. For instance, you could add the current user as tag and the request id to every data point.
121
+
122
+ ```ruby
123
+ class ApplicationController
124
+
125
+ before_action :set_influx_data
126
+
127
+ def set_influx_data
128
+ InfluxDB::Rails.current.tags = { user: current_user.id }
129
+ InfluxDB::Rails.current.values = { id: request.request_id }
130
+ end
131
+ end
132
+
133
+ ```
134
+
135
+ By default, the following tags are sent for *non-exception series*
136
+ (`rails.controller`, `rails.view`, `rails.db` and `instrumentation`):
137
+
138
+ ```ruby
139
+ {
140
+ method: "#{payload[:controller]}##{payload[:action]}",
141
+ server: Socket.gethostname,
142
+ app_name: configuration.application_name,
143
+ http_method: payload[:method],
144
+ format: payload[:format],
145
+ status: payload[:status]
146
+ }
147
+ ```
148
+ For the render series (``rails.render_partial``, ``rails.render_view`` and ``rails.render_collection``)
149
+
150
+ ```ruby
151
+ server: Socket.gethostname,
152
+ app_name: configuration.application_name,
153
+ location: "#{payload[:controller]}##{payload[:action]}",
154
+ filename: payload[:identifier],
155
+ count: payload[:count],
156
+ cache_hits: payload[:cache_hits],
157
+ ```
158
+
159
+ For the SQL series (``rails.sql``, disabled by default)
160
+
161
+ ```ruby
162
+ server: Socket.gethostname,
163
+ app_name: configuration.application_name,
164
+ location: "#{payload[:controller]}##{payload[:action]}",,
165
+ operation: "SELECT",
166
+ class_name: "USER",
167
+ name: payload[:name],
168
+ ```
169
+
170
+ 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).
171
+
172
+
173
+ For the exceptions (series name `rails.exceptions`):
174
+
175
+ ```ruby
176
+ {
177
+ application_name: InfluxDB::Rails.configuration.application_name,
178
+ application_root: InfluxDB::Rails.configuration.application_root,
179
+ framework: InfluxDB::Rails.configuration.framework,
180
+ framework_version: InfluxDB::Rails.configuration.framework_version,
181
+ language: "Ruby",
182
+ language_version: "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
183
+ custom_data: @custom_data,
184
+ class: @exception.class.to_s,
185
+ method: "#{@controller}##{@action}",
186
+ filename: File.basename(@backtrace.lines.first.try(:file)),
187
+ server: Socket.gethostname,
188
+ status: "open",
189
+ }
190
+ ```
191
+
192
+
193
+ ## Frequently Asked Questions
194
+
195
+
196
+ **Q: I'm seeing far less requests recorded in InfluxDB than my logs suggest.**
197
+
198
+ By default, this gem only sends data points with *second time precision*
199
+ to the InfluxDB server. If you experience multiple requests per second,
200
+ **only the last** point (with the same tag set) is stored.
201
+
202
+ See [InfluxDB server docs][duplicate-points] for further details.
203
+ To work around this limitation, set the `config.time_precision` to one
204
+ of `"ms"` (milliseconds, 1·10<sup>-3</sup>s), `"us"` (microseconds,
205
+ 1·10<sup>-6</sup>s) or `"ns"` (nanoseconds, 1·10<sup>-9</sup>s).
206
+
207
+ [duplicate-points]: https://docs.influxdata.com/influxdb/v1.4/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
208
+
209
+
210
+ **Q: How does the measurement influence the response time?**
211
+
212
+ This gem subscribes to the `process_action.action_controller` controller
213
+ notification (via `ActiveSupport::Notifications` · [guide][arn-guide] ·
214
+ [docs][arn-docs] · [impl][arn-impl]), i.e. it runs *after* a controller
215
+ action has finished.
216
+
217
+ The thread processing incoming HTTP requests however is blocked until
218
+ the notification is processed. By default, this means calculating and
219
+ enqueueing some data points for later processing (`config.async = true`),
220
+ which usually is negligible. The asynchronuous sending happens in a seperate
221
+ thread, which batches multiple data points.
222
+
223
+ If you, however, use a synchronous client (`config.async = false`), the
224
+ data points are immediately sent to the InfluxDB server. Depending on
225
+ the network link, this might cause the HTTP thread to block a lot longer.
226
+
227
+ [arn-guide]: http://guides.rubyonrails.org/v5.1/active_support_instrumentation.html#process-action-action-controller
228
+ [arn-docs]: http://api.rubyonrails.org/v5.1/classes/ActiveSupport/Notifications.html
229
+ [arn-impl]: https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_controller/metal/instrumentation.rb#L30-L38
230
+
231
+
232
+ **Q: How does this gem handle an unreachable InfluxDB server?**
233
+
234
+ By default, the InfluxDB client will retry indefinetly, until a write
235
+ succeedes (see [client docs][] for details). This has two important
236
+ implcations, depending on the value of `config.async`:
237
+
238
+ - if the client runs asynchronously (i.e. in a seperate thread), the queue
239
+ might fill up with hundrets of megabytes of data points
240
+ - if the client runs synchronously (i.e. inline in the request/response
241
+ cycle), it might block all available request threads
242
+
243
+ In both cases, your application server might become inresponsive and needs
244
+ to be restarted (which can happen automatically in `cgroups` contexts).
245
+
246
+ If you setup a maximum retry value (`Integer === config.retry`), the
247
+ client will try upto that amount of times to send the data to the server
248
+ and (on final error) log an error and discard the values.
249
+
250
+ [client docs]: https://github.com/influxdata/influxdb-ruby#retry
251
+
252
+
253
+ **Q: What happens with unwritten points, when the application restarts?**
254
+
255
+ The data points are simply discarded.
256
+
257
+
258
+ **Q: What happens, when the InfluxDB client or this gem throws an exception? Will the user see 500 errors?**
259
+
260
+ No. The controller instrumentation is wrapped in a `rescue StandardError`
261
+ clause, i.e. this gem will only write the error to the `client.logger`
262
+ (`Rails.logger` by default) and not disturb the user experience.
263
+
264
+
265
+ ## Testing
266
+
267
+ ```
268
+ git clone git@github.com:influxdata/influxdb-rails.git
269
+ cd influxdb-rails
270
+ bundle
271
+ bundle exec rake
272
+ ```
273
+
274
+
275
+ ## Contributing
276
+
277
+ - Fork this repository on GitHub.
278
+ - Make your changes.
279
+ - Add tests.
280
+ - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top.
281
+ - Run the tests:
282
+ - Either run them manually:
283
+ ```console
284
+ $ rake test:all
285
+ ```
286
+ - or wait for [Travis][travis-pr] to pick up your changes, *after*
287
+ you made a pull request.
288
+ - Send a pull request.
289
+ - Please rebase against the master branch.
290
+ - If your changes look good, we'll merge them.
291
+
292
+ [travis-pr]: https://travis-ci.org/influxdata/influxdb-rails/pull_requests