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
@@ -0,0 +1,57 @@
|
|
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
|
+
hook: "render_collection",
|
22
|
+
filename: include("spec/support/views/metrics/_item.html.erb")
|
23
|
+
),
|
24
|
+
values: a_hash_including(
|
25
|
+
count: 3,
|
26
|
+
value: be_between(1, 500)
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "includes correct timestamps" do
|
32
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
33
|
+
|
34
|
+
get "/metrics"
|
35
|
+
|
36
|
+
expect_metric(
|
37
|
+
name: "rails",
|
38
|
+
tags: a_hash_including(
|
39
|
+
hook: "render_collection"
|
40
|
+
),
|
41
|
+
timestamp: 1_514_797_200
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not write metric when hook is ignored" do
|
46
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_collection.action_view"])
|
47
|
+
|
48
|
+
get "/metrics"
|
49
|
+
|
50
|
+
expect_no_metric(
|
51
|
+
name: "rails",
|
52
|
+
tags: a_hash_including(
|
53
|
+
hook: "render_collection"
|
54
|
+
)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
hook: "render_partial",
|
21
|
+
filename: include("spec/support/views/metrics/_item.html.erb")
|
22
|
+
),
|
23
|
+
values: a_hash_including(
|
24
|
+
value: be_between(1, 500)
|
25
|
+
)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "includes correct timestamps" do
|
30
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
31
|
+
|
32
|
+
get "/metrics"
|
33
|
+
|
34
|
+
expect_metric(
|
35
|
+
tags: a_hash_including(
|
36
|
+
hook: "render_partial"
|
37
|
+
),
|
38
|
+
timestamp: 1_514_797_200
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not write metric when hook is ignored" do
|
43
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_partial.action_view"])
|
44
|
+
|
45
|
+
get "/metrics"
|
46
|
+
|
47
|
+
expect_no_metric(
|
48
|
+
tags: a_hash_including(
|
49
|
+
hook: "render_partial"
|
50
|
+
)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
hook: "render_template",
|
21
|
+
filename: include("spec/support/views/metrics/index.html.erb")
|
22
|
+
),
|
23
|
+
values: a_hash_including(
|
24
|
+
value: be_between(1, 500)
|
25
|
+
)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "includes correct timestamps" do
|
30
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
31
|
+
|
32
|
+
get "/metrics"
|
33
|
+
|
34
|
+
expect_metric(
|
35
|
+
tags: a_hash_including(
|
36
|
+
hook: "render_template"
|
37
|
+
),
|
38
|
+
timestamp: 1_514_797_200
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not write metric when hook is ignored" do
|
43
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_template.action_view"])
|
44
|
+
|
45
|
+
get "/metrics"
|
46
|
+
|
47
|
+
expect_no_metric(
|
48
|
+
tags: a_hash_including(
|
49
|
+
hook: "render_template"
|
50
|
+
)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
hook: "enqueue",
|
22
|
+
job: "MetricJob",
|
23
|
+
queue: "default",
|
24
|
+
state: "queued"
|
25
|
+
),
|
26
|
+
values: a_hash_including(
|
27
|
+
value: 1
|
28
|
+
)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes correct timestamps" do
|
33
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
34
|
+
|
35
|
+
get "/metrics"
|
36
|
+
|
37
|
+
expect_metric(
|
38
|
+
tags: a_hash_including(
|
39
|
+
hook: "enqueue"
|
40
|
+
),
|
41
|
+
timestamp: 1_514_797_200
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not write metric when hook is ignored" do
|
46
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["enqueue.active_job"])
|
47
|
+
|
48
|
+
get "/metrics"
|
49
|
+
|
50
|
+
expect_no_metric(
|
51
|
+
tags: a_hash_including(
|
52
|
+
hook: "enqueue"
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,62 @@
|
|
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
|
+
hook: "perform",
|
24
|
+
state: "succeeded",
|
25
|
+
job: "MetricJob",
|
26
|
+
queue: "default"
|
27
|
+
),
|
28
|
+
values: a_hash_including(
|
29
|
+
value: be_between(0, 30)
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "includes correct timestamps" do
|
35
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
36
|
+
|
37
|
+
perform_enqueued_jobs do
|
38
|
+
get "/metrics"
|
39
|
+
end
|
40
|
+
|
41
|
+
expect_metric(
|
42
|
+
tags: a_hash_including(
|
43
|
+
hook: "perform"
|
44
|
+
),
|
45
|
+
timestamp: 1_514_797_200
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not write metric when hook is ignored" do
|
50
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["perform.active_job"])
|
51
|
+
|
52
|
+
perform_enqueued_jobs do
|
53
|
+
get "/metrics"
|
54
|
+
end
|
55
|
+
|
56
|
+
expect_no_metric(
|
57
|
+
tags: a_hash_including(
|
58
|
+
hook: "perform"
|
59
|
+
)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
hook: "instantiation",
|
23
|
+
class_name: "Metric"
|
24
|
+
),
|
25
|
+
values: a_hash_including(
|
26
|
+
value: be_between(1, 500),
|
27
|
+
record_count: 1
|
28
|
+
)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes correct timestamps" do
|
33
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
34
|
+
|
35
|
+
get metric_path(metric)
|
36
|
+
|
37
|
+
expect_metric(
|
38
|
+
tags: a_hash_including(
|
39
|
+
hook: "instantiation"
|
40
|
+
),
|
41
|
+
timestamp: 1_514_797_200
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "does not write metric when hook is ignored" do
|
46
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["instantiation.active_record"])
|
47
|
+
|
48
|
+
get metric_path(metric)
|
49
|
+
|
50
|
+
expect_no_metric(
|
51
|
+
tags: a_hash_including(
|
52
|
+
hook: "instantiation"
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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
|
+
hook: "sql",
|
23
|
+
name: "Metric Create",
|
24
|
+
class_name: "Metric",
|
25
|
+
operation: "INSERT"
|
26
|
+
),
|
27
|
+
values: a_hash_including(
|
28
|
+
value: be_between(1, 500),
|
29
|
+
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "writes metric" do
|
35
|
+
skip("https://github.com/rails/rails/issues/30586") if payload_names_fixed_in_rails?
|
36
|
+
|
37
|
+
get "/metrics"
|
38
|
+
|
39
|
+
expect_metric(
|
40
|
+
tags: a_hash_including(
|
41
|
+
hook: "sql",
|
42
|
+
name: "SQL",
|
43
|
+
class_name: "SQL",
|
44
|
+
operation: "INSERT"
|
45
|
+
),
|
46
|
+
values: a_hash_including(
|
47
|
+
value: be_between(1, 500),
|
48
|
+
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
|
49
|
+
)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "includes correct timestamps" do
|
54
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
55
|
+
|
56
|
+
get "/metrics"
|
57
|
+
|
58
|
+
expect_metric(
|
59
|
+
tags: a_hash_including(
|
60
|
+
hook: "sql"
|
61
|
+
),
|
62
|
+
timestamp: 1_514_797_200
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "does not write metric when hook is ignored" do
|
67
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["sql.active_record"])
|
68
|
+
|
69
|
+
get "/metrics"
|
70
|
+
|
71
|
+
expect_no_metric(
|
72
|
+
tags: a_hash_including(
|
73
|
+
hook: "sql"
|
74
|
+
)
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def payload_names_fixed_in_rails?
|
79
|
+
Rails::VERSION::MAJOR > 5 ||
|
80
|
+
rails_after_5_1?
|
81
|
+
end
|
82
|
+
|
83
|
+
def rails_after_5_1?
|
84
|
+
Rails::VERSION::MAJOR == 5 &&
|
85
|
+
Rails::VERSION::MINOR > 1
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "BlockInstrumentation 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
|
+
hook: "block_instrumentation",
|
21
|
+
block_tag: :block_tag,
|
22
|
+
name: "name"
|
23
|
+
),
|
24
|
+
values: a_hash_including(
|
25
|
+
block_value: :block_value,
|
26
|
+
value: be_between(1, 500)
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "includes correct timestamps" do
|
32
|
+
travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)
|
33
|
+
|
34
|
+
get "/metrics"
|
35
|
+
|
36
|
+
expect_metric(
|
37
|
+
tags: a_hash_including(
|
38
|
+
hook: "block_instrumentation"
|
39
|
+
),
|
40
|
+
timestamp: 1_514_797_200
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does not write metric when hook is ignored" do
|
45
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["block_instrumentation.influxdb_rails"])
|
46
|
+
|
47
|
+
get "/metrics"
|
48
|
+
|
49
|
+
expect_no_metric(
|
50
|
+
tags: a_hash_including(
|
51
|
+
hook: "block_instrumentation"
|
52
|
+
)
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|