inst_statsd 3.0.2 → 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 +1 -1
- 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 +20 -20
- data/lib/inst_statsd/request_tracking.rb +19 -18
- data/lib/inst_statsd/sql_tracker.rb +9 -11
- data/lib/inst_statsd/statsd.rb +61 -52
- data/lib/inst_statsd/version.rb +1 -1
- data/lib/inst_statsd.rb +36 -29
- 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 +25 -24
- 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 +90 -93
- 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 +118 -101
- data/spec/spec_helper.rb +2 -2
- metadata +44 -28
data/lib/inst_statsd.rb
CHANGED
@@ -1,24 +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
|
21
|
-
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"
|
22
30
|
|
23
31
|
class << self
|
24
32
|
def settings
|
@@ -33,11 +41,11 @@ module InstStatsd
|
|
33
41
|
return nil if value.nil?
|
34
42
|
|
35
43
|
validated = {}
|
44
|
+
regexp_methods = %i[mask negative_mask]
|
36
45
|
value.each do |k, v|
|
37
|
-
unless VALID_SETTINGS.include?(k.to_sym)
|
38
|
-
|
39
|
-
|
40
|
-
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)
|
41
49
|
validated[k.to_sym] = v
|
42
50
|
end
|
43
51
|
|
@@ -45,19 +53,17 @@ module InstStatsd
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def env_settings(env = ENV)
|
48
|
-
dog_tags = JSON.parse(env[
|
56
|
+
dog_tags = JSON.parse(env["INST_DOG_TAGS"]).to_h if env["INST_DOG_TAGS"]
|
49
57
|
config = {
|
50
|
-
host: env.fetch(
|
51
|
-
port: env.fetch(
|
52
|
-
namespace: env.fetch(
|
53
|
-
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),
|
54
62
|
dog_tags: dog_tags
|
55
63
|
}
|
56
|
-
config.
|
64
|
+
config.compact!
|
57
65
|
convert_bool(config, :append_hostname)
|
58
|
-
if config[:host]
|
59
|
-
config
|
60
|
-
elsif config[:dog_tags]
|
66
|
+
if config[:host] || config[:dog_tags]
|
61
67
|
config
|
62
68
|
else
|
63
69
|
{}
|
@@ -67,11 +73,12 @@ module InstStatsd
|
|
67
73
|
def convert_bool(hash, key)
|
68
74
|
value = hash[key]
|
69
75
|
return if value.nil?
|
70
|
-
|
76
|
+
|
77
|
+
unless ["true", "True", "false", "False", true, false].include?(value)
|
71
78
|
message = "#{key} must be a boolean, or the string representation of a boolean, got: #{value}"
|
72
79
|
raise InstStatsd::ConfigurationError, message
|
73
80
|
end
|
74
|
-
hash[key] = [
|
81
|
+
hash[key] = ["true", "True", true].include?(value)
|
75
82
|
end
|
76
83
|
end
|
77
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
|
@@ -1,22 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "datadog/statsd"
|
4
5
|
|
5
6
|
RSpec.describe InstStatsd::Event do
|
6
7
|
include described_class
|
7
8
|
|
8
9
|
let(:title) { "Title" }
|
9
|
-
let(:text) {"Some text."}
|
10
|
+
let(:text) { "Some text." }
|
10
11
|
|
11
|
-
let(:instance) {
|
12
|
+
let(:instance) { instance_double(Datadog::Statsd) }
|
12
13
|
let(:data_dog?) { true }
|
13
14
|
let(:dog_tags) { {} }
|
14
15
|
let(:opts) { {} }
|
15
16
|
|
16
|
-
describe
|
17
|
-
subject { event(title, text, opts) }
|
17
|
+
describe "#event" do
|
18
|
+
subject { event(title, text, **opts) }
|
18
19
|
|
19
|
-
context
|
20
|
+
context "with title and text only" do
|
20
21
|
let(:opts) { {} }
|
21
22
|
|
22
23
|
it 'invokes "event" on the instance with title and text' do
|
@@ -30,7 +31,7 @@ RSpec.describe InstStatsd::Event do
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
context
|
34
|
+
context "with alert_type set" do
|
34
35
|
let(:opts) { { alert_type: :error } }
|
35
36
|
|
36
37
|
it 'invokes "event" on the instance with expected arguments' do
|
@@ -45,7 +46,7 @@ RSpec.describe InstStatsd::Event do
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
context
|
49
|
+
context "with priority set" do
|
49
50
|
let(:opts) { { priority: :low } }
|
50
51
|
|
51
52
|
it 'invokes "event" on the instance with expected arguments' do
|
@@ -60,7 +61,7 @@ RSpec.describe InstStatsd::Event do
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
context
|
64
|
+
context "with date_happened set" do
|
64
65
|
let(:opts) { { date_happened: date_happened } }
|
65
66
|
let(:date_happened) { Time.now.to_i }
|
66
67
|
|
@@ -76,10 +77,10 @@ RSpec.describe InstStatsd::Event do
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
context
|
80
|
+
context "with an invalid type set" do
|
80
81
|
let(:opts) { { type: :banana } }
|
81
82
|
|
82
|
-
it
|
83
|
+
it "does not sent the invalid aggregation key" do
|
83
84
|
expect(instance).to receive(:event).with(
|
84
85
|
title,
|
85
86
|
text,
|
@@ -90,35 +91,35 @@ RSpec.describe InstStatsd::Event do
|
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
|
-
context
|
94
|
+
context "with a valid type set" do
|
94
95
|
let(:opts) { { type: :deploy } }
|
95
96
|
|
96
|
-
it
|
97
|
+
it "sets the valid aggregation key" do
|
97
98
|
expect(instance).to receive(:event).with(
|
98
99
|
title,
|
99
100
|
text,
|
100
|
-
tags: {type: :deploy}
|
101
|
+
tags: { type: :deploy }
|
101
102
|
)
|
102
103
|
|
103
104
|
subject
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
|
-
context
|
108
|
-
let(:opts) { { tags: { project:
|
108
|
+
context "with custom tags" do
|
109
|
+
let(:opts) { { tags: { project: "cool-project" } } }
|
109
110
|
|
110
111
|
it 'invokes "event" on the instance with expected arguments' do
|
111
112
|
expect(instance).to receive(:event).with(
|
112
113
|
title,
|
113
114
|
text,
|
114
|
-
tags: { project:
|
115
|
+
tags: { project: "cool-project" }
|
115
116
|
)
|
116
117
|
|
117
118
|
subject
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
121
|
-
context
|
122
|
+
context "with all opts set" do
|
122
123
|
let(:date_happened) { Time.now.to_i }
|
123
124
|
let(:opts) do
|
124
125
|
{
|
@@ -126,28 +127,28 @@ RSpec.describe InstStatsd::Event do
|
|
126
127
|
alert_type: :warning,
|
127
128
|
priority: :low,
|
128
129
|
date_happened: date_happened,
|
129
|
-
tags: { foo:
|
130
|
+
tags: { foo: "bar" }
|
130
131
|
}
|
131
132
|
end
|
132
133
|
|
133
|
-
it
|
134
|
+
it "sets all arguments" do
|
134
135
|
expect(instance).to receive(:event).with(
|
135
136
|
title,
|
136
137
|
text,
|
137
138
|
alert_type: :warning,
|
138
139
|
priority: :low,
|
139
140
|
date_happened: date_happened,
|
140
|
-
tags: { foo:
|
141
|
+
tags: { foo: "bar", type: :deploy }
|
141
142
|
)
|
142
143
|
|
143
144
|
subject
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
147
|
-
context
|
148
|
+
context "when the instance is not DataDog" do
|
148
149
|
let(:data_dog?) { false }
|
149
150
|
|
150
|
-
it { is_expected.to
|
151
|
+
it { is_expected.to be_nil }
|
151
152
|
|
152
153
|
it 'does not invoke "event" on the instance' do
|
153
154
|
expect(instance).not_to receive(:event)
|
@@ -156,4 +157,4 @@ RSpec.describe InstStatsd::Event do
|
|
156
157
|
end
|
157
158
|
end
|
158
159
|
end
|
159
|
-
end
|
160
|
+
end
|