influxdb-rails 1.0.0.beta1 → 1.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.gitignore +2 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +7 -1
  6. data/.travis.yml +9 -10
  7. data/CHANGELOG.md +48 -11
  8. data/Gemfile +6 -0
  9. data/README.md +278 -100
  10. data/Rakefile +17 -18
  11. data/gemfiles/Gemfile.rails-5.0.x +2 -0
  12. data/gemfiles/Gemfile.rails-6.0.x +10 -0
  13. data/influxdb-rails.gemspec +20 -10
  14. data/lib/influxdb-rails.rb +35 -118
  15. data/lib/influxdb/rails/configuration.rb +99 -179
  16. data/lib/influxdb/rails/context.rb +26 -0
  17. data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
  18. data/lib/influxdb/rails/metric.rb +39 -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 +32 -0
  23. data/lib/influxdb/rails/middleware/request_subscriber.rb +44 -0
  24. data/lib/influxdb/rails/middleware/sql_subscriber.rb +37 -0
  25. data/lib/influxdb/rails/middleware/subscriber.rb +68 -0
  26. data/lib/influxdb/rails/railtie.rb +28 -25
  27. data/lib/influxdb/rails/sql/normalizer.rb +27 -0
  28. data/lib/influxdb/rails/sql/query.rb +32 -0
  29. data/lib/influxdb/rails/tags.rb +33 -0
  30. data/lib/influxdb/rails/test_client.rb +13 -0
  31. data/lib/influxdb/rails/values.rb +24 -0
  32. data/lib/influxdb/rails/version.rb +1 -1
  33. data/lib/rails/generators/influxdb/influxdb_generator.rb +1 -1
  34. data/lib/rails/generators/influxdb/templates/initializer.rb +39 -9
  35. data/sample-dashboard/Dockerfile +24 -0
  36. data/sample-dashboard/README.md +74 -0
  37. data/sample-dashboard/Rakefile +9 -0
  38. data/sample-dashboard/Ruby On Rails Performance (per Action).json +1576 -0
  39. data/sample-dashboard/Ruby On Rails Performance (per Request).json +1053 -0
  40. data/sample-dashboard/Ruby On Rails Performance.json +2041 -0
  41. data/sample-dashboard/docker-compose.yml +34 -0
  42. data/sample-dashboard/provisioning/grafana-dashboards.yml +12 -0
  43. data/sample-dashboard/provisioning/grafana-datasource.yml +10 -0
  44. data/sample-dashboard/provisioning/performance-action.json +1576 -0
  45. data/sample-dashboard/provisioning/performance-request.json +1053 -0
  46. data/sample-dashboard/provisioning/performance.json +2041 -0
  47. data/spec/requests/action_controller_metrics_spec.rb +83 -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_job_perform_start_metrics_spec.rb +68 -0
  54. data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
  55. data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
  56. data/spec/requests/block_inistrumentation_spec.rb +64 -0
  57. data/spec/requests/context_spec.rb +27 -0
  58. data/spec/requests/logger_spec.rb +10 -0
  59. data/spec/spec_helper.rb +12 -4
  60. data/spec/support/broken_client.rb +11 -0
  61. data/spec/support/rails5/app.rb +44 -5
  62. data/spec/support/rails6/app.rb +70 -0
  63. data/spec/support/views/metrics/_item.html.erb +1 -0
  64. data/spec/support/views/metrics/index.html.erb +5 -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 +64 -65
  68. data/spec/unit/sql/normalizer_spec.rb +15 -0
  69. data/spec/unit/sql/query_spec.rb +29 -0
  70. metadata +167 -44
  71. data/gemfiles/Gemfile.rails-4.2.x +0 -7
  72. data/lib/influxdb/rails/air_traffic_controller.rb +0 -41
  73. data/lib/influxdb/rails/backtrace.rb +0 -44
  74. data/lib/influxdb/rails/exception_presenter.rb +0 -94
  75. data/lib/influxdb/rails/instrumentation.rb +0 -34
  76. data/lib/influxdb/rails/logger.rb +0 -16
  77. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +0 -16
  78. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +0 -31
  79. data/lib/influxdb/rails/rack.rb +0 -24
  80. data/spec/controllers/widgets_controller_spec.rb +0 -15
  81. data/spec/integration/exceptions_spec.rb +0 -37
  82. data/spec/integration/integration_helper.rb +0 -1
  83. data/spec/integration/metrics_spec.rb +0 -21
  84. data/spec/support/rails4/app.rb +0 -30
  85. data/spec/unit/backtrace_spec.rb +0 -85
  86. data/spec/unit/exception_presenter_spec.rb +0 -23
  87. data/spec/unit/influxdb_rails_spec.rb +0 -164
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68333c3962daf87c05e1ff1b221accc5854e4c7d671f0d0441a5c789b2322cee
4
- data.tar.gz: 56017328de99c335fd4c590fe80c2d9de1b9132f39a7d3ac6d07b87b551597f9
3
+ metadata.gz: 0c7bbb899eeb093fce13f1997b9f99eeb4451ca059676cd7b23e44fc29058769
4
+ data.tar.gz: c05d83cb5fbbb99b1b8a34794a174e1c4a1d6193d4aa2560fa3dba22fa665da1
5
5
  SHA512:
