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
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe InfluxDB::Rails::ExceptionPresenter do
4
- before do
5
- begin
6
- 1 / 0
7
- rescue ZeroDivisionError => e
8
- @exception = e
9
- end
10
- end
11
-
12
- describe ".new" do
13
- it "should create a new ExceptionPresenter" do
14
- exception_presenter = InfluxDB::Rails::ExceptionPresenter.new(@exception)
15
- expect(exception_presenter).to be_a(InfluxDB::Rails::ExceptionPresenter)
16
- end
17
-
18
- it "should accept an exception as a parameter" do
19
- exception_presenter = InfluxDB::Rails::ExceptionPresenter.new(@exception)
20
- expect(exception_presenter).not_to be_nil
21
- end
22
- end
23
- end
@@ -1,164 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe InfluxDB::Rails do
4
- before do
5
- InfluxDB::Rails.configure do |config|
6
- config.application_name = "my-rails-app"
7
- config.ignored_environments = []
8
- config.time_precision = "ms"
9
- end
10
- end
11
-
12
- describe ".handle_action_controller_metrics" do
13
- let(:start) { Time.at(1_517_567_368) }
14
- let(:finish) { Time.at(1_517_567_370) }
15
- let(:payload) { { view_runtime: 2, db_runtime: 2, controller: "MyController", action: "show", method: "GET", format: "*/*", path: "/posts", status: 200 } }
16
- let(:data) do
17
- {
18
- values: {
19
- value: 2
20
- },
21
- tags: {
22
- method: "MyController#show",
23
- status: 200,
24
- format: "*/*",
25
- http_method: "GET",
26
- path: "/posts",
27
- server: Socket.gethostname,
28
- app_name: "my-rails-app",
29
- },
30
- timestamp: 1_517_567_370_000
31
- }
32
- end
33
-
34
- context "application_name is set" do
35
- it "sends metrics with taggings and timestamps" do
36
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
37
- "rails.controller", data.merge(values: { value: 2000 })
38
- )
39
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.view", data)
40
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.db", data)
41
-
42
- described_class.handle_action_controller_metrics("unused", start, finish, "unused", payload)
43
- end
44
- end
45
-
46
- context "application_name is nil" do
47
- before do
48
- InfluxDB::Rails.configure do |config|
49
- config.application_name = nil
50
- end
51
- end
52
-
53
- it "does not add the app_name tag to metrics" do
54
- tags = {
55
- method: "MyController#show",
56
- status: 200,
57
- format: "*/*",
58
- http_method: "GET",
59
- path: "/posts",
60
- server: Socket.gethostname,
61
- }
62
-
63
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
64
- "rails.controller", data.merge(values: { value: 2000 }, tags: tags)
65
- )
66
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.view", data.merge(tags: tags))
67
- expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with("rails.db", data.merge(tags: tags))
68
-
69
- described_class.handle_action_controller_metrics("unused", start, finish, "unused", payload)
70
- end
71
- end
72
- end
73
-
74
- describe ".convert_timestamp" do
75
- let(:sometime) { Time.parse("2017-12-11 16:20:29.111222333 UTC") }
76
- let(:configuration) { double("Configuration") }
77
- before { allow(InfluxDB::Rails).to receive(:configuration).and_return configuration }
78
-
79
- {
80
- "ns" => 1_513_009_229_111_222_333,
81
- nil => 1_513_009_229_111_222_333,
82
- "u" => 1_513_009_229_111_222,
83
- "ms" => 1_513_009_229_111,
84
- "s" => 1_513_009_229,
85
- "m" => 25_216_820,
86
- "h" => 420_280,
87
- }.each do |precision, converted_value|
88
- it "should return the timestamp in nanoseconds when precision is #{precision.inspect}" do
89
- allow(configuration).to receive(:time_precision).and_return(precision)
90
- expect(InfluxDB::Rails.convert_timestamp(sometime)).to eq(converted_value)
91
- end
92
- end
93
-
94
- it "should raise an excpetion when precision is unrecognized" do
95
- allow(configuration).to receive(:time_precision).and_return("whatever")
96
- expect { InfluxDB::Rails.convert_timestamp(sometime) }
97
- .to raise_exception(/invalid time precision.*whatever/i)
98
- end
99
- end
100
-
101
- describe ".current_timestamp" do
102
- it "should return the current timestamp in the configured precision" do
103
- now = Time.parse("2017-12-11 16:20:29.111222333 UTC")
104
- allow(Time).to receive(:now).and_return(now)
105
- InfluxDB::Rails.configure { |config| config.time_precision = "ms" }
106
- expect(InfluxDB::Rails.current_timestamp).to eq(1_513_009_229_111)
107
- end
108
- end
109
-
110
- describe ".ignorable_exception?" do
111
- it "should be true for exception types specified in the configuration" do
112
- class DummyException < RuntimeError; end
113
- exception = DummyException.new
114
-
115
- InfluxDB::Rails.configure do |config|
116
- config.ignored_exceptions << "DummyException"
117
- end
118
-
119
- expect(InfluxDB::Rails.ignorable_exception?(exception)).to be_truthy
120
- end
121
-
122
- it "should be true for exception types specified in the configuration" do
123
- exception = ActionController::RoutingError.new("foo")
124
- expect(InfluxDB::Rails.ignorable_exception?(exception)).to be_truthy
125
- end
126
-
127
- it "should be false for valid exceptions" do
128
- exception = ZeroDivisionError.new
129
- expect(InfluxDB::Rails.ignorable_exception?(exception)).to be_falsey
130
- end
131
- end
132
-
133
- describe "rescue" do
134
- it "should transmit an exception when passed" do
135
- expect(InfluxDB::Rails.client).to receive(:write_point)
136
-
137
- InfluxDB::Rails.rescue do
138
- raise ArgumentError, "wrong"
139
- end
140
- end
141
-
142
- it "should also raise the exception when in an ignored environment" do
143
- InfluxDB::Rails.configure do |config|
144
- config.ignored_environments = %w[development test]
145
- end
146
-
147
- expect do
148
- InfluxDB::Rails.rescue do
149
- raise ArgumentError, "wrong"
150
- end
151
- end.to raise_error(ArgumentError)
152
- end
153
- end
154
-
155
- describe "rescue_and_reraise" do
156
- it "should transmit an exception when passed" do
157
- expect(InfluxDB::Rails.client).to receive(:write_point)
158
-
159
- expect do
160
- InfluxDB::Rails.rescue_and_reraise { raise ArgumentError, "wrong" }
161
- end.to raise_error(ArgumentError)
162
- end
163
- end
164
- end