influxdb-rails 1.0.1.beta2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +18 -0
  3. data/.github/workflows/spec.yml +32 -0
  4. data/.rubocop.yml +36 -7
  5. data/CHANGELOG.md +22 -1
  6. data/README.md +43 -34
  7. data/gemfiles/Gemfile.rails-6.0.x +1 -2
  8. data/gemfiles/Gemfile.rails-6.1.x +9 -0
  9. data/influxdb-rails.gemspec +2 -2
  10. data/lib/influxdb/rails/middleware/active_job_subscriber.rb +11 -11
  11. data/lib/influxdb/rails/middleware/request_subscriber.rb +9 -1
  12. data/lib/influxdb/rails/railtie.rb +0 -1
  13. data/lib/influxdb/rails/sql/normalizer.rb +3 -3
  14. data/lib/influxdb/rails/tags.rb +2 -2
  15. data/lib/influxdb/rails/values.rb +1 -1
  16. data/lib/influxdb/rails/version.rb +1 -1
  17. data/lib/influxdb-rails.rb +1 -2
  18. data/lib/rails/generators/influxdb/templates/initializer.rb +4 -0
  19. data/sample-dashboard/Dockerfile +2 -2
  20. data/sample-dashboard/README.md +21 -28
  21. data/sample-dashboard/Rakefile +10 -5
  22. data/sample-dashboard/Ruby On Rails ActiveJob.json +600 -0
  23. data/sample-dashboard/{Ruby On Rails Performance (per Action).json → Ruby On Rails Performance per Action.json } +343 -589
  24. data/sample-dashboard/{Ruby On Rails Performance (per Request).json → Ruby On Rails Performance per Request.json } +361 -211
  25. data/sample-dashboard/Ruby On Rails Performance.json +1347 -1139
  26. data/sample-dashboard/Ruby On Rails Requests.json +834 -0
  27. data/sample-dashboard/Ruby On Rails Slowlog by Action.json +278 -0
  28. data/sample-dashboard/Ruby On Rails Slowlog by Request.json +277 -0
  29. data/sample-dashboard/Ruby On Rails Slowlog by SQL.json +328 -0
  30. data/sample-dashboard/docker-compose.yml +6 -1
  31. data/sample-dashboard/provisioning/activejob.json +600 -0
  32. data/sample-dashboard/provisioning/performance-action.json +334 -580
  33. data/sample-dashboard/provisioning/performance-request.json +355 -205
  34. data/sample-dashboard/provisioning/performance.json +1336 -1128
  35. data/sample-dashboard/provisioning/requests.json +834 -0
  36. data/sample-dashboard/provisioning/slowlog-action.json +278 -0
  37. data/sample-dashboard/provisioning/slowlog-requests.json +277 -0
  38. data/sample-dashboard/provisioning/slowlog-sql.json +328 -0
  39. data/spec/requests/action_controller_metrics_spec.rb +24 -10
  40. data/spec/requests/action_mailer_deliver_metrics_spec.rb +4 -11
  41. data/spec/requests/action_view_collection_metrics_spec.rb +7 -16
  42. data/spec/requests/action_view_partial_metrics_spec.rb +6 -15
  43. data/spec/requests/action_view_template_metrics_spec.rb +6 -15
  44. data/spec/requests/active_job_enqueue_metrics_spec.rb +6 -15
  45. data/spec/requests/active_job_perform_metrics_spec.rb +5 -11
  46. data/spec/requests/active_record_instantiation_metrics_spec.rb +7 -16
  47. data/spec/requests/active_record_sql_metrics_spec.rb +13 -29
  48. data/spec/requests/block_inistrumentation_spec.rb +8 -17
  49. data/spec/requests/context_spec.rb +1 -1
  50. data/spec/requests/logger_spec.rb +1 -1
  51. data/spec/spec_helper.rb +2 -1
  52. data/spec/support/rails5/app.rb +3 -4
  53. data/spec/support/rails6/app.rb +3 -4
  54. data/spec/unit/tags.rb +47 -0
  55. metadata +25 -14
  56. data/.travis.yml +0 -28
  57. data/spec/requests/active_job_perform_start_metrics_spec.rb +0 -68
@@ -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
+ }
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  RSpec.describe "ActionController metrics", type: :request do
4
4
  let(:tags_middleware) do