6
- metadata.gz: e6c6087522e487aaefabe377698d2275270070c0e9d70eb7110fd90000f2160fc03b127879e39481ca0ff7f1f6bc5010075c4d9fe64bd30ecebd9b04b7e98df6
7
- data.tar.gz: baf2150e6140c85119da580cb89b06204a0372277c6adf7c57f15b89c214e41d80f05e0b47447df939eecc26dfb27115787750d92a22ae3ced38a047448f97bc
6
+ metadata.gz: c1681dc59869917c09f4da05beaa880565814a263df81567c33af9ab6b5b529d49e8c7dbf666a9758e998adf08f2f521b2fa4734b80845381b3672c824040450
7
+ data.tar.gz: 420b905817df05e25cda3a22dfa05bf32118e94104915a3aba212dc56f39396f1ff1aadf3261a2018b650b56f1431140829b6142a7324022fea8542413872697
@@ -0,0 +1,11 @@
1
+ version: 2
2
+ updates:
3
+ # Enable version updates for bundler
4
+ - package-ecosystem: "bundler"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "daily"
8
+ allow:
9
+ - dependency-type: "all"
10
+ labels:
11
+ - "dependencies"
data/.gitignore CHANGED
@@ -2,8 +2,10 @@
2
2
  .rvmrc
3
3
  *.gem
4
4
  Gemfile.lock
5
+ Gemfile.local
5
6
  gemfiles/*.lock
6
7
  pkg/*
7
8
  spec/support/rails*/log/*
8
9
  .ruby-*
9
10
  vendor/bundle
11
+ tmp
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format progress
2
2
  --color
3
+ --order rand
@@ -8,9 +8,10 @@ AllCops:
8
8
  - 'bin/**/*'
9
9
  - 'smoke/**/*'
10
10
  - 'Gemfile'
11
+ - 'vendor/bundle/**/*'
11
12
  DisplayCopNames: true
12
13
  StyleGuideCopsOnly: false
13
- TargetRubyVersion: 2.3
14
+ TargetRubyVersion: 2.4
14
15
 
15
16
  Rails:
16
17
  Enabled: false
@@ -31,6 +32,7 @@ Metrics/AbcSize:
31
32
  Metrics/BlockLength:
32
33
  Exclude:
33
34
  - 'spec/**/*.rb'
35
+ - 'influxdb-rails.gemspec'
34
36
 
35
37
  Metrics/LineLength:
36
38
  Max: 100
@@ -50,6 +52,10 @@ Naming/UncommunicativeMethodParamName:
50
52
  Naming/FileName:
51
53
  Exclude:
52
54
  - lib/influxdb-rails.rb
55
+ - sample-dashboard/Rakefile
56
+
57
+ Style/Documentation:
58
+ Enabled: false
53
59
 
