influxdb-rails 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.github/workflows/spec.yml +32 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +35 -7
- data/CHANGELOG.md +40 -1
- data/README.md +125 -27
- data/Rakefile +0 -6
- data/gemfiles/Gemfile.rails-6.0.x +9 -0
- data/gemfiles/Gemfile.rails-6.1.x +9 -0
- data/influxdb-rails.gemspec +7 -4
- data/lib/influxdb-rails.rb +13 -2
- data/lib/influxdb/rails/configuration.rb +8 -12
- data/lib/influxdb/rails/context.rb +6 -40
- data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
- data/lib/influxdb/rails/metric.rb +39 -0
- data/lib/influxdb/rails/middleware/action_mailer_subscriber.rb +22 -0
- data/lib/influxdb/rails/middleware/active_job_subscriber.rb +67 -0
- data/lib/influxdb/rails/middleware/active_record_subscriber.rb +26 -0
- data/lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb +24 -0
- data/lib/influxdb/rails/middleware/render_subscriber.rb +15 -16
- data/lib/influxdb/rails/middleware/request_subscriber.rb +16 -21
- data/lib/influxdb/rails/middleware/sql_subscriber.rb +18 -18
- data/lib/influxdb/rails/middleware/subscriber.rb +40 -27
- data/lib/influxdb/rails/railtie.rb +15 -18
- data/lib/influxdb/rails/sql/normalizer.rb +3 -3
- data/lib/influxdb/rails/tags.rb +33 -0
- data/lib/influxdb/rails/test_client.rb +13 -0
- data/lib/influxdb/rails/values.rb +24 -0
- data/lib/influxdb/rails/version.rb +1 -1
- data/lib/rails/generators/influxdb/templates/initializer.rb +4 -0
- data/sample-dashboard/Dockerfile +2 -2
- data/sample-dashboard/README.md +21 -28
- data/sample-dashboard/Rakefile +10 -5
- data/sample-dashboard/Ruby On Rails ActiveJob.json +600 -0
- data/sample-dashboard/{Ruby On Rails Performance (per Action).json → Ruby On Rails Performance per Action.json } +343 -589
- data/sample-dashboard/{Ruby On Rails Performance (per Request).json → Ruby On Rails Performance per Request.json } +361 -211
- data/sample-dashboard/Ruby On Rails Performance.json +1347 -1139
- data/sample-dashboard/Ruby On Rails Requests.json +834 -0
- data/sample-dashboard/Ruby On Rails Slowlog by Action.json +278 -0
- data/sample-dashboard/Ruby On Rails Slowlog by Request.json +277 -0
- data/sample-dashboard/Ruby On Rails Slowlog by SQL.json +328 -0
- data/sample-dashboard/docker-compose.yml +6 -1
- data/sample-dashboard/provisioning/activejob.json +600 -0
- data/sample-dashboard/provisioning/performance-action.json +334 -580
- data/sample-dashboard/provisioning/performance-request.json +355 -205
- data/sample-dashboard/provisioning/performance.json +1336 -1128
- data/sample-dashboard/provisioning/requests.json +834 -0
- data/sample-dashboard/provisioning/slowlog-action.json +278 -0
- data/sample-dashboard/provisioning/slowlog-requests.json +277 -0
- data/sample-dashboard/provisioning/slowlog-sql.json +328 -0
- data/spec/requests/action_controller_metrics_spec.rb +96 -0
- data/spec/requests/action_mailer_deliver_metrics_spec.rb +42 -0
- data/spec/requests/action_view_collection_metrics_spec.rb +57 -0
- data/spec/requests/action_view_partial_metrics_spec.rb +53 -0
- data/spec/requests/action_view_template_metrics_spec.rb +53 -0
- data/spec/requests/active_job_enqueue_metrics_spec.rb +56 -0
- data/spec/requests/active_job_perform_metrics_spec.rb +62 -0
- data/spec/requests/active_record_instantiation_metrics_spec.rb +56 -0
- data/spec/requests/active_record_sql_metrics_spec.rb +87 -0
- data/spec/requests/block_inistrumentation_spec.rb +55 -0
- data/spec/requests/context_spec.rb +27 -0
- data/spec/requests/logger_spec.rb +10 -0
- data/spec/spec_helper.rb +12 -4
- data/spec/support/broken_client.rb +11 -0
- data/spec/support/rails5/app.rb +48 -13
- data/spec/support/rails6/app.rb +83 -0
- data/spec/support/views/layouts/mailer.txt.erb +1 -0
- data/spec/support/views/{widgets → metrics}/_item.html.erb +0 -0
- data/spec/support/views/{widgets → metrics}/index.html.erb +0 -0
- data/spec/support/views/metrics/show.html.erb +4 -0
- data/spec/unit/block_instrumentation_spec.rb +18 -0
- data/spec/unit/tags.rb +47 -0
- metadata +123 -45
- data/.travis.yml +0 -37
- data/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/gemfiles/Gemfile.rails-5.0.x +0 -7
- data/gemfiles/Gemfile.rails-5.1.x +0 -7
- data/lib/influxdb/rails/instrumentation.rb +0 -34
- data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -33
- data/spec/controllers/widgets_controller_spec.rb +0 -15
- data/spec/integration/integration_helper.rb +0 -1
- data/spec/integration/metrics_spec.rb +0 -27
- data/spec/shared_examples/data.rb +0 -61
- data/spec/support/rails4/app.rb +0 -48
- data/spec/unit/context_spec.rb +0 -40
- data/spec/unit/middleware/render_subscriber_spec.rb +0 -96
- data/spec/unit/middleware/request_subscriber_spec.rb +0 -103
- data/spec/unit/middleware/sql_subscriber_spec.rb +0 -108
@@ -1,108 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "shared_examples/data"
|
3
|
-
|
4
|
-
RSpec.describe InfluxDB::Rails::Middleware::SqlSubscriber do
|
5
|
-
let(:config) { InfluxDB::Rails::Configuration.new }
|
6
|
-
let(:logger) { double(:logger) }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(config).to receive(:application_name).and_return("my-rails-app")
|
10
|
-
allow(config).to receive(:ignored_environments).and_return([])
|
11
|
-
allow(config.client).to receive(:time_precision).and_return("ms")
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ".call" do
|
15
|
-
let(:start) { Time.at(1_517_567_368) }
|
16
|
-
let(:finish) { Time.at(1_517_567_370) }
|
17
|
-
let(:hook_name) { "sql.active_record" }
|
18
|
-
let(:payload) { { sql: "SELECT * FROM POSTS WHERE id = 1", name: "Post Load", binds: %w[1 2 3] } }
|
19
|
-
let(:data) do
|
20
|
-
{
|
21
|
-
values: {
|
22
|
-
value: 2000,
|
23
|
-
sql: "SELECT * FROM POSTS WHERE id = xxx"
|
24
|
-
},
|
25
|
-
tags: {
|
26
|
-
location: "Foo#bar",
|
27
|
-
operation: "SELECT",
|
28
|
-
class_name: "Post",
|
29
|
-
hook: "sql",
|
30
|
-
name: "Post Load",
|
31
|
-
},
|
32
|
-
timestamp: 1_517_567_370_000
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
subject { described_class.new(config, hook_name) }
|
37
|
-
|
38
|
-
before do
|
39
|
-
InfluxDB::Rails.current.controller = "Foo"
|
40
|
-
InfluxDB::Rails.current.action = "bar"
|
41
|
-
end
|
42
|
-
|
43
|
-
after do
|
44
|
-
InfluxDB::Rails.current.reset
|
45
|
-
end
|
46
|
-
|
47
|
-
context "successfully" do
|
48
|
-
it "writes to InfluxDB" do
|
49
|
-
expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
|
50
|
-
config.measurement_name, data
|
51
|
-
)
|
52
|
-
subject.call("name", start, finish, "id", payload)
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with not relevant queries" do
|
56
|
-
before do
|
57
|
-
payload[:sql] = "SHOW FULL FIELDS FROM `users`"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not write to InfluxDB" do
|
61
|
-
expect_any_instance_of(InfluxDB::Client).not_to receive(:write_point)
|
62
|
-
subject.call("name", start, finish, "id", payload)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it_behaves_like "with additional data", ["sql"]
|
67
|
-
|
68
|
-
context "without location" do
|
69
|
-
before do
|
70
|
-
InfluxDB::Rails.current.reset
|
71
|
-
end
|
72
|
-
|
73
|
-
it "does use the default location" do
|
74
|
-
data[:tags] = data[:tags].merge(location: :raw)
|
75
|
-
expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
|
76
|
-
config.measurement_name, data
|
77
|
-
)
|
78
|
-
subject.call("name", start, finish, "id", payload)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "unsuccessfully" do
|
84
|
-
before do
|
85
|
-
InfluxDB::Rails.configuration = config
|
86
|
-
end
|
87
|
-
|
88
|
-
it "does log exceptions" do
|
89
|
-
allow_any_instance_of(InfluxDB::Client).to receive(:write_point).and_raise("boom")
|
90
|
-
expect(::Rails.logger).to receive(:error).with(/boom/)
|
91
|
-
subject.call("name", start, finish, "id", payload)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "disabled" do
|
96
|
-
before do
|
97
|
-
allow(config).to receive(:ignored_hooks).and_return(["sql.active_record"])
|
98
|
-
end
|
99
|
-
|
100
|
-
subject { described_class.new(config, "sql.active_record") }
|
101
|
-
|
102
|
-
it "does not write a data point" do
|
103
|
-
expect_any_instance_of(InfluxDB::Client).not_to receive(:write_point)
|
104
|
-
subject.call("name", start, finish, "id", payload)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|