influxdb-rails 1.0.0.beta3 → 1.0.1.beta3

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