54
60
  Style/FormatStringToken:
55
61
  Enabled: false
@@ -7,29 +7,28 @@ before_install:
7
7
  - gem update bundler --no-doc
8
8
  rvm:
9
9
  - ruby-head
10
- - 2.5.3
11
- - 2.4.5
12
- - 2.3.8
10
+ - "2.7"
11
+ - "2.6"
12
+ - "2.5"
13
+ - "2.4"
13
14
  gemfile:
15
+ - gemfiles/Gemfile.rails-6.0.x
14
16
  - gemfiles/Gemfile.rails-5.2.x
15
17
  - gemfiles/Gemfile.rails-5.1.x
16
18
  - gemfiles/Gemfile.rails-5.0.x
17
- - gemfiles/Gemfile.rails-4.2.x
18
19
  env:
19
20
  - TEST_TASK=spec
20
21
  matrix:
21
22
  allow_failures:
22
23
  - rvm: ruby-head
23
24
  include:
24
- - { rvm: "2.5.3", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
25
+ - { rvm: "2.6", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
25
26
  exclude:
26
- # 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" }
27
+ # Rails > 5 not on MRI 2.4+
28
+ - { rvm: "2.4", gemfile: "gemfiles/Gemfile.rails-6.0.x" }
30
29
  addons:
31
30
  apt:
32
31
  packages:
33
32
  - haveged
34
33
  - libgmp-dev
35
- script: bundle exec rake spec
34
+ script: bundle exec rake $TEST_TASK
@@ -2,6 +2,54 @@
2
2
 
3
3
  For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/master).
4
4
 
5
+ ## v1.0.1.beta1, released 2020-08-21
6
+ - Drop support for Ruby 2.3
7
+ - Drop support for Rails 4.x
8
+ - Add `auth_method` to client configuration (#96, @anlek)
9
+ - Drop undocumented `instrumentation_enabled` setting, use
10
+ `ignored_environments` do disable instrumentation
11
+ - Simplified spec with a PORO test client
12
+ - Implement `instantiation.active_record` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#instantiation-active-record)
13
+ - Implement `enqueue.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job)
14
+ - Implement `perform_start.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job)
15
+ - Implement `perform.active_job` subscriber (https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job)
16
+ - Implement block instrumentation `InfluxDB::Rails.instrument do; 1 + 1; end`
17
+ - Record unhandled exceptions as tags for process_action.action_controller
18
+
19
+ ## v1.0.0, released 2019-10-23
20
+ The Final release, no code changes.
21
+
22
+ ## v1.0.0.beta5, unreleased
23
+ - Silently eat all dropped configuration options and do not crash
24
+ - Add per action view to the sample dashboard
25
+
26
+ ## v1.0.0.beta4
27
+
28
+ - Introduces a Sample Grafana Dashboard + docker-compose demo (#75/#79, @hennevogel)
29
+ - Redesign Measurement Output (#66, @dmke, @ChrisBr, @hennevogel)
30
+ - Switching from emitting eight different measurements to one called `rails`
31
+ to support easier aggregation across data, to simplify configuration and to
32
+ stay closer to the InfluxDB/Grafana nomenclature.
33
+ - Introduced configuration option `ignored_hooks` to disable specifc hooks
34
+ - Enable SQL subscriber by default
35
+ - Set a default location (:raw) for SQL subscriber
36
+ - Add dynamic values (#65, @ChrisBr)
37
+ - Remove empty tags (#64, @ChrisBr)
38
+
39
+ ## v1.0.0.beta3, released 2019-01-07
40
+
41
+ - Add dynamic tags (#62, @ChrisBr)
42
+ - Reduce cardinality of resulting InfluxDB measurement by moving
43
+ some tags to values (#63, @ChrisBr)
44
+ - Remove SCHEMA queries from SQL instrumentation (#61, @ChrisBr)
45
+
46
+ ## v1.0.0.beta2, released 2018-12-07
47
+
48
+ - Added `tags_middleware` config option (#47, @Kukunin)
49
+ - Removed path tag from metrics (introduced with #50), because it
50
+ potentially produces "exceed tag value limit" (#54, @ChrisBr)
51
+ - Added render instrumentation (#53, @ChrisBr)
52
+ - Added SQL instrumentation (#55, @ChrisBr)
5
53
 
6
54
  ## v1.0.0.beta1, released 2018-11-22
7
55
 
@@ -15,22 +63,11 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-rails
15
63
 
16
64
  - Support for Ruby <= 2.2.x has been removed
17
65
  - 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
66
  - Removed previously deprecated methods:
28
67
  - `InfluxDB::Rails::Configuration#reraise_global_exceptions`
29
68
  - `InfluxDB::Rails::Configuration#database_name`
30
69
  - `InfluxDB::Rails::Configuration#application_id`
31
70
 
32
- [migrate]: https://gist.github.com/dmke/2d0f4ccf9f43faf82e732dc041e90ca2
33
-
34
71
  ## v0.4.3, released 2017-12-12
35
72
 
36
73
  - Added `time_precision` config option (#42, @kkentzo)
data/Gemfile CHANGED
@@ -1,3 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
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/README.md CHANGED
@@ -1,7 +1,6 @@
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.
1
+ > :warning: You are looking at the README for the master branch of this gem.
2
+ > See the latest [released version (1.0.0)](https://github.com/influxdata/influxdb-rails/tree/v1.0.0#readme)
3
+ > instead.
5
4
 
6
5
  # influxdb-rails
7
6
 
@@ -11,170 +10,349 @@
11
10
  Automatically instrument your Ruby on Rails applications and write the
12
11
  metrics directly into [InfluxDB](http://influxdb.org/).
13
12
 
14
- This gem is designed for Rails 4.0+, Ruby 2.2+ and InfluxDB 0.9+.
13
+ This gem is designed for Rails 4.2+, Ruby 2.3+ and InfluxDB 0.9+.
15
14
 
16
- ## Install
15
+ ## Table of contents
17
16
 
17
+ - [Installation](#installation)
18
+ - [Usage](#installation)
19
+ - [Configuration](#configuration)
20
+ - [Demo](#demo)
21
+ - [FAQ](#frequently-asked-questions)
22
+ - [Contributing](#contributing)
23
+
24
+ ## Installation
25
+
26
+ Add the gem to your `Gemfile`:
27
+
28
+ ```console
29
+ echo 'gem "influxdb-rails"' >>Gemfile
30
+ bundle install
18
31
  ```
19
- $ [sudo] gem install influxdb-rails
32
+
33
+ To get things set up, create an initializer:
34
+
35
+ ```console
36
+ bundle exec rails generate influxdb
20
37
  ```
21
38
 
22
- Or add it to your `Gemfile`, etc.
39
+ This creates a file `config/initializers/influxdb_rails.rb`, which allows
40
+ configuration of this gem.
23
41
 
24
42
  ## Usage
25
43
 
26
- To get things set up, just create an initializer:
44
+ Out of the box, you'll automatically get reporting for sql, model, view and
45
+ controller Rails instrumentation for every request.
46
+
47
+ ### Action Controller
48
+
49
+ Reported ActiveSupport instrumentation hooks:
50
+
51
+ - [start\_processing.action\_controller](https://guides.rubyonrails.org/active_support_instrumentation.html#start-processing-action-controller)
52
+ - [process\_action.action\_controller](https://guides.rubyonrails.org/active_support_instrumentation.html#process-action-action-controller)
53
+
54
+ Reported values:
55
+
56
+ ```ruby
57
+ controller: 48.467,
58
+ view: 46.848
59
+ db: 0.157,
60
+ started: 1465839830100400200
61
+ request_id: "d5bf620b-3494-425b-b7e1-4953597ea744"
62
+ ```
63
+
64
+ Reported tags:
65
+
66
+ ```ruby
67
+ {
68
+ hook: "process_action",
69
+ server: Socket.gethostname,
70
+ app_name: configuration.application_name,
71
+ method: "PostsController#index",
72
+ http_method: "GET",
73
+ format: "html",
74
+ status: ["200", ""]
75
+ exception: ["", "ArgumentError"]
76
+ }
77
+ ```
78
+
79
+ *Note*: If an exception happens during that particular instrumentation the
80
+ `status` will be blank and the tag `exception` will contain the name of the
81
+ exception class.
82
+
83
+ ### Action View
84
+
85
+ Reported ActiveSupport instrumentation hooks:
86
+
87
+ - [render\_template.action\_view](https://guides.rubyonrails.org/active_support_instrumentation.html#render-template-action-view)
88
+ - [render\_partial.action\_view](https://guides.rubyonrails.org/active_support_instrumentation.html#render-partial-action-view)
89
+ - [render\_collection.action\_view](https://guides.rubyonrails.org/active_support_instrumentation.html#render-collection-action-view)
90
+
91
+ Reported values:
92
+
93
+ ```ruby
94
+ value: 48.467,
95
+ count: 3,
96
+ cache_hits: 0,
97
+ request_id: "d5bf620b-3494-425b-b7e1-4953597ea744"
98
+ ```
99
+
100
+ Reported tags:
27
101
 
102
+ ```ruby
103
+ hook: ["render_template", "render_partial", "render_collection"]
104
+ server: Socket.gethostname,
105
+ app_name: configuration.application_name,
106
+ location: "PostsController#index",
107
+ filename: "/some/file/action.html",
28
108
  ```
29
- $ cd /to/you/rails/application
30
- $ touch config/initializers/influxdb_rails.rb
109
+
110
+ ### Active Record
111
+
112
+ Reported ActiveSupport instrumentation hooks:
113
+
114
+ - [sql.active\_record](https://guides.rubyonrails.org/active_support_instrumentation.html#sql-active-record)
115
+
116
+ Reported values:
117
+
118
+ ```ruby
119
+ sql: "SELECT \"posts\".* FROM \"posts\"",
120
+ request_id: "d5bf620b-3494-425b-b7e1-4953597ea744"
31
121
  ```
32
122
 
33
- In this file, you can configure the `InfluxDB::Rails` adapter. The default
34
- config should look something like this:
123
+ Reported tags:
35
124
 
36
- ``` ruby
125
+ ```ruby
126
+ hook: "sql",
127
+ server: Socket.gethostname,
128
+ app_name: configuration.application_name,
129
+ location: "PostsController#index",
130
+ operation: "SELECT",
131
+ class_name: "POST",
132
+ name: "Post Load"
133
+ ```
134
+
135
+ ## Configuration
136
+
137
+ The only setting you actually need to configure is the name of the database
138
+ within the InfluxDB server instance (don't forget to create this database!).
139
+
140
+ ```ruby
37
141
  InfluxDB::Rails.configure do |config|
38
- config.influxdb_database = "rails"
39
- config.influxdb_username = "root"
40
- config.influxdb_password = "root"
41
- config.influxdb_hosts = ["localhost"]
42
- config.influxdb_port = 8086
43
-
44
- # config.retry = false
45
- # config.async = false
46
- # config.open_timeout = 5
47
- # config.read_timeout = 30
48
- # config.max_delay = 300
49
- # config.time_precision = 'ms'
50
-
51
- # config.series_name_for_controller_runtimes = "rails.controller"
52
- # config.series_name_for_view_runtimes = "rails.view"
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
142
+ config.client.database = "rails"
60
143
  end
61
144
  ```
62
145
 
63
- To see all default values, take a look into `InfluxDB::Rails::Configuration::DEFAULTS`,
64
- defined in `lib/influxdb/rails/configuration.rb`
146
+ You'll find *most* of the configuration settings in the initializer file. The
147
+ canonical list of default values is located in `lib/influxdb/rails/configuration.rb`
148
+ (`InfluxDB::Rails::Configuration::DEFAULTS`).
149
+
150
+ ### Custom Tags
151
+
152
+ You can modify the tags sent to InfluxDB by defining a middleware, which
153
+ receives the current tag set as argument and returns a hash in the same
154
+ form. The middleware can be any object, as long it responds to `#call`
155
+ (like a `Proc`):
156
+
157
+ ```ruby
158
+ InfluxDB::Rails.configure do |config|
159
+ config.tags_middleware = lambda do |tags|
160
+ tags.merge(env: Rails.env)
161
+ end
162
+ end
163
+ ```
164
+
165
+ The `tags` argument is a Hash (mapping Symbol keys to String values). The
166
+ actual keys and values depend on the series name (`tags[:series]`, see
167
+ next section).
168
+
169
+ If you want to add dynamically tags or fields *per request*, you can access
170
+ `InfluxDB::Rails.current` to do so. For instance, you could add the current
171
+ user as tag or redis query time to every data point:
172
+
173
+ ```ruby
174
+ class ApplicationController
175
+ before_action :set_influx_data
176
+
177
+ def set_influx_data
178
+ InfluxDB::Rails.current.tags = { user: current_user.id }
179
+ InfluxDB::Rails.current.values = { redis_value: redis_value }
180
+ end
181
+ end
182
+ ```
65
183
 
66
- Out of the box, you'll automatically get reporting of your controller,
67
- view, and db runtimes for each request. You can also call through to the
68
- underlying `InfluxDB::Client` object to write arbitrary data like this:
184
+ ### Block Instrumentation
185
+ If you want to add custom instrumentation, you can wrap any code into a block instrumentation
69
186
 
70
- ``` ruby
187
+ ```ruby
188
+ InfluxDB::Rails.instrument "expensive_operation", tags: { }, values: { } do
189
+ expensive_operation
190
+ end
191
+ ```
192
+
193
+ Reported tags:
194
+
195
+ ```ruby
196
+ hook: "block_instrumentation"
197
+ server: Socket.gethostname,
198
+ app_name: configuration.application_name,
199
+ location: "PostsController#index",
200
+ name: "expensive_operation"
201
+ ```
202
+
203
+ Reported values:
204
+ ```ruby
205
+ value: 100 # execution time of the block
206
+ ```
207
+
208
+ You can also overwrite the `value`
209
+
210
+ ```ruby
211
+ InfluxDB::Rails.instrument "user_count", values: { value: 1 } do
212
+ User.create(name: 'mickey', surname: 'mouse')
213
+ end
214
+ ```
215
+
216
+ or call it even without a block
217
+
218
+ ```ruby
219
+ InfluxDB::Rails.instrument "temperature", values: { value: 25 }
220
+ ```
221
+
222
+ ### Custom client configuration
223
+
224
+ The settings named `config.client.*` are used to construct an `InfluxDB::Client`
225
+ instance, which is used internally to transmit the reporting data points
226
+ to your InfluxDB server. You can access this client as well, and perform
227
+ arbitrary operations on your data:
228
+
229
+ ```ruby
71
230
  InfluxDB::Rails.client.write_point "events",
72
- tags: { url: "/foo", user_id: current_user.id },
231
+ tags: { url: "/foo", user_id: current_user.id, location: InfluxDB::Rails.current.location },
73
232
  values: { value: 0 }
74
233
  ```
75
234
 
76
- Additional documentation for `InfluxDB::Client` lives in the
77
- [influxdb-ruby](http://github.com/influxdata/influxdb-ruby) repo.
235
+ If you do that, it might be useful to add the current context to these custom
236
+ data points which can get accessed with `InfluxDB::Rails.current.location`.
237
+
238
+ See [influxdb-ruby](http://github.com/influxdata/influxdb-ruby) for a
239
+ full list of configuration options and detailed usage.
240
+
241
+ ### Disabling hooks
242
+
243
+ If you are not interested in certain reports you can disable them in the configuration.
244
+
245
+ ```ruby
246
+ InfluxDB::Rails.configure do |config|
247
+ config.ignored_hooks = ['sql.active_record', 'render_template.action_view']
248
+ end
249
+ ```
250
+
251
+ ## Demo
252
+ Want to see this in action? Check out our [sample dashboard](https://github.com/influxdata/influxdb-rails/tree/master/sample-dashboard).
78
253
 
79
254
  ## Frequently Asked Questions
80
255
 
256
+ ### I'm seeing far less requests recorded in InfluxDB than my logs suggest.
81
257
 
82
- **Q: I'm seeing far less requests recorded in InfluxDB than my logs suggest.**
258
+ By default, this gem writes data points with *millisecond time precision*
259
+ to the InfluxDB server. If you have more than 1000 requests/second (and/or
260
+ multiple parallel requests), **only the last** data point (within the
261
+ same tag set) is stored. See [InfluxDB server docs][duplicate-points] for
262
+ further details.
83
263
 
84
- By default, this gem only sends data points with *second time precision*
85
- to the InfluxDB server. If you experience multiple requests per second,
86
- **only the last** point (with the same tag set) is stored.
264
+ To work around this limitation, set the `config.client.time_precision`
265
+ to one of `"us"` (microseconds, 1·10<sup>-6</sup>s) or `"ns"` (nanoseconds,
266
+ 1·10<sup>-9</sup>s).
87
267
 
88
- See [InfluxDB server docs][duplicate-points] for further details.
89
- To work around this limitation, set the `config.time_precision` to one
90
- of `"ms"` (milliseconds, 1·10<sup>-3</sup>s), `"us"` (microseconds,
91
- 1·10<sup>-6</sup>s) or `"ns"` (nanoseconds, 1·10<sup>-9</sup>s).
268
+ Please note: This will only ever reduce the likelihood of data points
269
+ overwriting each other, but not eliminate it completely.
92
270
 
93
271
  [duplicate-points]: https://docs.influxdata.com/influxdb/v1.4/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
94
272
 
95
273
 
96
- **Q: How does the measurement influence the response time?**
274
+ ### How does the measurement influence the response time?
275
+
276
+ This gem subscribes to various `ActiveSupport::Notifications` hooks.
277
+ (cf. [guide][arn-guide] · [docs][arn-docs] · [impl][arn-impl]). The
278
+ controller notifications are run *after* a controller action has finished,
279
+ and should not impact the response time.
97
280
 
98
- This gem subscribes to the `process_action.action_controller` controller
99
- notification (via `ActiveSupport::Notifications` · [guide][arn-guide] ·
100
- [docs][arn-docs] · [impl][arn-impl]), i.e. it runs *after* a controller
101
- action has finished.
281
+ Other notification hooks (rendering and SQL queries) run *inline* in the
282
+ request processing. The amount of overhead introduced should be negligible,
283
+ though. However reporting of SQL queries relies on Ruby string parsing which
284
+ might cause performance issues on traffic intensive applications. Disable it in
285
+ the configuration if you are not willing to tolerate this.
102
286
 
103
- The thread processing incoming HTTP requests however is blocked until
104
- the notification is processed. By default, this means calculating and
105
- enqueueing some data points for later processing (`config.async = true`),
106
- which usually is negligible. The asynchronuous sending happens in a seperate
107
- thread, which batches multiple data points.
287
+ By default, this gem performs writes to InfluxDB asynchronously. A single
288
+ hooks usually only performs some time delta calculations, and then enqueues
289
+ the data point into a worker queue (which is processed by a background
290
+ thread).
108
291
 
109
- If you, however, use a synchronous client (`config.async = false`), the
110
- data points are immediately sent to the InfluxDB server. Depending on
292
+ If you, however, use a synchronous client (`config.client.async = false`),
293
+ the data points are immediately sent to the InfluxDB server. Depending on
111
294
  the network link, this might cause the HTTP thread to block a lot longer.
112
295
 
113
296
  [arn-guide]: http://guides.rubyonrails.org/v5.1/active_support_instrumentation.html#process-action-action-controller
114
297
  [arn-docs]: http://api.rubyonrails.org/v5.1/classes/ActiveSupport/Notifications.html
115
298
  [arn-impl]: https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_controller/metal/instrumentation.rb#L30-L38
116
299
 
300
+ ### How does this gem handle an unreachable InfluxDB server?
117
301
 
118
- **Q: How does this gem handle an unreachable InfluxDB server?**
302
+ By default, the InfluxDB client will retry indefinitely, until a write
303
+ succeeds (see [client docs][] for details). This has two important
304
+ implications, depending on the value of `config.client.async`:
119
305
 
120
- By default, the InfluxDB client will retry indefinetly, until a write
121
- succeedes (see [client docs][] for details). This has two important
122
- implcations, depending on the value of `config.async`:
123
-
124
- - if the client runs asynchronously (i.e. in a seperate thread), the queue
125
- might fill up with hundrets of megabytes of data points
306
+ - if the client runs asynchronously (i.e. in a separate thread), the queue
307
+ might fill up with hundreds of megabytes of data points
126
308
  - if the client runs synchronously (i.e. inline in the request/response
127
309
  cycle), it might block all available request threads
128
310
 
129
- In both cases, your application server might become inresponsive and needs
130
- to be restarted (which can happen automatically in `cgroups` contexts).
311
+ In both cases, your application server might become unresponsive and needs
312
+ to be restarted (which can happen automatically in `cgroups` contexts,
313
+ like Docker containers).
131
314
 
132
- If you setup a maximum retry value (`Integer === config.retry`), the
133
- client will try upto that amount of times to send the data to the server
315
+ If you setup a maximum retry value (`Integer === config.client.retry`),
316
+ the client will try up to that amount of times to send the data to the server
134
317
  and (on final error) log an error and discard the values.
135
318
 
136
319
  [client docs]: https://github.com/influxdata/influxdb-ruby#retry
137
320
 
138
-
139
- **Q: What happens with unwritten points, when the application restarts?**
140
-
141
- The data points are simply discarded.
142
-
143
-
144
- **Q: What happens, when the InfluxDB client or this gem throws an exception? Will the user see 500 errors?**
321
+ ### What happens, when the InfluxDB client or this gem throws an exception? Will the user see 500 errors?
145
322
 
146
323
  No. The controller instrumentation is wrapped in a `rescue StandardError`
147
324
  clause, i.e. this gem will only write the error to the `client.logger`
148
325
  (`Rails.logger` by default) and not disturb the user experience.
149
326
 
327
+ ### What happens with unwritten points, when the application restarts?
150
328
 
151
- ## Testing
152
-
153
- ```
154
- git clone git@github.com:influxdata/influxdb-rails.git
155
- cd influxdb-rails
156
- bundle
157
- bundle exec rake
158
- ```
329
+ The data points are simply discarded.
159
330
 
160
331
  ## Contributing
161
332
 
162
- - Fork this repository on GitHub.
163
- - Make your changes.
333
+ - Fork this repository on GitHub
334
+ - Make your changes
164
335
  - Add tests.
165
336
  - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top.
166
337
  - Run the tests:
167
338
  - Either run them manually:
168
- ```sh
169
- for gemfile in gemfiles/Gemfile.rails-*.x; do \
170
- BUNDLE_GEMFILE=$gemfile bundle install --quiet; \
171
- BUNDLE_GEMFILE=$gemfile bundle exec rspec; \
172
- done
339
+
340
+ ```console
341
+ rake test:all
173
342
  ```
343
+
174
344
  - or wait for [Travis][travis-pr] to pick up your changes, *after*
175
345
  you made a pull request.
176
346
  - Send a pull request.
177
- - Please rebase against the master branch.
178
- - If your changes look good, we'll merge them.
347
+ - If your changes are looking good, we'll merge them.
179
348
 
180
349
  [travis-pr]: https://travis-ci.org/influxdata/influxdb-rails/pull_requests
350
+
351
+ ### Testing Tasks
352
+
353
+ ```console
354
+ rake # unit tests + Rubocop linting
355
+ rake spec # only unit tests
356
+ rake rubocop # only Rubocop linter
357
+ rake test:all # integration tests with various Rails version
358
+ ```