influxdb-rails 1.0.0.beta2 → 1.0.1.beta2

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