inst_statsd 3.0.6 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f7ff23c72ad7a2d4055a5b511bc358d452d596b5a70b91b48dbab2837b57789
4
- data.tar.gz: e90e0dafba21a6cd519ab4341963007132be3e7722bc81d8d013f250c3794cc4
3
+ metadata.gz: 57fa28e5cb8fa8bc63d35ca8233d41b3f79f58107c266b708f7d9c60e38d7f81
4
+ data.tar.gz: 45e23f3284b62308099fb6ab7167ef7036d4bbc4a87fb32dcf70a1bd246674b6
5
5
  SHA512:
6
- metadata.gz: 721e8a6e1805deb8c63a2ccc9a69d29621e99d4e699f7faf9fac7d96e86396a358da68f49d391586bbda59414ce61143139f6bc551fdc8a85987c2fb7d579ec6
7
- data.tar.gz: 57eabc93c85a1e6f2bd92632d8e1aa78ec365236c4d54f3ad3feffd934fba500f6357f4661b4172064376c825ff720bfde4f9428442858fa19d22f1e9350cad2
6
+ metadata.gz: 79d3b39e1de95726c07a623f2d317fa512f9d3fee346afbc26b1ec8435919783a46887292e54777a9e7ee19ca51314aa8e703729fa5bc5fc45bef121eebffe56
7
+ data.tar.gz: 3de309abbcc308546567c280c98c910b34cece7dd27dad1cea4911e3b5f7fb263a997f26128bfa1541ae5d23e87c93f36da98b8c13790c42734980444446f42a
@@ -4,24 +4,55 @@ module InstStatsd
4
4
  # Mix-in methods for supporting DataDog events
5
5
  # See https://docs.datadoghq.com/service_management/events/
6
6
  module Event
