inst_statsd 2.3.0 → 2.4.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: 568ce7b0b1164ceb930ba4c27604d3600f3afc9faf9486fa55ed315c3e1b6e90
4
- data.tar.gz: e8970517048f627c0449ba8fa241adaae49b9aa37b3a4faa5047aa64e67f07d6
3
+ metadata.gz: 8b3f7337500a808963c072d5a5f752cdb4c1934bfdbb597fb926bbde54b1ee7f
4
+ data.tar.gz: b6375958a56e88a8a0c1ffb766ae8ec31f517071f8032b8ef4947301aac9cbf8
5
5
  SHA512:
6
- metadata.gz: 92c65a63134c03d227481e0fca2cf23e438268dd8fa59a124ac95795c7e3ec304ac6d7052d7e9e0270cdfdb89ff7bba24543b4021fdfed3dc098fedb6951364a
7
- data.tar.gz: 53087ac5aa2d2efe2af74d037ed18a0723774b38e17e3ddb34a8de2b5f67ec74620ef33c02737f3393a1faaf48c81ff5cd0cbfb217f408eb57b249f97ed312d4
6
+ metadata.gz: 23d76e604d9a734e6d1f8530ddbf169a0b6f8e429bdcfe6c15b474da4a9ce6d23e1bfcaef2657c7d7bbdb15ab8a33dc633a388712fe6e1900a3b52b132bbdab8
7
+ data.tar.gz: eec92096bc95d50b22cc2f2562d71f4843fa31b00578f34c5c46897a4a83f20666ff3dd47ad5be98c0d014c5ee6f533611047f91d0b6e60969c14b01388387f4
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InstStatsd
4
+ # Mix-in methods for supporting DataDog events
5
+ # See https://docs.datadoghq.com/service_management/events/
6
+ module Event
7
+ SUPPORTED_TYPES = %i[
8
+ deploy
9
+ feature_disabled
10
+ feature_enabled
11
+ provision
12
+ refresh
13
+ ].freeze
14
+
15
+ def instance; end
16
+ def data_dog?; end
17
+ def dog_tags; end
18
+
19
+ # This end point allows you to post events to the DatDog event stream.
20
+ #
21
+ # @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"
25
+ # @param [Hash] :tags tags to be added to event. Note that the
26
+ # environment, service, and other data are automatically
27
+ # added as tags for you without specifying them here.
28
+ # @param [Integer, String, nil] :date_happened (nil) Assign a timestamp
29
+ # to the event. Default is now when none
30
+ # @param [String, nil] :priority ('normal') Can be "normal" or "low"
31
+ # @param [String, nil] :alert_type ('info') Can be "error", "warning", "info" or "success".
32
+ #
33
+ # @example Report an event:
34
+ # InstStatsd::Statsd.event(
35
+ # "Quiz API Deploy",
36
+ # "<release> was deployed to Quiz API",
37
+ # tags: {foo: 'bar'},
38
+ # type: 'deploy',
39
+ # alert_type: :success
40
+ # )
41
+ def event(title, text, type: nil, tags: {}, alert_type: nil, priority: nil, date_happened: nil)
42
+ return unless instance && data_dog?
43
+
44
+ instance.event(
45
+ title,
46
+ text,
47
+ {
48
+ alert_type: alert_type,
49
+ priority: priority,
50
+ date_happened: date_happened,
51
+ tags: tags_from_opts(tags, type, dog_tags)
52
+ }.compact
53
+ )
54
+ end
55
+
56
+ private
57
+
58
+ def tags_from_opts(tags, type, dd_tags)
59
+ custom_tags = tags.merge(dd_tags)
60
+ custom_tags[:type] = type if SUPPORTED_TYPES.include? type
61
+ custom_tags.compact
62
+ end
63
+ end
64
+ end
@@ -24,6 +24,8 @@
24
24
 
25
25
  module InstStatsd
26
26
  module Statsd
