influxdb-rails 1.0.0.beta4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) 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 +32 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +35 -7
  7. data/CHANGELOG.md +40 -3
  8. data/README.md +125 -27
  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 +7 -4
  13. data/lib/influxdb-rails.rb +13 -2
  14. data/lib/influxdb/rails/configuration.rb +22 -13
  15. data/lib/influxdb/rails/context.rb +6 -40
  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 +15 -16
  23. data/lib/influxdb/rails/middleware/request_subscriber.rb +16 -21
  24. data/lib/influxdb/rails/middleware/sql_subscriber.rb +18 -18
  25. data/lib/influxdb/rails/middleware/subscriber.rb +40 -27
  26. data/lib/influxdb/rails/railtie.rb +15 -18
  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/templates/initializer.rb +4 -0
  33. data/sample-dashboard/Dockerfile +2 -3
  34. data/sample-dashboard/README.md +21 -28
  35. data/sample-dashboard/Rakefile +10 -4
  36. data/sample-dashboard/Ruby On Rails ActiveJob.json +600 -0
  37. data/sample-dashboard/Ruby On Rails Performance per Action.json +1330 -0
  38. data/sample-dashboard/{Ruby On Rails Performance (per Request).json → Ruby On Rails Performance per Request.json } +367 -217
  39. data/sample-dashboard/Ruby On Rails Performance.json +1348 -1110
  40. data/sample-dashboard/Ruby On Rails Requests.json +834 -0
  41. data/sample-dashboard/Ruby On Rails Slowlog by Action.json +278 -0
  42. data/sample-dashboard/Ruby On Rails Slowlog by Request.json +277 -0
  43. data/sample-dashboard/Ruby On Rails Slowlog by SQL.json +328 -0
  44. data/sample-dashboard/docker-compose.yml +7 -1
  45. data/sample-dashboard/provisioning/activejob.json +600 -0
  46. data/sample-dashboard/provisioning/performance-action.json +1330 -0
  47. data/sample-dashboard/provisioning/performance-request.json +361 -211
  48. data/sample-dashboard/provisioning/performance.json +1337 -1099
  49. data/sample-dashboard/provisioning/requests.json +834 -0
  50. data/sample-dashboard/provisioning/slowlog-action.json +278 -0
  51. data/sample-dashboard/provisioning/slowlog-requests.json +277 -0
  52. data/sample-dashboard/provisioning/slowlog-sql.json +328 -0
  53. data/spec/requests/action_controller_metrics_spec.rb +83 -0
  54. data/spec/requests/action_mailer_deliver_metrics_spec.rb +49 -0
  55. data/spec/requests/action_view_collection_metrics_spec.rb +66 -0
  56. data/spec/requests/action_view_partial_metrics_spec.rb +62 -0
  57. data/spec/requests/action_view_template_metrics_spec.rb +62 -0
  58. data/spec/requests/active_job_enqueue_metrics_spec.rb +65 -0
  59. data/spec/requests/active_job_perform_metrics_spec.rb +68 -0
  60. data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
  61. data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
  62. data/spec/requests/block_inistrumentation_spec.rb +64 -0
  63. data/spec/requests/context_spec.rb +27 -0
  64. data/spec/requests/logger_spec.rb +10 -0
  65. data/spec/spec_helper.rb +12 -4
  66. data/spec/support/broken_client.rb +11 -0
  67. data/spec/support/rails5/app.rb +48 -13
  68. data/spec/support/rails6/app.rb +83 -0
  69. data/spec/support/views/layouts/mailer.txt.erb +1 -0
  70. data/spec/support/views/{widgets → metrics}/_item.html.erb +0 -0
  71. data/spec/support/views/{widgets → metrics}/index.html.erb +0 -0
  72. data/spec/support/views/metrics/show.html.erb +4 -0
  73. data/spec/unit/block_instrumentation_spec.rb +18 -0
  74. metadata +124 -46
  75. data/.travis.yml +0 -37
  76. data/gemfiles/Gemfile.rails-4.2.x +0 -7
  77. data/gemfiles/Gemfile.rails-5.0.x +0 -7
  78. data/gemfiles/Gemfile.rails-5.1.x +0 -7
  79. data/lib/influxdb/rails/instrumentation.rb +0 -34
  80. data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -33
  81. data/spec/controllers/widgets_controller_spec.rb +0 -15
  82. data/spec/integration/integration_helper.rb +0 -1
  83. data/spec/integration/metrics_spec.rb +0 -27
  84. data/spec/shared_examples/data.rb +0 -61
  85. data/spec/support/rails4/app.rb +0 -48
  86. data/spec/unit/context_spec.rb +0 -40
  87. data/spec/unit/middleware/render_subscriber_spec.rb +0 -96
  88. data/spec/unit/middleware/request_subscriber_spec.rb +0 -103
  89. data/spec/unit/middleware/sql_subscriber_spec.rb +0 -108