7
- SUPPORTED_TYPES = %i[
8
- deploy
9
- feature_disabled
10
- feature_enabled
11
- provision
12
- refresh
7
+ DEPLOY_EVENT = "deploy"
8
+ FEATURE_EVENT = "feature"
9
+ PROVISION_EVENT = "provision"
10
+ REFRESH_EVENT = "refresh"
11
+
12
+ SUPPORTED_TYPES = [
13
+ DEPLOY_EVENT,
14
+ FEATURE_EVENT,
15
+ PROVISION_EVENT,
16
+ REFRESH_EVENT
13
17
  ].freeze
14
18
 
15
19
  def instance; end
16
20
  def data_dog?; end
17
21
  def dog_tags; end
18
22
 
19
- # This end point allows you to post events to the DatDog event stream.
23
+ # A dynamic method that uses the class constants to create a specific event type
24
+ #
25
+ # @param [String] title Event title
26
+ # @param [String] description Event description. Supports newlines (+\n+)
27
+ # @param [Hash] :tags tags to be added to event. Note that the
28
+ # environment, service, and other data are automatically
29
+ # added as tags for you without specifying them here.
30
+ # @param [String, nil] :date_happened (nil) Assign a timestamp
31
+ #
32
+ # @example Report a flag flip event:
33
+ # InstStatsd::Statsd.feature_event(
34
+ # "Feature Flag Change",
35
+ # "Feature flag <flag_name> was flipped to <flag_state>",
36
+ # tags: {foo: 'bar'}
37
+ # )
38
+
39
+ SUPPORTED_TYPES.each do |event_name|
40
+ define_method("#{event_name}_event") do |*args, **kwargs|
41
+ event(
42
+ *args,
43
+ type: event_name,
44
+ alert_type: :success,
45
+ priority: :normal,
46
+ **kwargs
47
+ )
48
+ end
49
+ end
50
+
51
+ # This end point allows you to post events to the DataDog event stream.
20
52
  #
21
53
  # @param [String] title Event title
22
- # @param [String] text Event text. Supports newlines (+\n+)
23
- # @param [String, nil] :type Can be "deploy", "feature_disabled",
24
- # "feature_enabled", "provision", or "refresh"
54
+ # @param [String] description Event description. Supports newlines (+\n+)
55
+ # @param [String, nil] :type. It is recommended to use the constants
25
56
  # @param [Hash] :tags tags to be added to event. Note that the
26
57
  # environment, service, and other data are automatically
27
58
  # added as tags for you without specifying them here.
@@ -38,12 +69,12 @@ module InstStatsd
38
69
  # type: 'deploy',
39
70
  # alert_type: :success
40
71
  # )
41
- def event(title, text, type: nil, tags: {}, alert_type: nil, priority: nil, date_happened: nil)
72
+ def event(title, description, type: nil, tags: {}, alert_type: nil, priority: nil, date_happened: nil)
42
73
  return unless instance && data_dog?
43
74
 
44
75
  instance.event(
45
76
  title,
46
- text,
77
+ description,
47
78
  **{
48
79
  alert_type: alert_type,
49
80
  priority: priority,
@@ -57,7 +88,7 @@ module InstStatsd
57
88
 
58
89
  def tags_from_opts(tags, type, dd_tags)
59
90
  custom_tags = tags.merge(dd_tags)
60
- custom_tags[:type] = type.to_sym if SUPPORTED_TYPES.include? type&.to_sym
91
+ custom_tags[:type] = type
61
92
  custom_tags.compact
62
93
  end
63
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstStatsd
4
- VERSION = "3.0.6"
4
+ VERSION = "3.1.0"
5
5
  end
@@ -14,6 +14,49 @@ RSpec.describe InstStatsd::Event do
14
14
  let(:dog_tags) { {} }
15
15
  let(:opts) { {} }
16
16
 
17
+ describe "#feature_event" do
18
+ subject { feature_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
+ alert_type: :success,
28
+ priority: :normal,
29
+ tags: { type: InstStatsd::Event::FEATURE_EVENT }
30
+ )
31
+
32
+ subject
33
+ end
34
+ end
35
+
36
+ context "with all opts set" do
37
+ let(:date_happened) { Time.now.to_i }
38
+ let(:opts) do
39
+ {
40
+ date_happened: date_happened,
41
+ tags: { foo: "bar" }
42
+ }
43
+ end
44
+
45
+ it "sets all arguments" do
46
+ expect(instance).to receive(:event).with(
47
+ title,
48
+ text,
49
+ alert_type: :success,
50
+ priority: :normal,
51
+ date_happened: date_happened,
52
+ tags: { foo: "bar", type: InstStatsd::Event::FEATURE_EVENT }
53
+ )
54
+
55
+ subject
56
+ end
57
+ end
58
+ end
59
+
17
60
  describe "#event" do
18
61
  subject { event(title, text, **opts) }
19
62
 
@@ -77,28 +120,14 @@ RSpec.describe InstStatsd::Event do
77
120
  end
78
121
  end
79
122
 
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
123
  context "with a valid type set" do
95
- let(:opts) { { type: :deploy } }
124
+ let(:opts) { { type: InstStatsd::Event::DEPLOY_EVENT } }
96
125
 
97
126
  it "sets the valid aggregation key" do
98
127
  expect(instance).to receive(:event).with(
99
128
  title,
100
129
  text,
101
- tags: { type: :deploy }
130
+ tags: { type: InstStatsd::Event::DEPLOY_EVENT }
102
131
  )
103
132
 
104
133
  subject
@@ -112,7 +141,7 @@ RSpec.describe InstStatsd::Event do
112
141
  expect(instance).to receive(:event).with(
113
142
  title,
114
143
  text,
115
- tags: { type: :deploy }
144
+ tags: { type: InstStatsd::Event::DEPLOY_EVENT }
116
145
  )
117
146
 
118
147
  subject
@@ -137,7 +166,7 @@ RSpec.describe InstStatsd::Event do
137
166
  let(:date_happened) { Time.now.to_i }
138
167
  let(:opts) do
139
168
  {
140
- type: :deploy,
169
+ type: InstStatsd::Event::DEPLOY_EVENT,
141
170
  alert_type: :warning,
142
171
  priority: :low,
143
172
  date_happened: date_happened,
@@ -152,7 +181,7 @@ RSpec.describe InstStatsd::Event do
152
181
  alert_type: :warning,
153
182
  priority: :low,
154
183
  date_happened: date_happened,
155
- tags: { foo: "bar", type: :deploy }
184
+ tags: { foo: "bar", type: InstStatsd::Event::DEPLOY_EVENT }
156
185
  )
157
186
 
158
187
  subject
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst_statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Cloward
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-11-11 00:00:00.000000000 Z
12
+ date: 2024-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aroi