inst_statsd 2.2.0 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/inst_statsd/block_stat.rb +14 -14
- data/lib/inst_statsd/block_tracking.rb +12 -13
- data/lib/inst_statsd/counter.rb +2 -4
- data/lib/inst_statsd/default_tracking.rb +30 -27
- data/lib/inst_statsd/event.rb +64 -0
- data/lib/inst_statsd/null_logger.rb +3 -4
- data/lib/inst_statsd/request_logger.rb +4 -6
- data/lib/inst_statsd/request_stat.rb +26 -14
- data/lib/inst_statsd/request_tracking.rb +19 -18
- data/lib/inst_statsd/sql_tracker.rb +9 -11
- data/lib/inst_statsd/statsd.rb +63 -52
- data/lib/inst_statsd/version.rb +5 -0
- data/lib/inst_statsd.rb +36 -28
- data/spec/inst_statsd/block_stat_spec.rb +2 -2
- data/spec/inst_statsd/block_tracking_spec.rb +66 -46
- data/spec/inst_statsd/counter_spec.rb +21 -23
- data/spec/inst_statsd/event_spec.rb +160 -0
- data/spec/inst_statsd/inst_statsd_spec.rb +85 -81
- data/spec/inst_statsd/null_logger_spec.rb +11 -13
- data/spec/inst_statsd/request_logger_spec.rb +43 -50
- data/spec/inst_statsd/request_stat_spec.rb +98 -84
- data/spec/inst_statsd/request_tracking_spec.rb +6 -7
- data/spec/inst_statsd/sql_tracker_spec.rb +29 -31
- data/spec/inst_statsd/statsd_spec.rb +126 -87
- data/spec/spec_helper.rb +2 -2
- metadata +67 -35
data/lib/inst_statsd.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "statsd"
|
4
4
|
|
5
5
|
module InstStatsd
|
6
|
-
VALID_SETTINGS = %i[host
|
7
|
-
|
6
|
+
VALID_SETTINGS = %i[host
|
7
|
+
port
|
8
|
+
namespace
|
9
|
+
append_hostname
|
10
|
+
mask
|
11
|
+
negative_mask
|
12
|
+
batch_size
|
13
|
+
batch_byte_size
|
14
|
+
dog_tags
|
15
|
+
socket_path].freeze
|
8
16
|
|
9
17
|
class ConfigurationError < StandardError; end
|
10
18
|
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
19
|
+
require "inst_statsd/event"
|
20
|
+
require "inst_statsd/statsd"
|
21
|
+
require "inst_statsd/block_stat"
|
22
|
+
require "inst_statsd/block_tracking"
|
23
|
+
require "inst_statsd/request_stat"
|
24
|
+
require "inst_statsd/counter"
|
25
|
+
require "inst_statsd/sql_tracker"
|
26
|
+
require "inst_statsd/default_tracking"
|
27
|
+
require "inst_statsd/request_logger"
|
28
|
+
require "inst_statsd/request_tracking"
|
29
|
+
require "inst_statsd/null_logger"
|
21
30
|
|
22
31
|
class << self
|
23
32
|
def settings
|
@@ -32,11 +41,11 @@ module InstStatsd
|
|
32
41
|
return nil if value.nil?
|
33
42
|
|
34
43
|
validated = {}
|
44
|
+
regexp_methods = %i[mask negative_mask]
|
35
45
|
value.each do |k, v|
|
36
|
-
unless VALID_SETTINGS.include?(k.to_sym)
|
37
|
-
|
38
|
-
|
39
|
-
v = Regexp.new(v) if %i[mask negative_mask].include?(k.to_sym) && v.is_a?(String)
|
46
|
+
raise InstStatsd::ConfigurationError, "Invalid key: #{k}" unless VALID_SETTINGS.include?(k.to_sym)
|
47
|
+
|
48
|
+
v = Regexp.new(v) if regexp_methods.include?(k.to_sym) && v.is_a?(String)
|
40
49
|
validated[k.to_sym] = v
|
41
50
|
end
|
42
51
|
|
@@ -44,19 +53,17 @@ module InstStatsd
|
|
44
53
|
end
|
45
54
|
|
46
55
|
def env_settings(env = ENV)
|
47
|
-
dog_tags = JSON.parse(env[
|
56
|
+
dog_tags = JSON.parse(env["INST_DOG_TAGS"]).to_h if env["INST_DOG_TAGS"]
|
48
57
|
config = {
|
49
|
-
host: env.fetch(
|
50
|
-
port: env.fetch(
|
51
|
-
namespace: env.fetch(
|
52
|
-
append_hostname: env.fetch(
|
58
|
+
host: env.fetch("INST_STATSD_HOST", nil),
|
59
|
+
port: env.fetch("INST_STATSD_PORT", nil),
|
60
|
+
namespace: env.fetch("INST_STATSD_NAMESPACE", nil),
|
61
|
+
append_hostname: env.fetch("INST_STATSD_APPEND_HOSTNAME", nil),
|
53
62
|
dog_tags: dog_tags
|
54
63
|
}
|
55
|
-
config.
|
64
|
+
config.compact!
|
56
65
|
convert_bool(config, :append_hostname)
|
57
|
-
if config[:host]
|
58
|
-
config
|
59
|
-
elsif config[:dog_tags]
|
66
|
+
if config[:host] || config[:dog_tags]
|
60
67
|
config
|
61
68
|
else
|
62
69
|
{}
|
@@ -66,11 +73,12 @@ module InstStatsd
|
|
66
73
|
def convert_bool(hash, key)
|
67
74
|
value = hash[key]
|
68
75
|
return if value.nil?
|
69
|
-
|
76
|
+
|
77
|
+
unless ["true", "True", "false", "False", true, false].include?(value)
|
70
78
|
message = "#{key} must be a boolean, or the string representation of a boolean, got: #{value}"
|
71
79
|
raise InstStatsd::ConfigurationError, message
|
72
80
|
end
|
73
|
-
hash[key] = [
|
81
|
+
hash[key] = ["true", "True", true].include?(value)
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe InstStatsd::BlockStat do
|
6
6
|
it "track exclusives correctly" do
|
7
7
|
stat = InstStatsd::BlockStat.new("key")
|
8
|
-
stat.stats[
|
8
|
+
stat.stats["total"] = 5.0
|
9
9
|
stat.subtract_exclusives("total" => 1.5)
|
10
10
|
stat.subtract_exclusives("total" => 2.1)
|
11
11
|
expect(stat.exclusive_stats).to eql("total" => 1.4)
|
@@ -1,62 +1,82 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe InstStatsd::BlockTracking do
|
6
|
-
before(:all) do
|
6
|
+
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
|
7
7
|
InstStatsd::DefaultTracking.track_sql
|
8
8
|
end
|
9
9
|
|
10
10
|
it "works" do
|
11
|
-
statsd = double
|
12
|
-
allow(statsd).to receive(:timing).with(
|
13
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
11
|
+
statsd = double
|
12
|
+
allow(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} })
|
13
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, { short_stat: "mykey.sql.read", tags: {} })
|
14
14
|
|
15
|
-
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only:
|
16
|
-
ActiveSupport::Notifications.instrument(
|
15
|
+
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: "sql.read") do
|
16
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
it "works for data_dog" do
|
21
|
-
statsd = double
|
21
|
+
statsd = double
|
22
22
|
allow(statsd).to receive(:data_dog?).and_return true
|
23
|
-
allow(statsd).to receive(:timing).with(
|
24
|
-
|
23
|
+
allow(statsd).to receive(:timing).with("mykey.total",
|
24
|
+
anything,
|
25
|
+
{ short_stat: "mykey.total", tags: { app: "canvas", env: "prod" } })
|
26
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read",
|
27
|
+
1,
|
28
|
+
{ short_stat: "mykey.sql.read", tags: { app: "canvas", env: "prod" } })
|
25
29
|
|
26
|
-
InstStatsd::BlockTracking.track("mykey",
|
27
|
-
|
30
|
+
InstStatsd::BlockTracking.track("mykey",
|
31
|
+
statsd: statsd,
|
32
|
+
only: "sql.read",
|
33
|
+
tags: { app: "canvas", env: "prod" },
|
34
|
+
short_stat: "mykey") do
|
35
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
28
36
|
end
|
29
37
|
end
|
30
38
|
|
31
39
|
it "keeps track of exclusive stats too" do
|
32
|
-
statsd = double
|
33
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 2, {short_stat: "mykey.sql.read", tags: {}}).ordered
|
34
|
-
expect(statsd).to receive(:timing).with(
|
35
|
-
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read",
|
36
|
-
|
37
|
-
|
38
|
-
expect(statsd).to receive(:timing).with(
|
39
|
-
|
40
|
-
|
41
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read",
|
42
|
-
expect(statsd).to receive(:timing).with(
|
43
|
-
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read",
|
44
|
-
|
40
|
+
statsd = double
|
41
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 2, { short_stat: "mykey.sql.read", tags: {} }).ordered
|
42
|
+
expect(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} }).ordered
|
43
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read",
|
44
|
+
2,
|
45
|
+
{ short_stat: "mykey.exclusive.sql.read", tags: {} }).ordered
|
46
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.total",
|
47
|
+
anything,
|
48
|
+
{ short_stat: "mykey.exclusive.total", tags: {} }).ordered
|
49
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 2, { short_stat: "mykey.sql.read", tags: {} }).ordered
|
50
|
+
expect(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} }).ordered
|
51
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read",
|
52
|
+
2,
|
53
|
+
{ short_stat: "mykey.exclusive.sql.read", tags: {} }).ordered
|
54
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.total",
|
55
|
+
anything,
|
56
|
+
{ short_stat: "mykey.exclusive.total", tags: {} }).ordered
|
57
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 5, { short_stat: "mykey.sql.read", tags: {} }).ordered
|
58
|
+
expect(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} }).ordered
|
59
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.sql.read",
|
60
|
+
1,
|
61
|
+
{ short_stat: "mykey.exclusive.sql.read", tags: {} }).ordered
|
62
|
+
expect(statsd).to receive(:timing).with("mykey.exclusive.total",
|
63
|
+
anything,
|
64
|
+
{ short_stat: "mykey.exclusive.total", tags: {} }).ordered
|
45
65
|
|
46
|
-
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only:
|
47
|
-
ActiveSupport::Notifications.instrument(
|
48
|
-
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only:
|
49
|
-
ActiveSupport::Notifications.instrument(
|
50
|
-
ActiveSupport::Notifications.instrument(
|
66
|
+
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only: "sql.read") do
|
67
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
68
|
+
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only: "sql.read") do
|
69
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
70
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
51
71
|
end
|
52
|
-
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only:
|
53
|
-
ActiveSupport::Notifications.instrument(
|
54
|
-
ActiveSupport::Notifications.instrument(
|
72
|
+
InstStatsd::BlockTracking.track("mykey", category: :nested, statsd: statsd, only: "sql.read") do
|
73
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
74
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
55
75
|
end
|
56
76
|
end
|
57
77
|
end
|
58
78
|
|
59
|
-
context "mask" do
|
79
|
+
context "with a mask" do
|
60
80
|
after do
|
61
81
|
InstStatsd::BlockTracking.mask = nil
|
62
82
|
InstStatsd::BlockTracking.negative_mask = nil
|
@@ -64,26 +84,26 @@ describe InstStatsd::BlockTracking do
|
|
64
84
|
|
65
85
|
it "only tracks keys that match the mask" do
|
66
86
|
InstStatsd::BlockTracking.mask = /mykey/
|
67
|
-
statsd = double
|
68
|
-
allow(statsd).to receive(:timing).with(
|
69
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
87
|
+
statsd = double
|
88
|
+
allow(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} })
|
89
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, { short_stat: "mykey.sql.read", tags: {} })
|
70
90
|
|
71
|
-
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only:
|
72
|
-
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only:
|
73
|
-
ActiveSupport::Notifications.instrument(
|
91
|
+
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: "sql.read") do
|
92
|
+
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only: "sql.read") do
|
93
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
74
94
|
end
|
75
95
|
end
|
76
96
|
end
|
77
97
|
|
78
98
|
it "doesn't track keys that match the negative mask" do
|
79
99
|
InstStatsd::BlockTracking.negative_mask = /ignoreme/
|
80
|
-
statsd = double
|
81
|
-
allow(statsd).to receive(:timing).with(
|
82
|
-
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, {short_stat: "mykey.sql.read", tags: {}})
|
100
|
+
statsd = double
|
101
|
+
allow(statsd).to receive(:timing).with("mykey.total", anything, { short_stat: "mykey.total", tags: {} })
|
102
|
+
expect(statsd).to receive(:timing).with("mykey.sql.read", 1, { short_stat: "mykey.sql.read", tags: {} })
|
83
103
|
|
84
|
-
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only:
|
85
|
-
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only:
|
86
|
-
ActiveSupport::Notifications.instrument(
|
104
|
+
InstStatsd::BlockTracking.track("mykey", statsd: statsd, only: "sql.read") do
|
105
|
+
InstStatsd::BlockTracking.track("ignoreme", statsd: statsd, only: "sql.read") do
|
106
|
+
ActiveSupport::Notifications.instrument("sql.active_record", name: "LOAD", sql: "SELECT * FROM users") { nil }
|
87
107
|
end
|
88
108
|
end
|
89
109
|
end
|
@@ -1,60 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe InstStatsd::Counter do
|
6
|
-
|
7
|
-
let(:subject) { InstStatsd::Counter.new('test', ['foo']) }
|
6
|
+
subject { InstStatsd::Counter.new("test", ["foo"]) }
|
8
7
|
|
9
8
|
describe "#accepted_name?" do
|
10
|
-
it
|
11
|
-
expect(subject.accepted_name?(
|
9
|
+
it "should return true for names not in blocked_names" do
|
10
|
+
expect(subject.accepted_name?("bar")).to be true
|
12
11
|
end
|
13
12
|
|
14
|
-
it
|
15
|
-
expect(subject.accepted_name?(
|
13
|
+
it "should return false for names in blocked_names" do
|
14
|
+
expect(subject.accepted_name?("foo")).to be false
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
19
|
-
expect(subject.accepted_name?(
|
17
|
+
it "should return true for empty string names" do
|
18
|
+
expect(subject.accepted_name?("")).to be true
|
20
19
|
end
|
21
20
|
|
22
|
-
it
|
23
|
-
expect(subject.accepted_name?(nil)).to
|
21
|
+
it "should return true for empty nil names" do
|
22
|
+
expect(subject.accepted_name?(nil)).to be true
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
describe "#track" do
|
28
|
-
it
|
27
|
+
it "should increment when given allowed names" do
|
29
28
|
cookie = subject.start
|
30
|
-
subject.track(
|
31
|
-
subject.track(
|
29
|
+
subject.track("bar")
|
30
|
+
subject.track("baz")
|
32
31
|
expect(subject.finalize_count(cookie)).to eq 2
|
33
32
|
end
|
34
33
|
|
35
|
-
it
|
34
|
+
it "should not increment when given a blocked name" do
|
36
35
|
cookie = subject.start
|
37
|
-
subject.track(
|
38
|
-
subject.track(
|
36
|
+
subject.track("foo") # shouldn't count as foo is a blocked name
|
37
|
+
subject.track("name")
|
39
38
|
expect(subject.finalize_count(cookie)).to eq 1
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
42
|
describe "#finalize_count" do
|
44
|
-
it
|
43
|
+
it "should return the current count" do
|
45
44
|
cookie = subject.start
|
46
|
-
subject.track(
|
45
|
+
subject.track("bar")
|
47
46
|
expect(subject.finalize_count(cookie)).to eq 1
|
48
47
|
end
|
49
48
|
|
50
|
-
it
|
49
|
+
it "should not interfere with multiple people using the object" do
|
51
50
|
cookie1 = subject.start
|
52
|
-
subject.track(
|
51
|
+
subject.track("bar")
|
53
52
|
cookie2 = subject.start
|
54
|
-
subject.track(
|
53
|
+
subject.track("bar")
|
55
54
|
expect(subject.finalize_count(cookie1)).to eq 2
|
56
55
|
expect(subject.finalize_count(cookie2)).to eq 1
|
57
56
|
end
|
58
57
|
end
|
59
|
-
|
60
58
|
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "datadog/statsd"
|
5
|
+
|
6
|
+
RSpec.describe InstStatsd::Event do
|
7
|
+
include described_class
|
8
|
+
|
9
|
+
let(:title) { "Title" }
|
10
|
+
let(:text) { "Some text." }
|
11
|
+
|
12
|
+
let(:instance) { instance_double(Datadog::Statsd) }
|
13
|
+
let(:data_dog?) { true }
|
14
|
+
let(:dog_tags) { {} }
|
15
|
+
let(:opts) { {} }
|
16
|
+
|
17
|
+
describe "#event" do
|
18
|
+
subject { event(title, text, **opts) }
|
19
|
+
|
20
|
+
context "with title and text only" do
|
21
|
+
let(:opts) { {} }
|
22
|
+
|
23
|
+
it 'invokes "event" on the instance with title and text' do
|
24
|
+
expect(instance).to receive(:event).with(
|
25
|
+
title,
|
26
|
+
text,
|
27
|
+
tags: {}
|
28
|
+
)
|
29
|
+
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with alert_type set" do
|
35
|
+
let(:opts) { { alert_type: :error } }
|
36
|
+
|
37
|
+
it 'invokes "event" on the instance with expected arguments' do
|
38
|
+
expect(instance).to receive(:event).with(
|
39
|
+
title,
|
40
|
+
text,
|
41
|
+
alert_type: :error,
|
42
|
+
tags: {}
|
43
|
+
)
|
44
|
+
|
45
|
+
subject
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with priority set" do
|
50
|
+
let(:opts) { { priority: :low } }
|
51
|
+
|
52
|
+
it 'invokes "event" on the instance with expected arguments' do
|
53
|
+
expect(instance).to receive(:event).with(
|
54
|
+
title,
|
55
|
+
text,
|
56
|
+
priority: :low,
|
57
|
+
tags: {}
|
58
|
+
)
|
59
|
+
|
60
|
+
subject
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with date_happened set" do
|
65
|
+
let(:opts) { { date_happened: date_happened } }
|
66
|
+
let(:date_happened) { Time.now.to_i }
|
67
|
+
|
68
|
+
it 'invokes "event" on the instance with expected arguments' do
|
69
|
+
expect(instance).to receive(:event).with(
|
70
|
+
title,
|
71
|
+
text,
|
72
|
+
date_happened: date_happened,
|
73
|
+
tags: {}
|
74
|
+
)
|
75
|
+
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with an invalid type set" do
|
81
|
+
let(:opts) { { type: :banana } }
|
82
|
+
|
83
|
+
it "does not sent the invalid aggregation key" do
|
84
|
+
expect(instance).to receive(:event).with(
|
85
|
+
title,
|
86
|
+
text,
|
87
|
+
tags: {}
|
88
|
+
)
|
89
|
+
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "with a valid type set" do
|
95
|
+
let(:opts) { { type: :deploy } }
|
96
|
+
|
97
|
+
it "sets the valid aggregation key" do
|
98
|
+
expect(instance).to receive(:event).with(
|
99
|
+
title,
|
100
|
+
text,
|
101
|
+
tags: { type: :deploy }
|
102
|
+
)
|
103
|
+
|
104
|
+
subject
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with custom tags" do
|
109
|
+
let(:opts) { { tags: { project: "cool-project" } } }
|
110
|
+
|
111
|
+
it 'invokes "event" on the instance with expected arguments' do
|
112
|
+
expect(instance).to receive(:event).with(
|
113
|
+
title,
|
114
|
+
text,
|
115
|
+
tags: { project: "cool-project" }
|
116
|
+
)
|
117
|
+
|
118
|
+
subject
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with all opts set" do
|
123
|
+
let(:date_happened) { Time.now.to_i }
|
124
|
+
let(:opts) do
|
125
|
+
{
|
126
|
+
type: :deploy,
|
127
|
+
alert_type: :warning,
|
128
|
+
priority: :low,
|
129
|
+
date_happened: date_happened,
|
130
|
+
tags: { foo: "bar" }
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
it "sets all arguments" do
|
135
|
+
expect(instance).to receive(:event).with(
|
136
|
+
title,
|
137
|
+
text,
|
138
|
+
alert_type: :warning,
|
139
|
+
priority: :low,
|
140
|
+
date_happened: date_happened,
|
141
|
+
tags: { foo: "bar", type: :deploy }
|
142
|
+
)
|
143
|
+
|
144
|
+
subject
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when the instance is not DataDog" do
|
149
|
+
let(:data_dog?) { false }
|
150
|
+
|
151
|
+
it { is_expected.to be_nil }
|
152
|
+
|
153
|
+
it 'does not invoke "event" on the instance' do
|
154
|
+
expect(instance).not_to receive(:event)
|
155
|
+
|
156
|
+
subject
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|