@@ -18,11 +18,27 @@ RSpec.describe "ActionController metrics", type: :request do
18
18
  expect_metric(
19
19
  name: "rails",
20
20
  tags: a_hash_including(
21
- method: "MetricsController#index",
21
+ hook: "process_action",
22
+ status: 200,
23
+ format: :html,
24
+ http_method: "GET"
25
+ ),
26
+ values: a_hash_including(
27
+ view: be_between(1, 500),
28
+ db: be_between(1, 500),
29
+ controller: be_between(1, 500)
30
+ )
31
+ )
32
+ end
33
+
34
+ it "writes default and custom tags" do
35
+ get "/metrics"
36
+
37
+ expect_metric(
38
+ name: "rails",
39
+ tags: a_hash_including(
22
40
  hook: "process_action",
23
- status: 200,
24
- format: :html,
25
- http_method: "GET",
41
+ location: "MetricsController#index",
26
42
  additional_tag: :value,
27
43
  server: Socket.gethostname,
28
44
  app_name: :app_name,
@@ -30,10 +46,7 @@ RSpec.describe "ActionController metrics", type: :request do
30
46
  ),
31
47
  values: a_hash_including(
32
48
  additional_value: :value,
33
- request_id: :request_id,
34
- view: be_between(1, 30),
35
- db: be_between(1, 30),
36
- controller: be_between(1, 30)
49
+ request_id: :request_id
37
50
  )
38
51
  )
39
52
  end
@@ -76,7 +89,8 @@ RSpec.describe "ActionController metrics", type: :request do
76
89
  tags: a_hash_including(
77
90
  method: "ExceptionsController#index",
78
91
  hook: "process_action",
79
- exception: "ZeroDivisionError"
92
+ exception: "ActiveRecord::RecordNotFound",
93
+ status: 404
80
94
  )
81
95
  )
82
96
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  RSpec.describe "ActionMailer deliver metrics", type: :request do
4
4
  let(:tags_middleware) do
@@ -18,18 +18,11 @@ RSpec.describe "ActionMailer deliver metrics", type: :request do
18
18
 
19
19
  expect_metric(
20
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
21
+ hook: "deliver",
22
+ mailer: "MetricMailer"
28
23
  ),
29
24
  values: a_hash_including(
30
- additional_value: :value,
31
- request_id: :request_id,
32
- value: 1
25
+ value: 1
33
26
  )
34
27
  )
35
28
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
2
 
3
3
  RSpec.describe "ActionView collection metrics", type: :request do
4
4
  let(:tags_middleware) do
@@ -18,19 +18,12 @@ RSpec.describe "ActionView collection metrics", type: :request do
18
18
  expect_metric(
19
19
  name: "rails",
20
20
  tags: a_hash_including(
21
- location: "MetricsController#index",
22
- hook: "render_collection",
23
- additional_tag: :value,
24
- filename: include("spec/support/views/metrics/_item.html.erb"),
25
- server: Socket.gethostname,
26
- app_name: :app_name,
27
- tags_middleware: :tags_middleware
21
+ hook: "render_collection",
22
+ filename: include("spec/support/views/metrics/_item.html.erb")
28
23
  ),
29
24
  values: a_hash_including(
30
- additional_value: :value,
31
- count: 3,
32
- request_id: :request_id,
33
- value: be_between(1, 30)
25
+ count: 3,
26
+ value: be_between(1, 500)
34
27
  )
35
28
  )
36
29
  end
@@ -43,8 +36,7 @@ RSpec.describe "ActionView collection metrics", type: :request do
43
36
  expect_metric(
44
37
  name: "rails",
45
38
  tags: a_hash_including(
46
- location: "MetricsController#index",
47
- hook: "render_collection"
39
+ hook: "render_collection"
48
40
  ),
49
41
  timestamp: 1_514_797_200
50
42
  )
@@ -58,8 +50,7 @@ RSpec.describe "ActionView collection metrics", type: :request do
58
50
  expect_no_metric(
59
51
  name: "rails",
60
52
  tags: a_hash_including(
61
- location: "MetricsController#index",
62
- hook: "render_collection"
53
+ hook: "render_collection"
63
54
  )
64
55
  )
65
56
  end