27
+ extend InstStatsd::Event
28
+
27
29
  # replace "." in key names with another character to avoid creating spurious sub-folders in graphite
28
30
  def self.escape(str, replacement = '_')
29
31
  str.respond_to?(:gsub) ? str.gsub('.', replacement) : str
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InstStatsd
4
+ VERSION = "2.4.0"
5
+ end
data/lib/inst_statsd.rb CHANGED
@@ -8,6 +8,7 @@ module InstStatsd
8
8
 
9
9
  class ConfigurationError < StandardError; end
10
10
 
11
+ require 'inst_statsd/event'
11
12
  require 'inst_statsd/statsd'
12
13
  require 'inst_statsd/block_stat'
13
14
  require 'inst_statsd/block_tracking'
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe InstStatsd::Event do
6
+ include described_class
7
+
8
+ let(:title) { "Title" }
9
+ let(:text) {"Some text."}
10
+
11
+ let(:instance) { double }
12
+ let(:data_dog?) { true }
13
+ let(:dog_tags) { {} }
14
+ let(:opts) { {} }
15
+
16
+ describe '#event' do
17
+ subject { event(title, text, opts) }
18
+
19
+ context 'with title and text only' do
20
+ let(:opts) { {} }
21
+
22
+ it 'invokes "event" on the instance with title and text' do
23
+ expect(instance).to receive(:event).with(
24
+ title,
25
+ text,
26
+ tags: {}
27
+ )
28
+
29
+ subject
30
+ end
31
+ end
32
+
33
+ context 'with alert_type set' do
34
+ let(:opts) { { alert_type: :error } }
35
+
36
+ it 'invokes "event" on the instance with expected arguments' do
37
+ expect(instance).to receive(:event).with(
38
+ title,
39
+ text,
40
+ alert_type: :error,
41
+ tags: {}
42
+ )
43
+
44
+ subject
45
+ end
46
+ end
47
+
48
+ context 'with priority set' do
49
+ let(:opts) { { priority: :low } }
50
+
51
+ it 'invokes "event" on the instance with expected arguments' do
52
+ expect(instance).to receive(:event).with(
53
+ title,
54
+ text,
55
+ priority: :low,
56
+ tags: {}
57
+ )
58
+
59
+ subject
60
+ end
61
+ end
62
+
63
+ context 'with date_happened set' do
64
+ let(:opts) { { date_happened: date_happened } }
65
+ let(:date_happened) { Time.now.to_i }
66
+
67
+ it 'invokes "event" on the instance with expected arguments' do
68
+ expect(instance).to receive(:event).with(
69
+ title,
70
+ text,
71
+ date_happened: date_happened,
72
+ tags: {}
73
+ )
74
+
75
+ subject
76
+ end
77
+ end
78
+
79
+ context 'with an invalid type set' do
80
+ let(:opts) { { type: :banana } }
81
+
82
+ it 'does not sent the invalid aggregation key' do
83
+ expect(instance).to receive(:event).with(
84
+ title,
85
+ text,
86
+ tags: {}
87
+ )
88
+
89
+ subject
90
+ end
91
+ end
92
+
93
+ context 'with a valid type set' do
94
+ let(:opts) { { type: :deploy } }
95
+
96
+ it 'sets the valid aggregation key' do
97
+ expect(instance).to receive(:event).with(
98
+ title,
99
+ text,
100
+ tags: {type: :deploy}
101
+ )
102
+
103
+ subject
104
+ end
105
+ end
106
+
107
+ context 'with custom tags' do
108
+ let(:opts) { { tags: { project: 'cool-project'} } }
109
+
110
+ it 'invokes "event" on the instance with expected arguments' do
111
+ expect(instance).to receive(:event).with(
112
+ title,
113
+ text,
114
+ tags: { project: 'cool-project' }
115
+ )
116
+
117
+ subject
118
+ end
119
+ end
120
+
121
+ context 'with all opts set' do
122
+ let(:date_happened) { Time.now.to_i }
123
+ let(:opts) do
124
+ {
125
+ type: :deploy,
126
+ alert_type: :warning,
127
+ priority: :low,
128
+ date_happened: date_happened,
129
+ tags: { foo: 'bar' }
130
+ }
131
+ end
132
+
133
+ it 'sets all arguments' do
134
+ expect(instance).to receive(:event).with(
135
+ title,
136
+ text,
137
+ alert_type: :warning,
138
+ priority: :low,
139
+ date_happened: date_happened,
140
+ tags: { foo: 'bar', type: :deploy }
141
+ )
142
+
143
+ subject
144
+ end
145
+ end
146
+
147
+ context 'when the instance is not DataDog' do
148
+ let(:data_dog?) { false }
149
+
150
+ it { is_expected.to eq nil }
151
+
152
+ it 'does not invoke "event" on the instance' do
153
+ expect(instance).not_to receive(:event)
154
+
155
+ subject
156
+ end
157
+ end
158
+ end
159
+ end
@@ -10,6 +10,10 @@ describe InstStatsd::Statsd do
10
10
  InstStatsd::Statsd.reset_instance
