datadog-notifications 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +21 -0
- data/.rubocop.yml +7 -3
- data/Gemfile.lock +81 -70
- data/datadog-notifications.gemspec +5 -4
- data/lib/datadog/notifications/config.rb +5 -5
- data/lib/datadog/notifications/plugins/active_job.rb +4 -3
- data/lib/datadog/notifications/plugins/grape.rb +5 -5
- data/lib/datadog/notifications/version.rb +1 -1
- data/spec/datadog/notifications/config_spec.rb +5 -7
- data/spec/datadog/notifications/plugins/active_job_spec.rb +20 -0
- data/spec/datadog/notifications/plugins/active_record_spec.rb +6 -6
- data/spec/datadog/notifications/plugins/grape_spec.rb +17 -17
- data/spec/datadog/notifications_spec.rb +20 -6
- data/spec/spec_helper.rb +22 -33
- metadata +24 -20
- data/.rake_tasks~ +0 -9
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5935ae5cdf0ad8a0b97044ee63f11b1a7c0c21b4d9d901bff27e14d2d7543b22
|
4
|
+
data.tar.gz: 0aa3de2457df6fb8d23e2ae3ac456cc7c463cc13482851e4e750fa1f1e53a8de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b87c1cd9fc7b2f2f0c4514661b4dd914ef1c529808c6eb1fad0ed1ee20a852b305e96d07b8ca297010495c7d8ae7982cf0cb7e93f8aca75b122d692f4985b415
|
7
|
+
data.tar.gz: 81e36be184535761d78a0e6c1dfd555232b6af6fbd86f6942d00892a5ca63b38377bdef49d60fbd4561794517b583c756bb508aecd34b4dc2e8fc8e9c898e63a
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ["2.7", "3.0", "3.1"]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
|
2
|
-
-
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-bsm:
|
3
|
+
- default.yml
|
4
|
+
inherit_mode:
|
5
|
+
merge:
|
6
|
+
- Exclude
|
3
7
|
|
4
8
|
AllCops:
|
5
|
-
TargetRubyVersion: "2.
|
9
|
+
TargetRubyVersion: "2.7"
|
6
10
|
|
7
11
|
Naming/FileName:
|
8
12
|
Exclude:
|
data/Gemfile.lock
CHANGED
@@ -1,114 +1,125 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datadog-notifications (0.
|
4
|
+
datadog-notifications (0.7.0)
|
5
5
|
activesupport
|
6
|
-
dogstatsd-ruby (>=
|
6
|
+
dogstatsd-ruby (>= 5.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
activesupport (=
|
13
|
-
|
14
|
-
|
15
|
-
activesupport (=
|
16
|
-
|
11
|
+
activejob (7.0.3)
|
12
|
+
activesupport (= 7.0.3)
|
13
|
+
globalid (>= 0.3.6)
|
14
|
+
activemodel (7.0.3)
|
15
|
+
activesupport (= 7.0.3)
|
16
|
+
activerecord (7.0.3)
|
17
|
+
activemodel (= 7.0.3)
|
18
|
+
activesupport (= 7.0.3)
|
19
|
+
activesupport (7.0.3)
|
17
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (>=
|
19
|
-
minitest (
|
20
|
-
tzinfo (~>
|
21
|
-
|
22
|
-
ast (2.4.0)
|
21
|
+
i18n (>= 1.6, < 2)
|
22
|
+
minitest (>= 5.1)
|
23
|
+
tzinfo (~> 2.0)
|
24
|
+
ast (2.4.2)
|
23
25
|
builder (3.2.4)
|
24
|
-
concurrent-ruby (1.1.
|
25
|
-
diff-lcs (1.
|
26
|
-
dogstatsd-ruby (
|
27
|
-
dry-configurable (0.
|
26
|
+
concurrent-ruby (1.1.10)
|
27
|
+
diff-lcs (1.5.0)
|
28
|
+
dogstatsd-ruby (5.5.0)
|
29
|
+
dry-configurable (0.15.0)
|
28
30
|
concurrent-ruby (~> 1.0)
|
29
|
-
dry-core (~> 0.
|
30
|
-
|
31
|
-
dry-container (0.7.2)
|
31
|
+
dry-core (~> 0.6)
|
32
|
+
dry-container (0.9.0)
|
32
33
|
concurrent-ruby (~> 1.0)
|
33
|
-
dry-configurable (~> 0.
|
34
|
-
dry-core (0.
|
34
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
35
|
+
dry-core (0.7.1)
|
35
36
|
concurrent-ruby (~> 1.0)
|
36
|
-
dry-
|
37
|
-
dry-
|
38
|
-
dry-logic (1.0.6)
|
37
|
+
dry-inflector (0.2.1)
|
38
|
+
dry-logic (1.2.0)
|
39
39
|
concurrent-ruby (~> 1.0)
|
40
|
-
dry-core (~> 0.
|
41
|
-
|
42
|
-
dry-types (1.4.0)
|
40
|
+
dry-core (~> 0.5, >= 0.5)
|
41
|
+
dry-types (1.5.1)
|
43
42
|
concurrent-ruby (~> 1.0)
|
44
43
|
dry-container (~> 0.3)
|
45
|
-
dry-core (~> 0.
|
46
|
-
dry-equalizer (~> 0.3)
|
44
|
+
dry-core (~> 0.5, >= 0.5)
|
47
45
|
dry-inflector (~> 0.1, >= 0.1.2)
|
48
46
|
dry-logic (~> 1.0, >= 1.0.2)
|
49
|
-
|
47
|
+
globalid (1.0.0)
|
48
|
+
activesupport (>= 5.0)
|
49
|
+
grape (1.6.2)
|
50
50
|
activesupport
|
51
51
|
builder
|
52
52
|
dry-types (>= 1.1)
|
53
53
|
mustermann-grape (~> 1.0.0)
|
54
54
|
rack (>= 1.3.0)
|
55
55
|
rack-accept
|
56
|
-
i18n (1.
|
56
|
+
i18n (1.10.0)
|
57
57
|
concurrent-ruby (~> 1.0)
|
58
|
-
minitest (5.
|
58
|
+
minitest (5.15.0)
|
59
59
|
mustermann (1.1.1)
|
60
60
|
ruby2_keywords (~> 0.0.1)
|
61
|
-
mustermann-grape (1.0.
|
61
|
+
mustermann-grape (1.0.2)
|
62
62
|
mustermann (>= 1.0.0)
|
63
|
-
parallel (1.
|
64
|
-
parser (
|
65
|
-
ast (~> 2.4.
|
66
|
-
rack (2.2.
|
63
|
+
parallel (1.22.1)
|
64
|
+
parser (3.1.2.0)
|
65
|
+
ast (~> 2.4.1)
|
66
|
+
rack (2.2.3.1)
|
67
67
|
rack-accept (0.4.5)
|
68
68
|
rack (>= 0.4)
|
69
69
|
rack-test (1.1.0)
|
70
70
|
rack (>= 1.0, < 3)
|
71
|
-
rainbow (3.
|
72
|
-
rake (13.0.
|
73
|
-
regexp_parser (
|
74
|
-
rexml (3.2.
|
75
|
-
rspec (3.
|
76
|
-
rspec-core (~> 3.
|
77
|
-
rspec-expectations (~> 3.
|
78
|
-
rspec-mocks (~> 3.
|
79
|
-
rspec-core (3.
|
80
|
-
rspec-support (~> 3.
|
81
|
-
rspec-expectations (3.
|
71
|
+
rainbow (3.1.1)
|
72
|
+
rake (13.0.6)
|
73
|
+
regexp_parser (2.5.0)
|
74
|
+
rexml (3.2.5)
|
75
|
+
rspec (3.11.0)
|
76
|
+
rspec-core (~> 3.11.0)
|
77
|
+
rspec-expectations (~> 3.11.0)
|
78
|
+
rspec-mocks (~> 3.11.0)
|
79
|
+
rspec-core (3.11.0)
|
80
|
+
rspec-support (~> 3.11.0)
|
81
|
+
rspec-expectations (3.11.0)
|
82
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
-
rspec-support (~> 3.
|
84
|
-
rspec-mocks (3.
|
83
|
+
rspec-support (~> 3.11.0)
|
84
|
+
rspec-mocks (3.11.1)
|
85
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
-
rspec-support (~> 3.
|
87
|
-
rspec-support (3.
|
88
|
-
rubocop (
|
86
|
+
rspec-support (~> 3.11.0)
|
87
|
+
rspec-support (3.11.0)
|
88
|
+
rubocop (1.30.1)
|
89
89
|
parallel (~> 1.10)
|
90
|
-
parser (>=
|
90
|
+
parser (>= 3.1.0.0)
|
91
91
|
rainbow (>= 2.2.2, < 4.0)
|
92
|
-
regexp_parser (>= 1.
|
93
|
-
rexml
|
94
|
-
rubocop-ast (>= 0.0
|
92
|
+
regexp_parser (>= 1.8, < 3.0)
|
93
|
+
rexml (>= 3.2.5, < 4.0)
|
94
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
95
95
|
ruby-progressbar (~> 1.7)
|
96
|
-
unicode-display_width (>= 1.4.0, <
|
97
|
-
rubocop-ast (
|
98
|
-
parser (>=
|
99
|
-
|
100
|
-
|
96
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
97
|
+
rubocop-ast (1.18.0)
|
98
|
+
parser (>= 3.1.1.0)
|
99
|
+
rubocop-bsm (0.6.0)
|
100
|
+
rubocop (~> 1.0)
|
101
|
+
rubocop-performance
|
102
|
+
rubocop-rake
|
103
|
+
rubocop-rspec
|
104
|
+
rubocop-performance (1.14.1)
|
105
|
+
rubocop (>= 1.7.0, < 2.0)
|
106
|
+
rubocop-ast (>= 0.4.0)
|
107
|
+
rubocop-rake (0.6.0)
|
108
|
+
rubocop (~> 1.0)
|
109
|
+
rubocop-rspec (2.11.1)
|
110
|
+
rubocop (~> 1.19)
|
111
|
+
ruby-progressbar (1.11.0)
|
112
|
+
ruby2_keywords (0.0.5)
|
101
113
|
sqlite3 (1.4.2)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
unicode-display_width (1.7.0)
|
106
|
-
zeitwerk (2.3.0)
|
114
|
+
tzinfo (2.0.4)
|
115
|
+
concurrent-ruby (~> 1.0)
|
116
|
+
unicode-display_width (2.1.0)
|
107
117
|
|
108
118
|
PLATFORMS
|
109
119
|
ruby
|
110
120
|
|
111
121
|
DEPENDENCIES
|
122
|
+
activejob
|
112
123
|
activerecord
|
113
124
|
bundler
|
114
125
|
datadog-notifications!
|
@@ -116,8 +127,8 @@ DEPENDENCIES
|
|
116
127
|
rack-test
|
117
128
|
rake
|
118
129
|
rspec
|
119
|
-
rubocop
|
130
|
+
rubocop-bsm
|
120
131
|
sqlite3
|
121
132
|
|
122
133
|
BUNDLED WITH
|
123
|
-
2.
|
134
|
+
2.3.9
|
@@ -12,19 +12,20 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.homepage = 'https://github.com/bsm/datadog-notifications'
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
-
s.test_files = s.files.grep(%r{^(spec)/})
|
16
15
|
s.require_paths = ['lib']
|
17
|
-
s.required_ruby_version = '>= 2.
|
16
|
+
s.required_ruby_version = '>= 2.7'
|
18
17
|
|
19
18
|
s.add_runtime_dependency 'activesupport'
|
20
|
-
s.add_runtime_dependency 'dogstatsd-ruby', '>=
|
19
|
+
s.add_runtime_dependency 'dogstatsd-ruby', '>= 5.0'
|
21
20
|
|
21
|
+
s.add_development_dependency 'activejob'
|
22
22
|
s.add_development_dependency 'activerecord'
|
23
23
|
s.add_development_dependency 'bundler'
|
24
24
|
s.add_development_dependency 'grape', '>= 1.0.2'
|
25
25
|
s.add_development_dependency 'rack-test'
|
26
26
|
s.add_development_dependency 'rake'
|
27
27
|
s.add_development_dependency 'rspec'
|
28
|
-
s.add_development_dependency 'rubocop'
|
28
|
+
s.add_development_dependency 'rubocop-bsm'
|
29
29
|
s.add_development_dependency 'sqlite3'
|
30
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
30
31
|
end
|
@@ -4,10 +4,10 @@ module Datadog
|
|
4
4
|
attr_accessor :hostname, :namespace, :tags, :statsd_host, :statsd_port, :reporter, :plugins, :socket_path
|
5
5
|
|
6
6
|
def initialize
|
7
|
-
@hostname = ENV
|
8
|
-
@statsd_host = ENV
|
9
|
-
@statsd_port = ENV
|
10
|
-
@socket_path = ENV
|
7
|
+
@hostname = ENV.fetch('INSTRUMENTATION_HOSTNAME') { Socket.gethostname }
|
8
|
+
@statsd_host = ENV.fetch('STATSD_HOST', nil)
|
9
|
+
@statsd_port = ENV.fetch('STATSD_PORT', nil)
|
10
|
+
@socket_path = ENV.fetch('SOCKET_PATH', nil)
|
11
11
|
@reporter = Datadog::Notifications::Reporter
|
12
12
|
@tags = []
|
13
13
|
@plugins = []
|
@@ -21,7 +21,7 @@ module Datadog
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def connect!
|
24
|
-
env = ENV
|
24
|
+
env = ENV.fetch('RAILS_ENV') { ENV.fetch('RACK_ENV', nil) }
|
25
25
|
tags.push("env:#{env}") if env && tags.none? {|t| t =~ /^env:/ }
|
26
26
|
|
27
27
|
enable_hostname = hostname && hostname != 'false'
|
@@ -18,9 +18,10 @@ module Datadog::Notifications::Plugins
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def record(reporter, event)
|
21
|
-
job
|
22
|
-
name
|
23
|
-
|
21
|
+
job = event.payload[:job]
|
22
|
+
name = job.class.name.sub(/Job$/, '').underscore
|
23
|
+
queue = job.queue_name.tr(':', '_')
|
24
|
+
tags = self.tags + %W[job:#{name} queue:#{queue}]
|
24
25
|
|
25
26
|
reporter.batch do
|
26
27
|
reporter.increment metric_name, tags: tags
|
@@ -49,16 +49,16 @@ module Datadog::Notifications::Plugins
|
|
49
49
|
|
50
50
|
def extract_path(endpoint)
|
51
51
|
route = begin
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
endpoint.route
|
53
|
+
rescue NoMethodError
|
54
|
+
nil
|
55
|
+
end
|
56
56
|
return endpoint.request.path unless route
|
57
57
|
|
58
58
|
path = endpoint.route.path.dup
|
59
59
|
path.sub!(/\(\.:format\)$/, '')
|
60
60
|
path.sub!(':version/', '') if endpoint.version
|
61
|
-
path.gsub!(/:(\w+)/) {|m| m[1
|
61
|
+
path.gsub!(/:(\w+)/) {|m| m[1..].upcase }
|
62
62
|
path
|
63
63
|
end
|
64
64
|
end
|
@@ -1,24 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Datadog::Notifications::Config do
|
4
|
-
it '
|
5
|
-
subject.reporter = Mock::Reporter
|
4
|
+
it 'is connect!' do
|
6
5
|
subject.hostname = 'test.host'
|
7
6
|
subject.tags = ['custom:tag']
|
8
7
|
|
9
8
|
client = subject.send(:connect!)
|
10
|
-
expect(client).to be_instance_of(
|
9
|
+
expect(client).to be_instance_of(Datadog::Notifications::Reporter)
|
11
10
|
expect(subject.tags).to eq(['custom:tag', 'env:test', 'host:test.host'])
|
12
11
|
end
|
13
12
|
|
14
13
|
RSpec.shared_examples 'host tag is not picked up' do |hostname|
|
15
|
-
it '
|
16
|
-
subject.reporter = Mock::Reporter
|
14
|
+
it 'does not pick up the host tag' do
|
17
15
|
subject.hostname = hostname
|
18
16
|
subject.tags = ['custom:tag']
|
19
17
|
|
20
18
|
client = subject.send(:connect!)
|
21
|
-
expect(client).to be_instance_of(
|
19
|
+
expect(client).to be_instance_of(Datadog::Notifications::Reporter)
|
22
20
|
expect(subject.tags).to eq(['custom:tag', 'env:test'])
|
23
21
|
end
|
24
22
|
end
|
@@ -26,7 +24,7 @@ describe Datadog::Notifications::Config do
|
|
26
24
|
include_examples 'host tag is not picked up', false
|
27
25
|
include_examples 'host tag is not picked up', 'false'
|
28
26
|
|
29
|
-
it '
|
27
|
+
it 'instantiates plugins on use' do
|
30
28
|
subject.use Datadog::Notifications::Plugins::ActionController
|
31
29
|
expect(subject.plugins.size).to eq(1)
|
32
30
|
expect(subject.plugins.first).to be_instance_of(Datadog::Notifications::Plugins::ActionController)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Datadog::Notifications::Plugins::ActiveJob do
|
4
|
+
it 'sanitizes tags' do
|
5
|
+
klass = Class.new(ActiveJob::Base) do
|
6
|
+
def self.name
|
7
|
+
'Mock::NoopJob'
|
8
|
+
end
|
9
|
+
|
10
|
+
self.queue_name = 'test:queue'
|
11
|
+
def perform; end
|
12
|
+
end
|
13
|
+
|
14
|
+
klass.perform_now
|
15
|
+
expect(messages).to eq [
|
16
|
+
'activejob.perform:1|c|#custom:tag,env:test,host:test.host,job:mock/noop,queue:test_queue',
|
17
|
+
'activejob.perform.time:787.0|ms|#custom:tag,env:test,host:test.host,job:mock/noop,queue:test_queue',
|
18
|
+
]
|
19
|
+
end
|
20
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Datadog::Notifications::Plugins::ActiveRecord do
|
4
|
-
it '
|
4
|
+
it 'sends an increment and timing event for each query' do
|
5
5
|
Post.all.to_a
|
6
|
-
expect(
|
6
|
+
expect(messages).to eq [
|
7
7
|
'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
|
8
|
-
'activerecord.sql.time:
|
8
|
+
'activerecord.sql.time:111.0|ms|#custom:tag,env:test,host:test.host,query:post.load',
|
9
9
|
]
|
10
10
|
end
|
11
11
|
|
12
|
-
it '
|
12
|
+
it 'supports custom queries' do
|
13
13
|
Post.find_by_sql('SELECT * FROM posts LIMIT 1').to_a
|
14
|
-
expect(
|
14
|
+
expect(messages).to eq [
|
15
15
|
'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
|
16
|
-
'activerecord.sql.time:
|
16
|
+
'activerecord.sql.time:111.0|ms|#custom:tag,env:test,host:test.host,query:post.load',
|
17
17
|
]
|
18
18
|
end
|
19
19
|
end
|
@@ -36,63 +36,63 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
it '
|
39
|
+
it 'sends an increment and timing event for each request' do
|
40
40
|
get '/echo/1/1234'
|
41
41
|
expect(last_response.status).to eq(200)
|
42
42
|
expect(last_response.body).to eq('1 1234')
|
43
43
|
|
44
|
-
expect(
|
44
|
+
expect(messages).to eq([
|
45
45
|
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
|
46
|
-
'api.request.time:
|
46
|
+
'api.request.time:111.0|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
|
47
47
|
])
|
48
48
|
end
|
49
49
|
|
50
|
-
it '
|
50
|
+
it 'supports namespaces and versioning' do
|
51
51
|
get '/api/v1/sub/versioned.txt'
|
52
52
|
expect(last_response.status).to eq(200)
|
53
53
|
expect(last_response.body).to eq('OK')
|
54
54
|
|
55
|
-
expect(
|
55
|
+
expect(messages).to eq([
|
56
56
|
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
|
57
|
-
'api.request.time:
|
57
|
+
'api.request.time:111.0|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
|
58
58
|
])
|
59
59
|
end
|
60
60
|
|
61
|
-
it '
|
61
|
+
it 'supports deep nesting' do
|
62
62
|
get '/sub/secure/resource'
|
63
63
|
expect(last_response.status).to eq(403)
|
64
64
|
expect(last_response.body).to eq('forbidden')
|
65
65
|
|
66
|
-
expect(
|
66
|
+
expect(messages).to eq([
|
67
67
|
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
|
68
|
-
'api.request.time:
|
68
|
+
'api.request.time:111.0|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
|
69
69
|
])
|
70
70
|
end
|
71
71
|
|
72
|
-
it '
|
72
|
+
it 'handles rescued errors' do
|
73
73
|
get '/rescued'
|
74
74
|
expect(last_response.status).to eq(401)
|
75
75
|
|
76
|
-
expect(
|
76
|
+
expect(messages).to eq([
|
77
77
|
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
|
78
|
-
'api.request.time:
|
78
|
+
'api.request.time:111.0|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
|
79
79
|
])
|
80
80
|
end
|
81
81
|
|
82
|
-
it '
|
82
|
+
it 'handles invalid method' do
|
83
83
|
post '/rescued'
|
84
84
|
|
85
85
|
expect(last_response.status).to eq(405)
|
86
|
-
expect(
|
86
|
+
expect(messages).to eq([
|
87
87
|
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
|
88
|
-
'api.request.time:
|
88
|
+
'api.request.time:111.0|ms|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
|
89
89
|
])
|
90
90
|
end
|
91
91
|
|
92
|
-
it '
|
92
|
+
it 'does not report paths on 404s' do
|
93
93
|
get '/sub/missing'
|
94
94
|
expect(last_response.status).to eq(404)
|
95
95
|
|
96
|
-
expect(
|
96
|
+
expect(messages).to eq([])
|
97
97
|
end
|
98
98
|
end
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Datadog::Notifications do
|
4
4
|
subject { described_class.instance }
|
5
|
+
|
5
6
|
after { ActiveSupport::Notifications.unsubscribe(subscription) }
|
6
7
|
|
7
8
|
let!(:subscription) do
|
@@ -17,15 +18,28 @@ describe Datadog::Notifications do
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
it '
|
21
|
-
expect(subject.send(:reporter)).to be_instance_of(
|
21
|
+
it 'has a reporter' do
|
22
|
+
expect(subject.send(:reporter)).to be_instance_of(Datadog::Notifications::Reporter)
|
22
23
|
end
|
23
24
|
|
24
|
-
it '
|
25
|
-
|
26
|
-
|
25
|
+
it 'subscribes and report' do
|
26
|
+
klass = Class.new do
|
27
|
+
def initialize(**opts)
|
28
|
+
@opts = opts
|
29
|
+
end
|
30
|
+
|
31
|
+
def perform
|
32
|
+
ActiveSupport::Notifications.instrument('mock.start', @opts)
|
33
|
+
ActiveSupport::Notifications.instrument('mock.perform', @opts) do |payload|
|
34
|
+
payload[:status] = 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
klass.new(method: 'GET').perform
|
39
|
+
|
40
|
+
expect(messages).to eq([
|
27
41
|
'web.render:1|c|#custom:tag,env:test,host:test.host,status:200,method:GET',
|
28
|
-
'web.render.time:
|
42
|
+
'web.render.time:111.0|ms|#custom:tag,env:test,host:test.host,status:200,method:GET',
|
29
43
|
])
|
30
44
|
end
|
31
45
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rspec'
|
|
6
6
|
require 'rack/test'
|
7
7
|
require 'grape'
|
8
8
|
require 'active_record'
|
9
|
+
require 'active_job'
|
9
10
|
require 'sqlite3'
|
10
11
|
|
11
12
|
### Active-record test preparation
|
@@ -18,58 +19,46 @@ end
|
|
18
19
|
class Post < ActiveRecord::Base
|
19
20
|
end
|
20
21
|
|
21
|
-
###
|
22
|
+
### ActiveJob test preparation
|
22
23
|
|
23
|
-
|
24
|
-
class Reporter < Datadog::Notifications::Reporter
|
25
|
-
def timing(stat, _millis, **opts)
|
26
|
-
super(stat, 333, **opts)
|
27
|
-
end
|
28
|
-
|
29
|
-
def send_stat(message)
|
30
|
-
messages.push message
|
31
|
-
end
|
32
|
-
|
33
|
-
def messages
|
34
|
-
@messages ||= []
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Instrumentable
|
39
|
-
def initialize(**opts)
|
40
|
-
@opts = opts
|
41
|
-
end
|
42
|
-
|
43
|
-
def perform
|
44
|
-
ActiveSupport::Notifications.instrument('mock.start', @opts)
|
45
|
-
ActiveSupport::Notifications.instrument('mock.perform', @opts) do |payload|
|
46
|
-
payload[:status] = 200
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
24
|
+
ActiveJob::Base.queue_adapter = :inline
|
51
25
|
|
52
26
|
### Configuration
|
53
27
|
|
54
28
|
RSpec.configure do |c|
|
55
29
|
helpers = Module.new do
|
56
|
-
def
|
57
|
-
|
30
|
+
def messages
|
31
|
+
@messages ||= []
|
58
32
|
end
|
59
33
|
end
|
60
34
|
|
61
35
|
c.include helpers
|
62
36
|
c.before do
|
63
|
-
|
37
|
+
# clear existing messages
|
38
|
+
messages.clear
|
39
|
+
|
40
|
+
# collect messages
|
41
|
+
reporter = Datadog::Notifications.instance.send(:reporter)
|
42
|
+
forwarder = reporter.send(:forwarder)
|
43
|
+
allow(forwarder).to receive(:send_message) do |msg|
|
44
|
+
@messages.push(msg)
|
45
|
+
end
|
46
|
+
|
47
|
+
# stub Time.now
|
48
|
+
allow(Time).to receive(:now).and_return(
|
49
|
+
Time.at(1616161616.161),
|
50
|
+
Time.at(1616161616.272),
|
51
|
+
Time.at(1616161616.948),
|
52
|
+
)
|
64
53
|
end
|
65
54
|
end
|
66
55
|
|
67
56
|
Datadog::Notifications.configure do |c|
|
68
57
|
c.hostname = 'test.host'
|
69
|
-
c.reporter = Mock::Reporter
|
70
58
|
c.tags = ['custom:tag']
|
71
59
|
|
72
60
|
c.use Datadog::Notifications::Plugins::ActiveRecord
|
61
|
+
c.use Datadog::Notifications::Plugins::ActiveJob
|
73
62
|
c.use Datadog::Notifications::Plugins::Grape,
|
74
63
|
tags: ['more:tags'],
|
75
64
|
metric_name: 'api.request',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -29,9 +29,6 @@ dependencies:
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '4.2'
|
34
|
-
- - "<"
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '5.0'
|
37
34
|
type: :runtime
|
@@ -39,11 +36,22 @@ dependencies:
|
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '4.2'
|
44
|
-
- - "<"
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activejob
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: activerecord
|
49
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,7 +137,7 @@ dependencies:
|
|
129
137
|
- !ruby/object:Gem::Version
|
130
138
|
version: '0'
|
131
139
|
- !ruby/object:Gem::Dependency
|
132
|
-
name: rubocop
|
140
|
+
name: rubocop-bsm
|
133
141
|
requirement: !ruby/object:Gem::Requirement
|
134
142
|
requirements:
|
135
143
|
- - ">="
|
@@ -164,10 +172,9 @@ extensions: []
|
|
164
172
|
extra_rdoc_files: []
|
165
173
|
files:
|
166
174
|
- ".editorconfig"
|
175
|
+
- ".github/workflows/ruby.yml"
|
167
176
|
- ".gitignore"
|
168
|
-
- ".rake_tasks~"
|
169
177
|
- ".rubocop.yml"
|
170
|
-
- ".travis.yml"
|
171
178
|
- Gemfile
|
172
179
|
- Gemfile.lock
|
173
180
|
- MIT-LICENCE
|
@@ -187,13 +194,15 @@ files:
|
|
187
194
|
- lib/datadog/notifications/reporter.rb
|
188
195
|
- lib/datadog/notifications/version.rb
|
189
196
|
- spec/datadog/notifications/config_spec.rb
|
197
|
+
- spec/datadog/notifications/plugins/active_job_spec.rb
|
190
198
|
- spec/datadog/notifications/plugins/active_record_spec.rb
|
191
199
|
- spec/datadog/notifications/plugins/grape_spec.rb
|
192
200
|
- spec/datadog/notifications_spec.rb
|
193
201
|
- spec/spec_helper.rb
|
194
202
|
homepage: https://github.com/bsm/datadog-notifications
|
195
203
|
licenses: []
|
196
|
-
metadata:
|
204
|
+
metadata:
|
205
|
+
rubygems_mfa_required: 'true'
|
197
206
|
post_install_message:
|
198
207
|
rdoc_options: []
|
199
208
|
require_paths:
|
@@ -202,20 +211,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
211
|
requirements:
|
203
212
|
- - ">="
|
204
213
|
- !ruby/object:Gem::Version
|
205
|
-
version: '2.
|
214
|
+
version: '2.7'
|
206
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
216
|
requirements:
|
208
217
|
- - ">="
|
209
218
|
- !ruby/object:Gem::Version
|
210
219
|
version: '0'
|
211
220
|
requirements: []
|
212
|
-
rubygems_version: 3.
|
221
|
+
rubygems_version: 3.3.7
|
213
222
|
signing_key:
|
214
223
|
specification_version: 4
|
215
224
|
summary: Generic ActiveSupport::Notifications Datadog handler
|
216
|
-
test_files:
|
217
|
-
- spec/datadog/notifications/config_spec.rb
|
218
|
-
- spec/datadog/notifications/plugins/active_record_spec.rb
|
219
|
-
- spec/datadog/notifications/plugins/grape_spec.rb
|
220
|
-
- spec/datadog/notifications_spec.rb
|
221
|
-
- spec/spec_helper.rb
|
225
|
+
test_files: []
|
data/.rake_tasks~
DELETED