appsignal 2.1.0.alpha.3 → 2.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +43 -0
- data/.rubocop_todo.yml +289 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/appsignal.gemspec +1 -0
- data/bin/appsignal +2 -2
- data/ext/agent.yml +11 -11
- data/ext/extconf.rb +33 -33
- data/gemfiles/rails-4.2.gemfile +4 -0
- data/gemfiles/resque.gemfile +4 -0
- data/lib/appsignal.rb +58 -54
- data/lib/appsignal/auth_check.rb +15 -16
- data/lib/appsignal/capistrano.rb +4 -4
- data/lib/appsignal/cli.rb +28 -28
- data/lib/appsignal/cli/diagnose.rb +11 -11
- data/lib/appsignal/cli/helpers.rb +1 -1
- data/lib/appsignal/cli/install.rb +38 -38
- data/lib/appsignal/cli/notify_of_deploy.rb +1 -1
- data/lib/appsignal/config.rb +73 -71
- data/lib/appsignal/event_formatter.rb +8 -8
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +4 -4
- data/lib/appsignal/event_formatter/active_record/instantiation_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/elastic_search/search_formatter.rb +9 -7
- data/lib/appsignal/event_formatter/faraday/request_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +6 -6
- data/lib/appsignal/event_formatter/moped/query_formatter.rb +56 -43
- data/lib/appsignal/extension.rb +5 -5
- data/lib/appsignal/hooks.rb +28 -26
- data/lib/appsignal/hooks/active_support_notifications.rb +2 -2
- data/lib/appsignal/hooks/celluloid.rb +1 -1
- data/lib/appsignal/hooks/data_mapper.rb +2 -2
- data/lib/appsignal/hooks/delayed_job.rb +1 -1
- data/lib/appsignal/hooks/mongo_ruby_driver.rb +1 -1
- data/lib/appsignal/hooks/net_http.rb +4 -4
- data/lib/appsignal/hooks/passenger.rb +2 -2
- data/lib/appsignal/hooks/puma.rb +4 -4
- data/lib/appsignal/hooks/rake.rb +1 -1
- data/lib/appsignal/hooks/redis.rb +1 -1
- data/lib/appsignal/hooks/sequel.rb +2 -2
- data/lib/appsignal/hooks/shoryuken.rb +8 -8
- data/lib/appsignal/hooks/sidekiq.rb +16 -15
- data/lib/appsignal/hooks/unicorn.rb +1 -1
- data/lib/appsignal/hooks/webmachine.rb +1 -1
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +6 -6
- data/lib/appsignal/integrations/data_mapper.rb +2 -3
- data/lib/appsignal/integrations/delayed_job_plugin.rb +5 -5
- data/lib/appsignal/integrations/mongo_ruby_driver.rb +6 -6
- data/lib/appsignal/integrations/padrino.rb +8 -8
- data/lib/appsignal/integrations/railtie.rb +5 -5
- data/lib/appsignal/integrations/resque.rb +4 -5
- data/lib/appsignal/integrations/resque_active_job.rb +3 -6
- data/lib/appsignal/integrations/sinatra.rb +2 -2
- data/lib/appsignal/integrations/webmachine.rb +2 -3
- data/lib/appsignal/js_exception_transaction.rb +10 -10
- data/lib/appsignal/marker.rb +3 -3
- data/lib/appsignal/rack/generic_instrumentation.rb +10 -9
- data/lib/appsignal/rack/js_exception_catcher.rb +7 -6
- data/lib/appsignal/rack/rails_instrumentation.rb +9 -8
- data/lib/appsignal/rack/sinatra_instrumentation.rb +19 -17
- data/lib/appsignal/rack/streaming_listener.rb +9 -8
- data/lib/appsignal/system.rb +19 -17
- data/lib/appsignal/transaction.rb +97 -40
- data/lib/appsignal/transmitter.rb +23 -30
- data/lib/appsignal/utils.rb +3 -3
- data/lib/appsignal/utils/params_sanitizer.rb +1 -1
- data/lib/appsignal/utils/query_params_sanitizer.rb +1 -1
- data/lib/appsignal/version.rb +2 -2
- data/spec/.rubocop.yml +4 -0
- data/spec/lib/appsignal/auth_check_spec.rb +7 -7
- data/spec/lib/appsignal/capistrano2_spec.rb +41 -41
- data/spec/lib/appsignal/capistrano3_spec.rb +43 -44
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +9 -11
- data/spec/lib/appsignal/cli_spec.rb +9 -9
- data/spec/lib/appsignal/config_spec.rb +88 -86
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +9 -9
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +12 -12
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +23 -23
- data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +29 -30
- data/spec/lib/appsignal/event_formatter_spec.rb +28 -28
- data/spec/lib/appsignal/extension_spec.rb +15 -15
- data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +6 -5
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +12 -12
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +34 -34
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +10 -10
- data/spec/lib/appsignal/hooks/rake_spec.rb +7 -7
- data/spec/lib/appsignal/hooks/redis_spec.rb +6 -6
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +21 -22
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +48 -45
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +2 -2
- data/spec/lib/appsignal/hooks_spec.rb +16 -17
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +7 -8
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +19 -19
- data/spec/lib/appsignal/integrations/object_spec.rb +3 -3
- data/spec/lib/appsignal/integrations/padrino_spec.rb +44 -44
- data/spec/lib/appsignal/integrations/railtie_spec.rb +13 -13
- data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/resque_spec.rb +8 -8
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +15 -15
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +23 -23
- data/spec/lib/appsignal/marker_spec.rb +8 -8
- data/spec/lib/appsignal/minutely_spec.rb +6 -6
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +7 -7
- data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +13 -13
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +11 -11
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +21 -21
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +36 -36
- data/spec/lib/appsignal/system/container_spec.rb +1 -1
- data/spec/lib/appsignal/transaction_spec.rb +213 -184
- data/spec/lib/appsignal/transmitter_spec.rb +20 -20
- data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +19 -19
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +41 -41
- data/spec/lib/appsignal/utils_spec.rb +41 -37
- data/spec/lib/appsignal_spec.rb +150 -142
- data/spec/spec_helper.rb +18 -18
- data/spec/support/delegate_matcher.rb +6 -6
- data/spec/support/helpers/api_request_helper.rb +2 -2
- data/spec/support/helpers/config_helpers.rb +3 -3
- data/spec/support/helpers/dependency_helper.rb +13 -13
- data/spec/support/helpers/directory_helper.rb +5 -5
- data/spec/support/helpers/env_helpers.rb +14 -14
- data/spec/support/helpers/system_helpers.rb +3 -3
- data/spec/support/helpers/transaction_helpers.rb +10 -10
- metadata +20 -2
@@ -1,33 +1,33 @@
|
|
1
1
|
if DependencyHelper.rails_present?
|
2
|
-
require
|
2
|
+
require "action_view"
|
3
3
|
|
4
4
|
describe Appsignal::EventFormatter::ActionView::RenderFormatter do
|
5
|
-
before { Rails.root.stub(:to_s =>
|
5
|
+
before { Rails.root.stub(:to_s => "/var/www/app/20130101") }
|
6
6
|
let(:klass) { Appsignal::EventFormatter::ActionView::RenderFormatter }
|
7
7
|
let(:formatter) { klass.new }
|
8
8
|
|
9
9
|
it "should register render_partial.action_view and render_template.action_view" do
|
10
|
-
Appsignal::EventFormatter.registered?(
|
11
|
-
Appsignal::EventFormatter.registered?(
|
10
|
+
Appsignal::EventFormatter.registered?("render_partial.action_view", klass).should be_true
|
11
|
+
Appsignal::EventFormatter.registered?("render_template.action_view", klass).should be_true
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#root_path" do
|
15
|
-
its(:root_path) { should eq
|
15
|
+
its(:root_path) { should eq "/var/www/app/20130101/" }
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#format" do
|
19
19
|
subject { formatter.format(payload) }
|
20
20
|
|
21
21
|
context "with an identifier" do
|
22
|
-
let(:payload) { {:identifier =>
|
22
|
+
let(:payload) { { :identifier => "/var/www/app/20130101/app/views/home/index/html.erb" } }
|
23
23
|
|
24
|
-
it { should eq [
|
24
|
+
it { should eq ["app/views/home/index/html.erb", nil] }
|
25
25
|
end
|
26
26
|
|
27
27
|
context "with a frozen identifier" do
|
28
|
-
let(:payload) { {:identifier =>
|
28
|
+
let(:payload) { { :identifier => "/var/www/app/20130101/app/views/home/index/html.erb".freeze } }
|
29
29
|
|
30
|
-
it { should eq [
|
30
|
+
it { should eq ["app/views/home/index/html.erb", nil] }
|
31
31
|
end
|
32
32
|
|
33
33
|
context "without an identifier" do
|
@@ -3,19 +3,19 @@ describe Appsignal::EventFormatter::ActiveRecord::InstantiationFormatter do
|
|
3
3
|
let(:formatter) { klass.new }
|
4
4
|
|
5
5
|
it "should register instantiation.active_record" do
|
6
|
-
Appsignal::EventFormatter.registered?(
|
6
|
+
Appsignal::EventFormatter.registered?("instantiation.active_record", klass).should be_true
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#format" do
|
10
10
|
let(:payload) do
|
11
11
|
{
|
12
|
-
record_count
|
13
|
-
class_name
|
12
|
+
:record_count => 1,
|
13
|
+
:class_name => "User"
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
subject { formatter.format(payload) }
|
18
18
|
|
19
|
-
it { should eq [
|
19
|
+
it { should eq ["User", nil] }
|
20
20
|
end
|
21
21
|
end
|
@@ -3,19 +3,19 @@ describe Appsignal::EventFormatter::ActiveRecord::InstantiationFormatter do
|
|
3
3
|
let(:formatter) { klass.new }
|
4
4
|
|
5
5
|
it "should register sql.active_record" do
|
6
|
-
Appsignal::EventFormatter.registered?(
|
6
|
+
Appsignal::EventFormatter.registered?("sql.active_record", klass).should be_true
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#format" do
|
10
10
|
let(:payload) do
|
11
11
|
{
|
12
|
-
name
|
13
|
-
sql
|
12
|
+
:name => "User load",
|
13
|
+
:sql => "SELECT * FROM users"
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
subject { formatter.format(payload) }
|
18
18
|
|
19
|
-
it { should eq [
|
19
|
+
it { should eq ["User load", "SELECT * FROM users", 1] }
|
20
20
|
end
|
21
21
|
end
|
@@ -4,21 +4,21 @@ describe Appsignal::EventFormatter::ElasticSearch::SearchFormatter do
|
|
4
4
|
|
5
5
|
it "should register query.moped" do
|
6
6
|
expect(
|
7
|
-
Appsignal::EventFormatter.registered?(
|
7
|
+
Appsignal::EventFormatter.registered?("search.elasticsearch", klass)
|
8
8
|
).to be_true
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#format" do
|
12
12
|
let(:payload) do
|
13
13
|
{
|
14
|
-
:name =>
|
15
|
-
:klass =>
|
16
|
-
:search => {:index =>
|
14
|
+
:name => "Search",
|
15
|
+
:klass => "User",
|
16
|
+
:search => { :index => "users", :type => "user", :q => "John Doe" }
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return a payload with name and sanitized body" do
|
21
|
-
expect(
|
21
|
+
expect(formatter.format(payload)).to eql([
|
22
22
|
"Search: User",
|
23
23
|
"{:index=>\"users\", :type=>\"user\", :q=>\"?\"}"
|
24
24
|
])
|
@@ -28,25 +28,25 @@ describe Appsignal::EventFormatter::ElasticSearch::SearchFormatter do
|
|
28
28
|
describe "#sanitized_search" do
|
29
29
|
let(:search) do
|
30
30
|
{
|
31
|
-
:index =>
|
32
|
-
:type =>
|
33
|
-
:q =>
|
34
|
-
:other =>
|
31
|
+
:index => "users",
|
32
|
+
:type => "user",
|
33
|
+
:q => "John Doe",
|
34
|
+
:other => "Other"
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should sanitize non-whitelisted params" do
|
39
39
|
expect(
|
40
40
|
formatter.sanitized_search(search)
|
41
|
-
).to eql(
|
41
|
+
).to eql(:index => "users", :type => "user", :q => "?", :other => "?")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should return nil string when search is nil" do
|
45
|
-
expect(
|
45
|
+
expect(formatter.sanitized_search(nil)).to be_nil
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return nil string when search is not a hash" do
|
49
|
-
expect(
|
49
|
+
expect(formatter.sanitized_search([])).to be_nil
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -3,19 +3,19 @@ describe Appsignal::EventFormatter::Faraday::RequestFormatter do
|
|
3
3
|
let(:formatter) { klass.new }
|
4
4
|
|
5
5
|
it "should register request.faraday" do
|
6
|
-
Appsignal::EventFormatter.registered?(
|
6
|
+
Appsignal::EventFormatter.registered?("request.faraday", klass).should be_true
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#format" do
|
10
10
|
let(:payload) do
|
11
11
|
{
|
12
|
-
method
|
13
|
-
url
|
12
|
+
:method => :get,
|
13
|
+
:url => URI.parse("http://example.org/hello/world?some=param")
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
subject { formatter.format(payload) }
|
18
18
|
|
19
|
-
it { should eq [
|
19
|
+
it { should eq ["GET http://example.org", "GET http://example.org/hello/world"] }
|
20
20
|
end
|
21
21
|
end
|
@@ -6,15 +6,15 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
|
|
6
6
|
let(:command) do
|
7
7
|
{
|
8
8
|
"find" => "users",
|
9
|
-
"filter" => {"_id" => 1}
|
9
|
+
"filter" => { "_id" => 1 }
|
10
10
|
}
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should apply a strategy for each key" do
|
14
|
-
expect(
|
15
|
-
.with(:sanitize_document,
|
14
|
+
expect(formatter).to receive(:apply_strategy)
|
15
|
+
.with(:sanitize_document, "_id" => 1)
|
16
16
|
|
17
|
-
expect(
|
17
|
+
expect(formatter).to receive(:apply_strategy)
|
18
18
|
.with(:allow, "users")
|
19
19
|
|
20
20
|
formatter.format(strategy, command)
|
@@ -24,7 +24,7 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
|
|
24
24
|
let(:strategy) { :bananas }
|
25
25
|
|
26
26
|
it "should return an empty hash" do
|
27
|
-
expect(
|
27
|
+
expect(formatter.format(strategy, command)).to eql({})
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,7 +32,7 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
|
|
32
32
|
let(:command) { :bananas }
|
33
33
|
|
34
34
|
it "should return an empty hash" do
|
35
|
-
expect(
|
35
|
+
expect(formatter.format(strategy, command)).to eql({})
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -40,61 +40,61 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
|
|
40
40
|
describe ".apply_strategy" do
|
41
41
|
context "when strategy is allow" do
|
42
42
|
let(:strategy) { :allow }
|
43
|
-
let(:value) { {"_id" => 1} }
|
43
|
+
let(:value) { { "_id" => 1 } }
|
44
44
|
|
45
45
|
it "should return the given value" do
|
46
|
-
expect(
|
46
|
+
expect(formatter.apply_strategy(strategy, value)).to eql(value)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
context "when strategy is deny" do
|
51
51
|
let(:strategy) { :deny }
|
52
|
-
let(:value) { {"_id" => 1} }
|
52
|
+
let(:value) { { "_id" => 1 } }
|
53
53
|
|
54
54
|
it "should return a '?'" do
|
55
|
-
expect(
|
55
|
+
expect(formatter.apply_strategy(strategy, value)).to eql("?")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
context "when strategy is deny_array" do
|
60
60
|
let(:strategy) { :deny_array }
|
61
|
-
let(:value) { {"_id" => 1} }
|
61
|
+
let(:value) { { "_id" => 1 } }
|
62
62
|
|
63
63
|
it "should return a sanitized array string" do
|
64
|
-
expect(
|
64
|
+
expect(formatter.apply_strategy(strategy, value)).to eql("[?]")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
context "when strategy is sanitize_document" do
|
69
69
|
let(:strategy) { :sanitize_document }
|
70
|
-
let(:value) { {"_id" => 1} }
|
70
|
+
let(:value) { { "_id" => 1 } }
|
71
71
|
|
72
72
|
it "should return a sanitized document" do
|
73
|
-
expect(
|
73
|
+
expect(formatter.apply_strategy(strategy, value)).to eql("_id" => "?")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
context "when strategy is sanitize_bulk" do
|
78
78
|
let(:strategy) { :sanitize_bulk }
|
79
|
-
let(:value) { [{"q" => {"_id" => 1}, "u" => [{"foo" => "bar"}]}] }
|
79
|
+
let(:value) { [{ "q" => { "_id" => 1 }, "u" => [{ "foo" => "bar" }] }] }
|
80
80
|
|
81
81
|
it "should return an array of sanitized bulk documents" do
|
82
|
-
expect(
|
83
|
-
{"q" => {"_id" =>
|
82
|
+
expect(formatter.apply_strategy(strategy, value)).to eql([
|
83
|
+
{ "q" => { "_id" => "?" }, "u" => "[?]" }
|
84
84
|
])
|
85
85
|
end
|
86
86
|
|
87
87
|
context "when bulk has more than one update" do
|
88
88
|
let(:value) do
|
89
89
|
[
|
90
|
-
{"q" => {"_id" => 1}, "u" => [{"foo" => "bar"}]},
|
91
|
-
{"q" => {"_id" => 2}, "u" => [{"foo" => "baz"}]}
|
90
|
+
{ "q" => { "_id" => 1 }, "u" => [{ "foo" => "bar" }] },
|
91
|
+
{ "q" => { "_id" => 2 }, "u" => [{ "foo" => "baz" }] }
|
92
92
|
]
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should return only the first value of sanitized bulk documents" do
|
96
|
-
expect(
|
97
|
-
{"q" => {"_id" =>
|
96
|
+
expect(formatter.apply_strategy(strategy, value)).to eql([
|
97
|
+
{ "q" => { "_id" => "?" }, "u" => "[?]" },
|
98
98
|
"[...]"
|
99
99
|
])
|
100
100
|
end
|
@@ -103,10 +103,10 @@ describe Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter do
|
|
103
103
|
|
104
104
|
context "when strategy is missing" do
|
105
105
|
let(:strategy) { nil }
|
106
|
-
let(:value) { {"_id" => 1} }
|
106
|
+
let(:value) { { "_id" => 1 } }
|
107
107
|
|
108
108
|
it "should return a '?'" do
|
109
|
-
expect(
|
109
|
+
expect(formatter.apply_strategy(strategy, value)).to eql("?")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -3,11 +3,11 @@ describe Appsignal::EventFormatter::Moped::QueryFormatter do
|
|
3
3
|
let(:formatter) { klass.new }
|
4
4
|
|
5
5
|
it "should register query.moped" do
|
6
|
-
Appsignal::EventFormatter.registered?(
|
6
|
+
Appsignal::EventFormatter.registered?("query.moped", klass).should be_true
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#format" do
|
10
|
-
let(:payload) { {:ops => [op]} }
|
10
|
+
let(:payload) { { :ops => [op] } }
|
11
11
|
subject { formatter.format(payload) }
|
12
12
|
|
13
13
|
context "without ops in the payload" do
|
@@ -19,95 +19,94 @@ describe Appsignal::EventFormatter::Moped::QueryFormatter do
|
|
19
19
|
context "Moped::Protocol::Command" do
|
20
20
|
let(:op) do
|
21
21
|
double(
|
22
|
-
:full_collection_name =>
|
23
|
-
:selector => {
|
24
|
-
:class => double(:to_s =>
|
22
|
+
:full_collection_name => "database.collection",
|
23
|
+
:selector => { "query" => { "_id" => "abc" } },
|
24
|
+
:class => double(:to_s => "Moped::Protocol::Command")
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
28
|
-
it { should eq [
|
28
|
+
it { should eq ["Command", '{:database=>"database.collection", :selector=>{"query"=>"?"}}'] }
|
29
29
|
end
|
30
30
|
|
31
31
|
context "Moped::Protocol::Query" do
|
32
32
|
let(:op) do
|
33
33
|
double(
|
34
|
-
:full_collection_name =>
|
35
|
-
:selector => {
|
34
|
+
:full_collection_name => "database.collection",
|
35
|
+
:selector => { "_id" => "abc" },
|
36
36
|
:flags => [],
|
37
37
|
:limit => 0,
|
38
38
|
:skip => 0,
|
39
39
|
:fields => nil,
|
40
|
-
:class => double(:to_s =>
|
40
|
+
:class => double(:to_s => "Moped::Protocol::Query")
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
44
|
-
it { should eq [
|
44
|
+
it { should eq ["Query", '{:database=>"database.collection", :selector=>{"_id"=>"?"}, :flags=>[], :limit=>0, :skip=>0, :fields=>nil}'] }
|
45
45
|
end
|
46
46
|
|
47
47
|
context "Moped::Protocol::Delete" do
|
48
48
|
let(:op) do
|
49
49
|
double(
|
50
|
-
:full_collection_name =>
|
51
|
-
:selector => {
|
50
|
+
:full_collection_name => "database.collection",
|
51
|
+
:selector => { "_id" => "abc" },
|
52
52
|
:flags => [],
|
53
|
-
:class => double(:to_s =>
|
53
|
+
:class => double(:to_s => "Moped::Protocol::Delete")
|
54
54
|
)
|
55
55
|
end
|
56
56
|
|
57
|
-
it { should eq [
|
57
|
+
it { should eq ["Delete", '{:database=>"database.collection", :selector=>{"_id"=>"?"}, :flags=>[]}'] }
|
58
58
|
end
|
59
59
|
|
60
60
|
context "Moped::Protocol::Insert" do
|
61
61
|
let(:op) do
|
62
62
|
double(
|
63
|
-
:full_collection_name =>
|
63
|
+
:full_collection_name => "database.collection",
|
64
64
|
:flags => [],
|
65
65
|
:documents => [
|
66
|
-
{
|
67
|
-
{
|
66
|
+
{ "_id" => "abc", "events" => { "foo" => [{ "bar" => "baz" }] } },
|
67
|
+
{ "_id" => "def", "events" => { "foo" => [{ "baz" => "bar" }] } }
|
68
68
|
],
|
69
|
-
:class => double(:to_s =>
|
69
|
+
:class => double(:to_s => "Moped::Protocol::Insert")
|
70
70
|
)
|
71
71
|
end
|
72
72
|
|
73
|
-
it { should eq [
|
73
|
+
it { should eq ["Insert", '{:database=>"database.collection", :documents=>{"_id"=>"?", "events"=>"?"}, :count=>2, :flags=>[]}'] }
|
74
74
|
end
|
75
75
|
|
76
76
|
context "Moped::Protocol::Update" do
|
77
77
|
let(:op) do
|
78
78
|
double(
|
79
|
-
:full_collection_name =>
|
80
|
-
:selector => {
|
81
|
-
:update => {
|
79
|
+
:full_collection_name => "database.collection",
|
80
|
+
:selector => { "_id" => "abc" },
|
81
|
+
:update => { "user.name" => "James Bond" },
|
82
82
|
:flags => [],
|
83
|
-
:class => double(:to_s =>
|
83
|
+
:class => double(:to_s => "Moped::Protocol::Update")
|
84
84
|
)
|
85
85
|
end
|
86
86
|
|
87
|
-
it { should eq [
|
87
|
+
it { should eq ["Update", '{:database=>"database.collection", :selector=>{"_id"=>"?"}, :update=>{"user.?"=>"?"}, :flags=>[]}'] }
|
88
88
|
end
|
89
89
|
|
90
90
|
context "Moped::Protocol::KillCursors" do
|
91
91
|
let(:op) do
|
92
92
|
double(
|
93
93
|
:number_of_cursor_ids => 2,
|
94
|
-
:class => double(:to_s =>
|
94
|
+
:class => double(:to_s => "Moped::Protocol::KillCursors")
|
95
95
|
)
|
96
96
|
end
|
97
97
|
|
98
|
-
it { should eq [
|
98
|
+
it { should eq ["KillCursors", "{:number_of_cursor_ids=>2}"] }
|
99
99
|
end
|
100
100
|
|
101
101
|
context "Moped::Protocol::Other" do
|
102
102
|
let(:op) do
|
103
103
|
double(
|
104
|
-
:full_collection_name =>
|
105
|
-
:class => double(:to_s =>
|
104
|
+
:full_collection_name => "database.collection",
|
105
|
+
:class => double(:to_s => "Moped::Protocol::Other")
|
106
106
|
)
|
107
107
|
end
|
108
108
|
|
109
|
-
it { should eq [
|
109
|
+
it { should eq ["Other", '{:database=>"database.collection"}'] }
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
113
112
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
class MockFormatter < Appsignal::EventFormatter
|
2
|
-
register
|
2
|
+
register "mock"
|
3
3
|
|
4
4
|
attr_reader :body
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@body =
|
7
|
+
@body = "some value"
|
8
8
|
end
|
9
9
|
|
10
|
-
def format(
|
11
|
-
[
|
10
|
+
def format(_payload)
|
11
|
+
["title", @body]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -23,7 +23,7 @@ class IncorrectFormatMockFormatter < Appsignal::EventFormatter
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class MockDependentFormatter < Appsignal::EventFormatter
|
26
|
-
register
|
26
|
+
register "mock.dependent"
|
27
27
|
|
28
28
|
def initialize
|
29
29
|
NonsenseDependency.something
|
@@ -39,62 +39,62 @@ describe Appsignal::EventFormatter do
|
|
39
39
|
|
40
40
|
context "registering and unregistering formatters" do
|
41
41
|
it "should register a formatter" do
|
42
|
-
klass.formatters[
|
42
|
+
klass.formatters["mock"].should be_instance_of(MockFormatter)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should know wether a formatter is registered" do
|
46
|
-
klass.registered?(
|
47
|
-
klass.registered?(
|
48
|
-
klass.registered?(
|
49
|
-
klass.registered?(
|
46
|
+
klass.registered?("mock").should be_true
|
47
|
+
klass.registered?("mock", MockFormatter).should be_true
|
48
|
+
klass.registered?("mock", Hash).should be_false
|
49
|
+
klass.registered?("nonsense").should be_false
|
50
50
|
end
|
51
51
|
|
52
52
|
it "doesn't register formatters that raise a name error in the initializer" do
|
53
|
-
klass.registered?(
|
53
|
+
klass.registered?("mock.dependent").should be_false
|
54
54
|
end
|
55
55
|
|
56
56
|
it "doesn't register formatters that don't have a format(payload) method" do
|
57
|
-
klass.register(
|
58
|
-
klass.register(
|
57
|
+
klass.register("mock.missing_format", MissingFormatMockFormatter)
|
58
|
+
klass.register("mock.incorrect_format", IncorrectFormatMockFormatter)
|
59
59
|
|
60
60
|
Appsignal::EventFormatter.initialize_formatters
|
61
61
|
|
62
|
-
klass.registered?(
|
63
|
-
klass.registered?(
|
62
|
+
klass.registered?("mock.missing_format").should be_false
|
63
|
+
klass.registered?("mock.incorrect_format").should be_false
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should register a custom formatter" do
|
67
|
-
klass.register(
|
67
|
+
klass.register("mock.specific", MockFormatter)
|
68
68
|
Appsignal::EventFormatter.initialize_formatters
|
69
69
|
|
70
|
-
klass.formatter_classes[
|
71
|
-
klass.registered?(
|
72
|
-
klass.formatters[
|
73
|
-
klass.formatters[
|
70
|
+
klass.formatter_classes["mock.specific"].should eq MockFormatter
|
71
|
+
klass.registered?("mock.specific").should be_true
|
72
|
+
klass.formatters["mock.specific"].should be_instance_of(MockFormatter)
|
73
|
+
klass.formatters["mock.specific"].body.should eq "some value"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should not have a formatter that's not registered" do
|
77
|
-
klass.formatters[
|
77
|
+
klass.formatters["nonsense"].should be_nil
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should unregister a formatter if the registered one has the same class" do
|
81
|
-
klass.register(
|
81
|
+
klass.register("mock.unregister", MockFormatter)
|
82
82
|
|
83
|
-
klass.unregister(
|
84
|
-
klass.registered?(
|
83
|
+
klass.unregister("mock.unregister", Hash)
|
84
|
+
klass.registered?("mock.unregister").should be_true
|
85
85
|
|
86
|
-
klass.unregister(
|
87
|
-
klass.registered?(
|
86
|
+
klass.unregister("mock.unregister", MockFormatter)
|
87
|
+
klass.registered?("mock.unregister").should be_false
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
91
|
context "calling formatters" do
|
92
92
|
it "should return nil if there is no formatter registered" do
|
93
|
-
klass.format(
|
93
|
+
klass.format("nonsense", {}).should be_nil
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should call the formatter if it is registered and use a value set in the initializer" do
|
97
|
-
klass.format(
|
97
|
+
klass.format("mock", {}).should eq ["title", "some value"]
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|