influxdb-rails 1.0.0.beta1 → 1.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.gitignore +2 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +7 -1
  6. data/.travis.yml +9 -10
  7. data/CHANGELOG.md +48 -11
  8. data/Gemfile +6 -0
  9. data/README.md +278 -100
  10. data/Rakefile +17 -18
  11. data/gemfiles/Gemfile.rails-5.0.x +2 -0
  12. data/gemfiles/Gemfile.rails-6.0.x +10 -0
  13. data/influxdb-rails.gemspec +20 -10
  14. data/lib/influxdb-rails.rb +35 -118
  15. data/lib/influxdb/rails/configuration.rb +99 -179
  16. data/lib/influxdb/rails/context.rb +26 -0
  17. data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
  18. data/lib/influxdb/rails/metric.rb +39 -0
  19. data/lib/influxdb/rails/middleware/active_job_subscriber.rb +67 -0
  20. data/lib/influxdb/rails/middleware/active_record_subscriber.rb +26 -0
  21. data/lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb +24 -0
  22. data/lib/influxdb/rails/middleware/render_subscriber.rb +32 -0
  23. data/lib/influxdb/rails/middleware/request_subscriber.rb +44 -0
  24. data/lib/influxdb/rails/middleware/sql_subscriber.rb +37 -0
  25. data/lib/influxdb/rails/middleware/subscriber.rb +68 -0
  26. data/lib/influxdb/rails/railtie.rb +28 -25
  27. data/lib/influxdb/rails/sql/normalizer.rb +27 -0
  28. data/lib/influxdb/rails/sql/query.rb +32 -0
  29. data/lib/influxdb/rails/tags.rb +33 -0
  30. data/lib/influxdb/rails/test_client.rb +13 -0
  31. data/lib/influxdb/rails/values.rb +24 -0
  32. data/lib/influxdb/rails/version.rb +1 -1
  33. data/lib/rails/generators/influxdb/influxdb_generator.rb +1 -1
  34. data/lib/rails/generators/influxdb/templates/initializer.rb +39 -9
  35. data/sample-dashboard/Dockerfile +24 -0
  36. data/sample-dashboard/README.md +74 -0
  37. data/sample-dashboard/Rakefile +9 -0
  38. data/sample-dashboard/Ruby On Rails Performance (per Action).json +1576 -0
  39. data/sample-dashboard/Ruby On Rails Performance (per Request).json +1053 -0
  40. data/sample-dashboard/Ruby On Rails Performance.json +2041 -0
  41. data/sample-dashboard/docker-compose.yml +34 -0
  42. data/sample-dashboard/provisioning/grafana-dashboards.yml +12 -0
  43. data/sample-dashboard/provisioning/grafana-datasource.yml +10 -0
  44. data/sample-dashboard/provisioning/performance-action.json +1576 -0
  45. data/sample-dashboard/provisioning/performance-request.json +1053 -0
  46. data/sample-dashboard/provisioning/performance.json +2041 -0
  47. data/spec/requests/action_controller_metrics_spec.rb +83 -0
  48. data/spec/requests/action_view_collection_metrics_spec.rb +66 -0
  49. data/spec/requests/action_view_partial_metrics_spec.rb +62 -0
  50. data/spec/requests/action_view_template_metrics_spec.rb +62 -0
  51. data/spec/requests/active_job_enqueue_metrics_spec.rb +65 -0
  52. data/spec/requests/active_job_perform_metrics_spec.rb +68 -0
  53. data/spec/requests/active_job_perform_start_metrics_spec.rb +68 -0
  54. data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
  55. data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
  56. data/spec/requests/block_inistrumentation_spec.rb +64 -0
  57. data/spec/requests/context_spec.rb +27 -0
  58. data/spec/requests/logger_spec.rb +10 -0
  59. data/spec/spec_helper.rb +12 -4
  60. data/spec/support/broken_client.rb +11 -0
  61. data/spec/support/rails5/app.rb +44 -5
  62. data/spec/support/rails6/app.rb +70 -0
  63. data/spec/support/views/metrics/_item.html.erb +1 -0
  64. data/spec/support/views/metrics/index.html.erb +5 -0
  65. data/spec/support/views/metrics/show.html.erb +4 -0
  66. data/spec/unit/block_instrumentation_spec.rb +18 -0
  67. data/spec/unit/configuration_spec.rb +64 -65
  68. data/spec/unit/sql/normalizer_spec.rb +15 -0
  69. data/spec/unit/sql/query_spec.rb +29 -0
  70. metadata +167 -44
  71. data/gemfiles/Gemfile.rails-4.2.x +0 -7
  72. data/lib/influxdb/rails/air_traffic_controller.rb +0 -41
  73. data/lib/influxdb/rails/backtrace.rb +0 -44
  74. data/lib/influxdb/rails/exception_presenter.rb +0 -94
  75. data/lib/influxdb/rails/instrumentation.rb +0 -34
  76. data/lib/influxdb/rails/logger.rb +0 -16
  77. data/lib/influxdb/rails/middleware/hijack_render_exception.rb +0 -16
  78. data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +0 -31
  79. data/lib/influxdb/rails/rack.rb +0 -24
  80. data/spec/controllers/widgets_controller_spec.rb +0 -15
  81. data/spec/integration/exceptions_spec.rb +0 -37
  82. data/spec/integration/integration_helper.rb +0 -1
  83. data/spec/integration/metrics_spec.rb +0 -21
  84. data/spec/support/rails4/app.rb +0 -30
  85. data/spec/unit/backtrace_spec.rb +0 -85
  86. data/spec/unit/exception_presenter_spec.rb +0 -23
  87. data/spec/unit/influxdb_rails_spec.rb +0 -164
