influxdb-rails 1.0.0.beta3 → 1.0.1.beta3
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 +31 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +40 -7
- data/CHANGELOG.md +42 -12
- data/README.md +277 -164
- 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 +18 -9
- data/lib/influxdb-rails.rb +31 -81
- data/lib/influxdb/rails/configuration.rb +99 -194
- data/lib/influxdb/rails/context.rb +12 -28
- 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 +16 -10
- data/lib/influxdb/rails/middleware/request_subscriber.rb +23 -30
- data/lib/influxdb/rails/middleware/sql_subscriber.rb +19 -15
- data/lib/influxdb/rails/middleware/subscriber.rb +44 -20
- data/lib/influxdb/rails/railtie.rb +29 -35
- 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/influxdb_generator.rb +1 -1
- data/lib/rails/generators/influxdb/templates/initializer.rb +43 -9
- data/sample-dashboard/Dockerfile +24 -0
- data/sample-dashboard/README.md +74 -0
- data/sample-dashboard/Rakefile +9 -0
- data/sample-dashboard/Ruby On Rails Performance (per Action).json +1576 -0
- data/sample-dashboard/Ruby On Rails Performance (per Request).json +1053 -0
- data/sample-dashboard/Ruby On Rails Performance.json +2041 -0
- data/sample-dashboard/docker-compose.yml +34 -0
- data/sample-dashboard/provisioning/grafana-dashboards.yml +12 -0
- data/sample-dashboard/provisioning/grafana-datasource.yml +10 -0
- data/sample-dashboard/provisioning/performance-action.json +1576 -0
- data/sample-dashboard/provisioning/performance-request.json +1053 -0
- data/sample-dashboard/provisioning/performance.json +2041 -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 +14 -4
- data/spec/support/broken_client.rb +11 -0
- data/spec/support/rails5/app.rb +51 -12
- 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/configuration_spec.rb +47 -65
- metadata +141 -61
- 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/air_traffic_controller.rb +0 -41
- data/lib/influxdb/rails/backtrace.rb +0 -44
- data/lib/influxdb/rails/exception_presenter.rb +0 -94
- data/lib/influxdb/rails/instrumentation.rb +0 -34
- data/lib/influxdb/rails/logger.rb +0 -16
- data/lib/influxdb/rails/middleware/hijack_render_exception.rb +0 -16
- data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +0 -31
- data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -46
- data/lib/influxdb/rails/rack.rb +0 -24
- data/spec/controllers/widgets_controller_spec.rb +0 -15
- data/spec/integration/exceptions_spec.rb +0 -37
- data/spec/integration/integration_helper.rb +0 -1
- data/spec/integration/metrics_spec.rb +0 -28
- data/spec/shared_examples/tags.rb +0 -42
- data/spec/support/rails4/app.rb +0 -44
- data/spec/unit/backtrace_spec.rb +0 -85
- data/spec/unit/context_spec.rb +0 -40
- data/spec/unit/exception_presenter_spec.rb +0 -23
- data/spec/unit/influxdb_rails_spec.rb +0 -78
- data/spec/unit/middleware/render_subscriber_spec.rb +0 -92
- data/spec/unit/middleware/request_subscriber_spec.rb +0 -91
- data/spec/unit/middleware/sql_subscriber_spec.rb +0 -81
@@ -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, 500),
|
35
|
+
db: be_between(1, 500),
|
36
|
+
controller: be_between(1, 500)
|
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,49 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "ActionMailer deliver 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: "deliver",
|
22
|
+
mailer: "MetricMailer",
|
23
|
+
location: "MetricsController#index",
|
24
|
+
additional_tag: :value,
|
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
|
+
request_id: :request_id,
|
32
|
+
value: 1
|
33
|
+
)
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not write metric when hook is ignored" do
|
38
|
+
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["deliver.action_mailer"])
|
39
|
+
|
40
|
+
get "/metrics"
|
41
|
+
|
42
|
+
expect_no_metric(
|
43
|
+
tags: a_hash_including(
|
44
|
+
hook: "deliver",
|
45
|
+
mailer: "MetricMailer"
|
46
|
+
)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
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, 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
|