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.
- 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 -3
- 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 +22 -13
- 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 -3
- data/sample-dashboard/README.md +21 -28
- data/sample-dashboard/Rakefile +10 -4
- data/sample-dashboard/Ruby On Rails ActiveJob.json +600 -0
- data/sample-dashboard/Ruby On Rails Performance per Action.json +1330 -0
- data/sample-dashboard/{Ruby On Rails Performance (per Request).json → Ruby On Rails Performance per Request.json } +367 -217
- data/sample-dashboard/Ruby On Rails Performance.json +1348 -1110
- 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 +7 -1
- data/sample-dashboard/provisioning/activejob.json +600 -0
- data/sample-dashboard/provisioning/performance-action.json +1330 -0
- data/sample-dashboard/provisioning/performance-request.json +361 -211
- data/sample-dashboard/provisioning/performance.json +1337 -1099
- 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 +83 -0
- data/spec/requests/action_mailer_deliver_metrics_spec.rb +49 -0
- data/spec/requests/action_view_collection_metrics_spec.rb +66 -0
- data/spec/requests/action_view_partial_metrics_spec.rb +62 -0
- data/spec/requests/action_view_template_metrics_spec.rb +62 -0
- data/spec/requests/active_job_enqueue_metrics_spec.rb +65 -0
- data/spec/requests/active_job_perform_metrics_spec.rb +68 -0
- data/spec/requests/active_record_instantiation_metrics_spec.rb +65 -0
- data/spec/requests/active_record_sql_metrics_spec.rb +103 -0
- data/spec/requests/block_inistrumentation_spec.rb +64 -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
- metadata +124 -46
- 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
@@ -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, 500)
|
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, 500)
|
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, 500)
|
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,65 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "ActiveRecord instantiation 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
|
+
let(:metric) { Metric.create!(name: "name") }
|
10
|
+
before do
|
11
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development])
|
12
|
+
allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
|
13
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name)
|
14
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "writes metric" do
|
18
|
+
get metric_path(metric)
|
19
|
+
|
20
|
+
expect_metric(
|
21
|
+
tags: a_hash_including(
|
22
|
+
location: "MetricsController#show",
|
23
|
+
hook: "instantiation",
|
24
|
+
class_name: "Metric",
|
25
|
+
additional_tag: :value,
|
26
|
+
server: Socket.gethostname,
|
27
|
+
app_name: :app_name,
|
28
|
+
tags_middleware: :tags_middleware
|
29
|
+
),
|
30
|
+
values: a_hash_including(
|
31
|
+
additional_value: :value,
|
32
|
+
request_id: :request_id,
|
33
|
+
value: be_between(1, 500),
|
34
|
+
record_count: 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 metric_path(metric)
|
43
|
+
|
44
|
+
expect_metric(
|
45
|
+
tags: a_hash_including(
|
46
|
+
location: "MetricsController#show",
|
47
|
+
hook: "instantiation"
|
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(["instantiation.active_record"])
|
55
|
+
|
56
|
+
get metric_path(metric)
|
57
|
+
|
58
|
+
expect_no_metric(
|
59
|
+
tags: a_hash_including(
|
60
|
+
location: "MetricsController#show",
|
61
|
+
hook: "instantiation"
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "ActiveRecord SQL 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
|
+
skip("https://github.com/rails/rails/issues/30586") unless payload_names_fixed_in_rails?
|
17
|
+
|
18
|
+
get "/metrics"
|
19
|
+
|
20
|
+
expect_metric(
|
21
|
+
tags: a_hash_including(
|
22
|
+
location: "MetricsController#index",
|
23
|
+
hook: "sql",
|
24
|
+
name: "Metric Create",
|
25
|
+
class_name: "Metric",
|
26
|
+
operation: "INSERT",
|
27
|
+
additional_tag: :value,
|
28
|
+
server: Socket.gethostname,
|
29
|
+
app_name: :app_name,
|
30
|
+
tags_middleware: :tags_middleware
|
31
|
+
),
|
32
|
+
values: a_hash_including(
|
33
|
+
additional_value: :value,
|
34
|
+
request_id: :request_id,
|
35
|
+
value: be_between(1, 500),
|
36
|
+
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
|
37
|
+
)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "writes metric" do
|
42
|
+
skip("https://github.com/rails/rails/issues/30586") if payload_names_fixed_in_rails?
|
43
|
+
|
44
|
+
get "/metrics"
|
45
|
+
|
46
|
+
expect_metric(
|
47
|
+
tags: a_hash_including(
|
48
|
+
location: "MetricsController#index",
|
49
|
+
hook: "sql",
|
50
|
+
name: "SQL",
|
51
|
+
class_name: "SQL",
|
52
|
+
operation: "INSERT",
|
53
|
+
additional_tag: :value,
|
54
|
+
server: Socket.gethostname,
|
55
|
+
app_name: :app_name,
|
56
|
+
tags_middleware: :tags_middleware
|
57
|
+
),
|
58
|
+
values: a_hash_including(
|
59
|
+
additional_value: :value,
|
60
|
+
request_id: :request_id,
|
61
|
+
value: be_between(1, 500),
|
62
|
+
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
|
63
|
+
)
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "includes correct timestamps" do
|
68
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
69
|
+
|
70
|
+
get "/metrics"
|
71
|
+
|
72
|
+
expect_metric(
|
73
|
+
tags: a_hash_including(
|
74
|
+
location: "MetricsController#index",
|
75
|
+
hook: "sql"
|
76
|
+
),
|
77
|
+
timestamp: 1_514_797_200
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "does not write metric when hook is ignored" do
|
82
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["sql.active_record"])
|
83
|
+
|
84
|
+
get "/metrics"
|
85
|
+
|
86
|
+
expect_no_metric(
|
87
|
+
tags: a_hash_including(
|
88
|
+
location: "MetricsController#index",
|
89
|
+
hook: "sql"
|
90
|
+
)
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def payload_names_fixed_in_rails?
|
95
|
+
Rails::VERSION::MAJOR > 5 ||
|
96
|
+
rails_after_5_1?
|
97
|
+
end
|
98
|
+
|
99
|
+
def rails_after_5_1?
|
100
|
+
Rails::VERSION::MAJOR == 5 &&
|
101
|
+
Rails::VERSION::MINOR > 1
|
102
|
+
end
|
103
|
+
end
|