11
11
  end
12
12
 
13
+ it 'includes the events module' do
14
+ expect(described_class).to respond_to :event
15
+ end
16
+
13
17
  it 'appends the hostname to stat names by default' do
14
18
  allow(InstStatsd::Statsd).to receive(:hostname).and_return('testhost')
15
19
  statsd = double
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: 2.3.0
4
+ version: 2.4.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: 2022-07-01 00:00:00.000000000 Z
12
+ date: 2023-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dogstatsd-ruby
@@ -136,15 +136,18 @@ files:
136
136
  - lib/inst_statsd/block_tracking.rb
137
137
  - lib/inst_statsd/counter.rb
138
138
  - lib/inst_statsd/default_tracking.rb
139
+ - lib/inst_statsd/event.rb
139
140
  - lib/inst_statsd/null_logger.rb
140
141
  - lib/inst_statsd/request_logger.rb
141
142
  - lib/inst_statsd/request_stat.rb
142
143
  - lib/inst_statsd/request_tracking.rb
143
144
  - lib/inst_statsd/sql_tracker.rb
144
145
  - lib/inst_statsd/statsd.rb
146
+ - lib/inst_statsd/version.rb
145
147
  - spec/inst_statsd/block_stat_spec.rb
146
148
  - spec/inst_statsd/block_tracking_spec.rb
147
149
  - spec/inst_statsd/counter_spec.rb
150
+ - spec/inst_statsd/event_spec.rb
148
151
  - spec/inst_statsd/inst_statsd_spec.rb
149
152
  - spec/inst_statsd/null_logger_spec.rb
150
153
  - spec/inst_statsd/request_logger_spec.rb
@@ -167,14 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
170
  requirements:
168
171
  - - ">="
169
172
  - !ruby/object:Gem::Version
170
- version: '2.3'
173
+ version: '2.7'
171
174
  required_rubygems_version: !ruby/object:Gem::Requirement
172
175
  requirements:
173
176
  - - ">="
174
177
  - !ruby/object:Gem::Version
175
178
  version: '0'
176
179
  requirements: []
177
- rubygems_version: 3.0.3
180
+ rubygems_version: 3.2.6
178
181
  signing_key:
179
182
  specification_version: 4
180
183
  summary: Statsd for Instructure
@@ -182,6 +185,7 @@ test_files:
182
185
  - spec/inst_statsd/block_stat_spec.rb
183
186
  - spec/inst_statsd/block_tracking_spec.rb
184
187
  - spec/inst_statsd/counter_spec.rb
188
+ - spec/inst_statsd/event_spec.rb
185
189
  - spec/inst_statsd/inst_statsd_spec.rb
186
190
  - spec/inst_statsd/null_logger_spec.rb
187
191
  - spec/inst_statsd/request_logger_spec.rb