@@ -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, 30),
35
+ db: be_between(1, 30),
36
+ controller: be_between(1, 30)
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,66 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActionView collection 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
+ 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
28
+ ),
29
+ values: a_hash_including(
30
+ additional_value: :value,
31
+ count: 3,
32
+ request_id: :request_id,
33
+ value: be_between(1, 30)
34
+ )
35
+ )
36
+ end
37
+
38
+ it "includes correct timestamps" do
39
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
40
+
41
+ get "/metrics"
42
+
43
+ expect_metric(
44
+ name: "rails",
45
+ tags: a_hash_including(
46
+ location: "MetricsController#index",
47
+ hook: "render_collection"
48
+ ),
49
+ timestamp: 1_514_797_200
50
+ )
51
+ end
52
+
53
+ it "does not write metric when hook is ignored" do
54
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_collection.action_view"])
55
+
56
+ get "/metrics"
57
+
58
+ expect_no_metric(
59
+ name: "rails",
60
+ tags: a_hash_including(
61
+ location: "MetricsController#index",
62
+ hook: "render_collection"
63
+ )
64
+ )
65
+ end
66
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActionView partial 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
+ tags: a_hash_including(
20
+ location: "MetricsController#index",
21
+ hook: "render_partial",
22
+ additional_tag: :value,
23
+ filename: include("spec/support/views/metrics/_item.html.erb"),
24
+ server: Socket.gethostname,
25
+ app_name: :app_name,
26
+ tags_middleware: :tags_middleware
27
+ ),
28
+ values: a_hash_including(
29
+ additional_value: :value,
30
+ request_id: :request_id,
31
+ value: be_between(1, 30)
32
+ )
33
+ )
34
+ end
35
+
36
+ it "includes correct timestamps" do
37
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
38
+
39
+ get "/metrics"
40
+
41
+ expect_metric(
42
+ tags: a_hash_including(
43
+ location: "MetricsController#index",
44
+ hook: "render_partial"
45
+ ),
46
+ timestamp: 1_514_797_200
47
+ )
48
+ end
49
+
50
+ it "does not write metric when hook is ignored" do
51
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_partial.action_view"])
52
+
53
+ get "/metrics"
54
+
55
+ expect_no_metric(
56
+ tags: a_hash_including(
57
+ location: "MetricsController#index",
58
+ hook: "render_partial"
59
+ )
60
+ )
61
+ end
62
+ end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActionView template 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
+ tags: a_hash_including(
20
+ location: "MetricsController#index",
21
+ hook: "render_template",
22
+ additional_tag: :value,
23
+ filename: include("spec/support/views/metrics/index.html.erb"),
24
+ server: Socket.gethostname,
25
+ app_name: :app_name,
26
+ tags_middleware: :tags_middleware
27
+ ),
28
+ values: a_hash_including(
29
+ additional_value: :value,
30
+ request_id: :request_id,
31
+ value: be_between(1, 30)
32
+ )
33
+ )
34
+ end
35
+
36
+ it "includes correct timestamps" do
37
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
38
+
39
+ get "/metrics"
40
+
41
+ expect_metric(
42
+ tags: a_hash_including(
43
+ location: "MetricsController#index",
44
+ hook: "render_template"
45
+ ),
46
+ timestamp: 1_514_797_200
47
+ )
48
+ end
49
+
50
+ it "does not write metric when hook is ignored" do
51
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_template.action_view"])
52
+
53
+ get "/metrics"
54
+
55
+ expect_no_metric(
56
+ tags: a_hash_including(
57
+ location: "MetricsController#index",
58
+ hook: "render_template"
59
+ )
60
+ )
61
+ end
62
+ end
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActiveJob enqueue 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
+ location: "MetricsController#index",
22
+ hook: "enqueue",
23
+ job: "MetricJob",
24
+ queue: "default",
25
+ state: "queued",
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
+ value: 1
35
+ )
36
+ )
37
+ end
38
+
39
+ it "includes correct timestamps" do
40
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
41
+
42
+ get "/metrics"
43
+
44
+ expect_metric(
45
+ tags: a_hash_including(
46
+ location: "MetricsController#index",
47
+ hook: "enqueue"
48
+ ),
49
+ timestamp: 1_514_797_200
50
+ )
51
+ end
52
+
53
+ it "does not write metric when hook is ignored" do
54
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["enqueue.active_job"])
55
+
56
+ get "/metrics"
57
+
58
+ expect_no_metric(
59
+ tags: a_hash_including(
60
+ location: "MetricsController#index",
61
+ hook: "enqueue"
62
+ )
63
+ )
64
+ end
65
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActiveJobs perform 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
+ perform_enqueued_jobs do
18
+ get "/metrics"
19
+ end
20
+
21
+ expect_metric(
22
+ tags: a_hash_including(
23
+ location: "MetricsController#index",
24
+ hook: "perform",
25
+ state: "succeeded",
26
+ job: "MetricJob",
27
+ queue: "default",
28
+ server: Socket.gethostname,
29
+ app_name: :app_name,
30
+ tags_middleware: :tags_middleware
31
+ ),
32
+ values: a_hash_including(
33
+ value: be_between(0, 30)
34
+ )
35
+ )
36
+ end
37
+
38
+ it "includes correct timestamps" do
39
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
40
+
41
+ perform_enqueued_jobs do
42
+ get "/metrics"
43
+ end
44
+
45
+ expect_metric(
46
+ tags: a_hash_including(
47
+ location: "MetricsController#index",
48
+ hook: "perform"
49
+ ),
50
+ timestamp: 1_514_797_200
51
+ )
52
+ end
53
+
54
+ it "does not write metric when hook is ignored" do
55
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["perform.active_job"])
56
+
57
+ perform_enqueued_jobs do
58
+ get "/metrics"
59
+ end
60
+
61
+ expect_no_metric(
62
+ tags: a_hash_including(
63
+ location: "MetricsController#index",
64
+ hook: "perform"
65
+ )
66
+ )
67
+ end
68
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper"
2
+
3
+ RSpec.describe "ActiveJob start 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
+ perform_enqueued_jobs do
18
+ get "/metrics"
19
+ end
20
+
21
+ expect_metric(
22
+ tags: a_hash_including(
23
+ location: "MetricsController#index",
24
+ hook: "perform_start",
25
+ state: "running",
26
+ job: "MetricJob",
27
+ queue: "default",
28
+ server: Socket.gethostname,
29
+ app_name: :app_name,
30
+ tags_middleware: :tags_middleware
31
+ ),
32
+ values: a_hash_including(
33
+ value: 1
34
+ )
35
+ )
36
+ end
37
+
38
+ it "includes correct timestamps" do
39
+ travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
40
+
41
+ perform_enqueued_jobs do
42
+ get "/metrics"
43
+ end
44
+
45
+ expect_metric(
46
+ tags: a_hash_including(
47
+ location: "MetricsController#index",
48
+ hook: "perform_start"
49
+ ),
50
+ timestamp: 1_514_797_200
51
+ )
52
+ end
53
+
54
+ it "does not write metric when hook is ignored" do
55
+ allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["perform_start.active_job"])
56
+
57
+ perform_enqueued_jobs do
58
+ get "/metrics"
59
+ end
60
+
61
+ expect_no_metric(
62
+ tags: a_hash_including(
63
+ location: "MetricsController#index",
64
+ hook: "perform_start"
65
+ )
66
+ )
67
+ end
68
+ end