inst_statsd 3.0.5 → 3.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a33a17cc0b4ff4ceba7edeb8b326e165a91a4accdf95d5b8452e5e015df793e5
4
- data.tar.gz: e602f9889485fa588d14e8457f7cddcbe075be733f9075594a663c517ab3f07c
3
+ metadata.gz: 57fa28e5cb8fa8bc63d35ca8233d41b3f79f58107c266b708f7d9c60e38d7f81
4
+ data.tar.gz: 45e23f3284b62308099fb6ab7167ef7036d4bbc4a87fb32dcf70a1bd246674b6
5
5
  SHA512:
6
- metadata.gz: b4488ce5d63fb8e490ff5be51fc18e2ab36b0af52d4e0788735ea2c580fd3b4d8d02db4a4bf377c1c43e6847c8a1d5bec6719d8073a38129b91f75871a4a6773
7
- data.tar.gz: 171e4007599cef67ad980034ab702d6575891ccc286d7769df11ce264fd93a6e61df29d542fffd39d094171ea0e4703c2d9d73941dbef203f359bc4bfaba028c
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
@@ -150,6 +150,10 @@ module InstStatsd
150
150
  @data_dog
151
151
  end
152
152
 
153
+ def self.initialized?
154
+ defined?(@statsd)
155
+ end
156
+
153
157
  def self.reset_instance
154
158
  remove_instance_variable(:@statsd) if defined?(@statsd)
155
159
  Thread.current[:inst_statsd] = nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstStatsd
4
- VERSION = "3.0.5"
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.5
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-09-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