@@ -0,0 +1,328 @@
1
+ {
2
+ "__inputs": [
3
+ {
4
+ "name": "DS_INFLUXDB-RAILS",
5
+ "label": "InfluxDB-Rails",
6
+ "description": "",
7
+ "type": "datasource",
8
+ "pluginId": "influxdb",
9
+ "pluginName": "InfluxDB"
10
+ }
11
+ ],
12
+ "__requires": [
13
+ {
14
+ "type": "grafana",
15
+ "id": "grafana",
16
+ "name": "Grafana",
17
+ "version": "7.1.1"
18
+ },
19
+ {
20
+ "type": "datasource",
21
+ "id": "influxdb",
22
+ "name": "InfluxDB",
23
+ "version": "1.0.0"
24
+ },
25
+ {
26
+ "type": "panel",
27
+ "id": "table-old",
28
+ "name": "Table (old)",
29
+ "version": ""
30
+ }
31
+ ],
32
+ "annotations": {
33
+ "list": [
34
+ {
35
+ "builtIn": 1,
36
+ "datasource": "-- Grafana --",
37
+ "enable": true,
38
+ "hide": true,
39
+ "iconColor": "rgba(0, 211, 255, 1)",
40
+ "name": "Annotations & Alerts",
41
+ "type": "dashboard"
42
+ }
43
+ ]
44
+ },
45
+ "description": "The sloweds queries in your app in the last hour",
46
+ "editable": true,
47
+ "gnetId": null,
48
+ "graphTooltip": 0,
49
+ "id": null,
50
+ "links": [
51
+ {
52
+ "$$hashKey": "object:40",
53
+ "icon": "external link",
54
+ "tags": [
55
+ "influxdb-rails"
56
+ ],
57
+ "type": "dashboards"
58
+ }
59
+ ],
60
+ "panels": [
61
+ {
62
+ "columns": [],
63
+ "datasource": "InfluxDB",
64
+ "description": "Data for the selected range by database query.\n\n- Count: Number of occurrences\n- Mean: Average time spent\n- Median: Median time spent\n- Maximum: Slowest occurrence\n\n[Average vs. Median?](https://www.differencebetween.com/difference-between-mean-and-median/)",
65
+ "fieldConfig": {
66
+ "defaults": {
67
+ "custom": {}
68
+ },
69
+ "overrides": []
70
+ },
71
+ "fontSize": "100%",
72
+ "gridPos": {
73
+ "h": 23,
74
+ "w": 24,
75
+ "x": 0,
76
+ "y": 0
77
+ },
78
+ "id": 2,
79
+ "links": [],
80
+ "pageSize": null,
81
+ "scroll": true,
82
+ "showHeader": true,
83
+ "sort": {
84
+ "col": 6,
85
+ "desc": true
86
+ },
87
+ "styles": [
88
+ {
89
+ "alias": "Time",
90
+ "align": "auto",
91
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
92
+ "pattern": "Time",
93
+ "type": "hidden"
94
+ },
95
+ {
96
+ "alias": "Count",
97
+ "align": "auto",
98
+ "colorMode": null,
99
+ "colors": [
100
+ "rgba(245, 54, 54, 0.9)",
101
+ "rgba(237, 129, 40, 0.89)",
102
+ "rgba(50, 172, 45, 0.97)"
103
+ ],
104
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
105
+ "decimals": null,
106
+ "mappingType": 1,
107
+ "pattern": "count",
108
+ "thresholds": [],
109
+ "type": "number",
110
+ "unit": "short"
111
+ },
112
+ {
113
+ "alias": "Mean",
114
+ "align": "auto",
115
+ "colorMode": null,
116
+ "colors": [
117
+ "rgba(245, 54, 54, 0.9)",
118
+ "rgba(237, 129, 40, 0.89)",
119
+ "rgba(50, 172, 45, 0.97)"
120
+ ],
121
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
122
+ "decimals": 2,
123
+ "mappingType": 1,
124
+ "pattern": "mean",
125
+ "thresholds": [],
126
+ "type": "number",
127
+ "unit": "ms"
128
+ },
129
+ {
130
+ "alias": "Median",
131
+ "align": "auto",
132
+ "colorMode": null,
133
+ "colors": [
134
+ "rgba(245, 54, 54, 0.9)",
135
+ "rgba(237, 129, 40, 0.89)",
136
+ "rgba(50, 172, 45, 0.97)"
137
+ ],
138
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
139
+ "decimals": 2,
140
+ "mappingType": 1,
141
+ "pattern": "median",
142
+ "thresholds": [],
143
+ "type": "number",
144
+ "unit": "ms"
145
+ },
146
+ {
147
+ "alias": "Controller Action",
148
+ "align": "auto",
149
+ "colorMode": null,
150
+ "colors": [
151
+ "rgba(245, 54, 54, 0.9)",
152
+ "rgba(237, 129, 40, 0.89)",
153
+ "rgba(50, 172, 45, 0.97)"
154
+ ],
155
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
156
+ "decimals": 2,
157
+ "link": true,
158
+ "linkTargetBlank": true,
159
+ "linkTooltip": "View data per this Controller Action",
160
+ "linkUrl": "/d/influxdb-rails-action/ruby-on-rails-performance-per-action?var-Action=${__cell}&from=$__from&to=$__to",
161
+ "mappingType": 1,
162
+ "pattern": "location",
163
+ "thresholds": [],
164
+ "type": "string",
165
+ "unit": "short"
166
+ },
167
+ {
168
+ "alias": "Name of the operation",
169
+ "align": "auto",
170
+ "colorMode": null,
171
+ "colors": [
172
+ "rgba(245, 54, 54, 0.9)",
173
+ "rgba(237, 129, 40, 0.89)",
174
+ "rgba(50, 172, 45, 0.97)"
175
+ ],
176
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
177
+ "decimals": 2,
178
+ "mappingType": 1,
179
+ "pattern": "name",
180
+ "thresholds": [],
181
+ "type": "string",
182
+ "unit": "short",
183
+ "valueMaps": [
184
+ {
185
+ "text": "Raw",
186
+ "value": ""
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ "alias": "Maximum",
192
+ "align": "auto",
193
+ "colorMode": "value",
194
+ "colors": [
195
+ "rgba(50, 172, 45, 0.97)",
196
+ "rgba(237, 129, 40, 0.89)",
197
+ "rgba(245, 54, 54, 0.9)"
198
+ ],
199
+ "dateFormat": "YYYY-MM-DD HH:mm:ss",
200
+ "decimals": 2,
201
+ "mappingType": 1,
202
+ "pattern": "max",
203
+ "thresholds": [
204
+ "3000",
205
+ "5000"
206
+ ],
207
+ "type": "number",
208
+ "unit": "ms"
209
+ }
210
+ ],
211
+ "targets": [
212
+ {
213
+ "groupBy": [
214
+ {
215
+ "params": [
216
+ "name"
217
+ ],
218
+ "type": "tag"
219
+ },
220
+ {
221
+ "params": [
222
+ "location"
223
+ ],
224
+ "type": "tag"
225
+ }
226
+ ],
227
+ "measurement": "rails",
228
+ "orderByTime": "ASC",
229
+ "policy": "default",
230
+ "refId": "A",
231
+ "resultFormat": "table",
232
+ "select": [
233
+ [
234
+ {
235
+ "params": [
236
+ "value"
237
+ ],
238
+ "type": "field"
239
+ },
240
+ {
241
+ "params": [],
242
+ "type": "count"
243
+ }
244
+ ],
245
+ [
246
+ {
247
+ "params": [
248
+ "value"
249
+ ],
250
+ "type": "field"
251
+ },
252
+ {
253
+ "params": [],
254
+ "type": "mean"
255
+ }
256
+ ],
257
+ [
258
+ {
259
+ "params": [
260
+ "value"
261
+ ],
262
+ "type": "field"
263
+ },
264
+ {
265
+ "params": [],
266
+ "type": "median"
267
+ }
268
+ ],
269
+ [
270
+ {
271
+ "params": [
272
+ "value"
273
+ ],
274
+ "type": "field"
275
+ },
276
+ {
277
+ "params": [],
278
+ "type": "max"
279
+ }
280
+ ]
281
+ ],
282
+ "tags": [
283
+ {
284
+ "key": "hook",
285
+ "operator": "=",
286
+ "value": "sql"
287
+ }
288
+ ]
289
+ }
290
+ ],
291
+ "title": "Slowest Database Query",
292
+ "transform": "table",
293
+ "type": "table-old"
294
+ }
295
+ ],
296
+ "schemaVersion": 26,
297
+ "style": "dark",
298
+ "tags": [
299
+ "Performance",
300
+ "Ruby on Rails",
301
+ "influxdb-rails"
302
+ ],
303
+ "templating": {
304
+ "list": []
305
+ },
306
+ "time": {
307
+ "from": "now-1h",
308
+ "to": "now"
309
+ },
310
+ "timepicker": {
311
+ "hidden": false,
312
+ "refresh_intervals": [
313
+ "10s",
314
+ "30s",
315
+ "1m",
316
+ "5m",
317
+ "15m",
318
+ "30m",
319
+ "1h",
320
+ "2h",
321
+ "1d"
322
+ ]
323
+ },
324
+ "timezone": "",
325
+ "title": "Slowlog by SQL Query",
326
+ "uid": "influxdb-rails-slowlog-sql",
327
+ "version": 14
328
+ }
@@ -0,0 +1,83 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ RSpec.describe "ActionController metrics", type: :request do
4
+ let(:tags_middleware) do
5
+ lambda do |tags|
6
+ tags.merge(tags_middleware: :tags_middleware)
7
+ end
8
+ end
9
+ before do
10
+ allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
11
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name)
12
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware)
13
+ end
14
+
15
+ it "writes metric" do
16
+ get "/metrics"
17
+
18
+ expect_metric(
19
+ name: "rails",
20
+ tags: a_hash_including(
21
+ method: "MetricsController#index",
22
+ hook: "process_action",
23
+ status: 200,
24
+ format: :html,
25
+ http_method: "GET",
26
+ additional_tag: :value,
27
+ server: Socket.gethostname,
28
+ app_name: :app_name,
29
+ tags_middleware: :tags_middleware
30
+ ),
31
+ values: a_hash_including(
32
+ additional_value: :value,
33
+ request_id: :request_id,
34
+ view: be_between(1, 500),
35
+ db: be_between(1, 500),
36
+ controller: be_between(1, 500)
37
+ )
38
+ )
39
+ end
40
+
41
+ it "includes correct timestamps" do
42
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
43
+
44
+ get "/metrics"
45
+
46
+ expect_metric(
47
+ name: "rails",
48
+ tags: a_hash_including(
49
+ method: "MetricsController#index",
50
+ hook: "process_action"
51
+ ),
52
+ values: a_hash_including(
53
+ started: 1_514_797_200
54
+ ),
55
+ timestamp: 1_514_797_200
56
+ )
57
+ end
58
+
59
+ it "does not write metric when hook is ignored" do
60
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["process_action.action_controller"])
61
+
62
+ get "/metrics"
63
+
64
+ expect_no_metric(
65
+ tags: a_hash_including(
66
+ method: "MetricsController#index",
67
+ hook: "process_action"
68
+ )
69
+ )
70
+ end
71
+
72
+ it "does not crash when controller throws and exception" do
73
+ get "/exceptions"
74
+
75
+ expect_metric(
76
+ tags: a_hash_including(
77
+ method: "ExceptionsController#index",
78
+ hook: "process_action",
79
+ exception: "ZeroDivisionError"
80
+ )
81
+ )
82
+ end
83
+ end
@@ -0,0 +1,49 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ RSpec.describe "ActionMailer deliver metrics", type: :request do
4
+ let(:tags_middleware) do
5
+ lambda do |tags|
6
+ tags.merge(tags_middleware: :tags_middleware)
7
+ end
8
+ end
9
+ before do
10
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development])
11
+ allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
12
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name)
13
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware)
14
+ end
15
+
16
+ it "writes metric" do
17
+ get "/metrics"
18
+
19
+ expect_metric(
20
+ tags: a_hash_including(
21
+ hook: "deliver",
22
+ mailer: "MetricMailer",
23
+ location: "MetricsController#index",
24
+ additional_tag: :value,
25
+ server: Socket.gethostname,
26
+ app_name: :app_name,
27
+ tags_middleware: :tags_middleware
28
+ ),
29
+ values: a_hash_including(
30
+ additional_value: :value,
31
+ request_id: :request_id,
32
+ value: 1
33
+ )
34
+ )
35
+ end
36
+
37
+ it "does not write metric when hook is ignored" do
38
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["deliver.action_mailer"])
39
+
40
+ get "/metrics"
41
+
42
+ expect_no_metric(
43
+ tags: a_hash_including(
44
+ hook: "deliver",
45
+ mailer: "MetricMailer"
46
+ )
47
+ )
48
+ end
49
+ end