datadog-notifications 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rake_tasks~ +9 -0
- data/.rubocop.yml +6 -66
- data/.travis.yml +5 -5
- data/Gemfile.lock +22 -22
- data/Rakefile +2 -2
- data/datadog-notifications.gemspec +3 -2
- data/lib/datadog-notifications.rb +1 -1
- data/lib/datadog/notifications.rb +1 -1
- data/lib/datadog/notifications/config.rb +2 -2
- data/lib/datadog/notifications/plugins/action_controller.rb +1 -1
- data/lib/datadog/notifications/plugins/active_job.rb +1 -1
- data/lib/datadog/notifications/plugins/active_record.rb +4 -4
- data/lib/datadog/notifications/plugins/grape.rb +2 -2
- data/lib/datadog/notifications/version.rb +1 -1
- data/spec/datadog/notifications/config_spec.rb +5 -5
- data/spec/datadog/notifications/plugins/active_record_spec.rb +5 -5
- data/spec/datadog/notifications/plugins/grape_spec.rb +19 -19
- data/spec/datadog/notifications_spec.rb +6 -6
- data/spec/spec_helper.rb +15 -10
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d0e1c30e83693a9e33832f3ed942f453c757f3dee361aea4bbc7172057c0d5c
|
4
|
+
data.tar.gz: 0f566306936e2f0e7bf0a2d70ed4f21825ec709fc3675405d1117acc0de3c634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c48e6b3b027fa4f80d610952cd417793b8f0a7a3570343dfea6712d65fd8872f414dc5421c19bdd6c1a8c4d31f756ed4cc6e5b4864f0d455a4a6d3c33bc68644
|
7
|
+
data.tar.gz: b0774629b619d7866cc6fbb5b67f21d268aabc8114d42d2ca9ea3f347fe5a6aa6dad6e35e7c6be71f7fece846f194157c5e85472360b6754d0073477c5805d2b
|
data/.gitignore
CHANGED
data/.rake_tasks~
ADDED
data/.rubocop.yml
CHANGED
@@ -1,70 +1,10 @@
|
|
1
|
+
inherit_from:
|
2
|
+
- https://bitbucket.org/bsm/misc/raw/master/rubocop/default.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: "2.3"
|
6
|
+
|
1
7
|
Naming/FileName:
|
2
8
|
Exclude:
|
3
9
|
- "lib/datadog-notifications.rb"
|
4
10
|
- "datadog-notifications.gemspec"
|
5
|
-
|
6
|
-
Metrics/AbcSize:
|
7
|
-
Enabled: false
|
8
|
-
Metrics/BlockLength:
|
9
|
-
Exclude:
|
10
|
-
- "**/*_spec.rb"
|
11
|
-
Metrics/ClassLength:
|
12
|
-
Max: 1500
|
13
|
-
Metrics/CyclomaticComplexity:
|
14
|
-
Enabled: false
|
15
|
-
Metrics/PerceivedComplexity:
|
16
|
-
Enabled: false
|
17
|
-
Metrics/LineLength:
|
18
|
-
Max: 160
|
19
|
-
Metrics/MethodLength:
|
20
|
-
Max: 20
|
21
|
-
Metrics/ModuleLength:
|
22
|
-
Exclude:
|
23
|
-
- "**/*_spec.rb"
|
24
|
-
|
25
|
-
Layout/AlignHash:
|
26
|
-
EnforcedHashRocketStyle: table
|
27
|
-
Layout/AlignParameters:
|
28
|
-
EnforcedStyle: with_fixed_indentation
|
29
|
-
Layout/EmptyLinesAroundBlockBody:
|
30
|
-
Exclude:
|
31
|
-
- "**/*_spec.rb"
|
32
|
-
Layout/EmptyLinesAroundClassBody:
|
33
|
-
Enabled: false
|
34
|
-
Layout/IndentArray:
|
35
|
-
EnforcedStyle: consistent
|
36
|
-
Layout/MultilineOperationIndentation:
|
37
|
-
Enabled: false
|
38
|
-
Layout/SpaceAroundEqualsInParameterDefault:
|
39
|
-
EnforcedStyle: no_space
|
40
|
-
Layout/SpaceInsideBlockBraces:
|
41
|
-
SpaceBeforeBlockParameters: false
|
42
|
-
|
43
|
-
Style/BlockDelimiters:
|
44
|
-
Enabled: false
|
45
|
-
Style/ClassAndModuleChildren:
|
46
|
-
Enabled: false
|
47
|
-
Style/Documentation:
|
48
|
-
Enabled: false
|
49
|
-
Style/FrozenStringLiteralComment:
|
50
|
-
Enabled: false
|
51
|
-
Style/HashSyntax:
|
52
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
53
|
-
Style/MultilineIfModifier:
|
54
|
-
Enabled: false
|
55
|
-
Style/NumericLiterals:
|
56
|
-
Enabled: false
|
57
|
-
Style/Semicolon:
|
58
|
-
AllowAsExpressionSeparator: true
|
59
|
-
Style/SingleLineBlockParams:
|
60
|
-
Enabled: false
|
61
|
-
Style/StringLiterals:
|
62
|
-
Enabled: false
|
63
|
-
Style/SymbolArray:
|
64
|
-
Enabled: true
|
65
|
-
Style/TrailingCommaInArguments:
|
66
|
-
EnforcedStyleForMultiline: consistent_comma
|
67
|
-
Style/TrailingCommaInArrayLiteral:
|
68
|
-
EnforcedStyleForMultiline: consistent_comma
|
69
|
-
Style/TrailingCommaInHashLiteral:
|
70
|
-
EnforcedStyleForMultiline: consistent_comma
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datadog-notifications (0.
|
4
|
+
datadog-notifications (0.6.0)
|
5
5
|
activesupport
|
6
|
-
dogstatsd-ruby (~>
|
6
|
+
dogstatsd-ruby (~> 4.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (5.2.
|
12
|
-
activesupport (= 5.2.
|
13
|
-
activerecord (5.2.
|
14
|
-
activemodel (= 5.2.
|
15
|
-
activesupport (= 5.2.
|
11
|
+
activemodel (5.2.2)
|
12
|
+
activesupport (= 5.2.2)
|
13
|
+
activerecord (5.2.2)
|
14
|
+
activemodel (= 5.2.2)
|
15
|
+
activesupport (= 5.2.2)
|
16
16
|
arel (>= 9.0)
|
17
|
-
activesupport (5.2.
|
17
|
+
activesupport (5.2.2)
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
19
|
i18n (>= 0.7, < 2)
|
20
20
|
minitest (~> 5.1)
|
@@ -28,65 +28,65 @@ GEM
|
|
28
28
|
builder (3.2.3)
|
29
29
|
coercible (1.0.0)
|
30
30
|
descendants_tracker (~> 0.0.1)
|
31
|
-
concurrent-ruby (1.
|
31
|
+
concurrent-ruby (1.1.4)
|
32
32
|
descendants_tracker (0.0.4)
|
33
33
|
thread_safe (~> 0.3, >= 0.3.1)
|
34
34
|
diff-lcs (1.3)
|
35
|
-
dogstatsd-ruby (
|
35
|
+
dogstatsd-ruby (4.0.0)
|
36
36
|
equalizer (0.0.11)
|
37
|
-
grape (1.
|
37
|
+
grape (1.2.2)
|
38
38
|
activesupport
|
39
39
|
builder
|
40
40
|
mustermann-grape (~> 1.0.0)
|
41
41
|
rack (>= 1.3.0)
|
42
42
|
rack-accept
|
43
43
|
virtus (>= 1.0.0)
|
44
|
-
i18n (1.
|
44
|
+
i18n (1.5.2)
|
45
45
|
concurrent-ruby (~> 1.0)
|
46
46
|
ice_nine (0.11.2)
|
47
|
-
jaro_winkler (1.5.
|
47
|
+
jaro_winkler (1.5.2)
|
48
48
|
minitest (5.11.3)
|
49
49
|
mustermann (1.0.3)
|
50
50
|
mustermann-grape (1.0.0)
|
51
51
|
mustermann (~> 1.0.0)
|
52
52
|
parallel (1.12.1)
|
53
|
-
parser (2.5.
|
53
|
+
parser (2.5.3.0)
|
54
54
|
ast (~> 2.4.0)
|
55
55
|
powerpack (0.1.2)
|
56
|
-
rack (2.0.
|
56
|
+
rack (2.0.6)
|
57
57
|
rack-accept (0.4.5)
|
58
58
|
rack (>= 0.4)
|
59
59
|
rack-test (1.1.0)
|
60
60
|
rack (>= 1.0, < 3)
|
61
61
|
rainbow (3.0.0)
|
62
|
-
rake (12.3.
|
62
|
+
rake (12.3.2)
|
63
63
|
rspec (3.8.0)
|
64
64
|
rspec-core (~> 3.8.0)
|
65
65
|
rspec-expectations (~> 3.8.0)
|
66
66
|
rspec-mocks (~> 3.8.0)
|
67
67
|
rspec-core (3.8.0)
|
68
68
|
rspec-support (~> 3.8.0)
|
69
|
-
rspec-expectations (3.8.
|
69
|
+
rspec-expectations (3.8.2)
|
70
70
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
71
|
rspec-support (~> 3.8.0)
|
72
72
|
rspec-mocks (3.8.0)
|
73
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
74
|
rspec-support (~> 3.8.0)
|
75
75
|
rspec-support (3.8.0)
|
76
|
-
rubocop (0.
|
76
|
+
rubocop (0.62.0)
|
77
77
|
jaro_winkler (~> 1.5.1)
|
78
78
|
parallel (~> 1.10)
|
79
79
|
parser (>= 2.5, != 2.5.1.1)
|
80
80
|
powerpack (~> 0.1)
|
81
81
|
rainbow (>= 2.2.2, < 4.0)
|
82
82
|
ruby-progressbar (~> 1.7)
|
83
|
-
unicode-display_width (~> 1.
|
83
|
+
unicode-display_width (~> 1.4.0)
|
84
84
|
ruby-progressbar (1.10.0)
|
85
85
|
sqlite3 (1.3.13)
|
86
86
|
thread_safe (0.3.6)
|
87
87
|
tzinfo (1.2.5)
|
88
88
|
thread_safe (~> 0.1)
|
89
|
-
unicode-display_width (1.4.
|
89
|
+
unicode-display_width (1.4.1)
|
90
90
|
virtus (1.0.5)
|
91
91
|
axiom-types (~> 0.1)
|
92
92
|
coercible (~> 1.0)
|
@@ -100,7 +100,7 @@ DEPENDENCIES
|
|
100
100
|
activerecord
|
101
101
|
bundler
|
102
102
|
datadog-notifications!
|
103
|
-
grape (>= 0.
|
103
|
+
grape (>= 1.0.2)
|
104
104
|
rack-test
|
105
105
|
rake
|
106
106
|
rspec
|
@@ -108,4 +108,4 @@ DEPENDENCIES
|
|
108
108
|
sqlite3
|
109
109
|
|
110
110
|
BUNDLED WITH
|
111
|
-
1.
|
111
|
+
1.17.3
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
|
3
3
|
begin
|
4
4
|
Bundler.setup(:default, :development)
|
5
5
|
rescue Bundler::BundlerError => e
|
6
6
|
warn e.message
|
7
|
-
warn
|
7
|
+
warn 'Run `bundle install` to install missing gems'
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
10
|
|
@@ -14,13 +14,14 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
15
|
s.test_files = s.files.grep(%r{^(spec)/})
|
16
16
|
s.require_paths = ['lib']
|
17
|
+
s.required_ruby_version = '>= 2.3'
|
17
18
|
|
18
19
|
s.add_runtime_dependency('activesupport')
|
19
|
-
s.add_runtime_dependency('dogstatsd-ruby', '~>
|
20
|
+
s.add_runtime_dependency('dogstatsd-ruby', '~> 4.0')
|
20
21
|
|
21
22
|
s.add_development_dependency('activerecord')
|
22
23
|
s.add_development_dependency('bundler')
|
23
|
-
s.add_development_dependency('grape', '>= 0.
|
24
|
+
s.add_development_dependency('grape', '>= 1.0.2')
|
24
25
|
s.add_development_dependency('rack-test')
|
25
26
|
s.add_development_dependency('rake')
|
26
27
|
s.add_development_dependency('rspec')
|
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'datadog/notifications'
|
@@ -34,7 +34,7 @@ module Datadog
|
|
34
34
|
warn "#{name} cannot be reconfigured once it has subscribed to notifications, called from: #{caller(2..2).first}"
|
35
35
|
return
|
36
36
|
end
|
37
|
-
block
|
37
|
+
block&.call instance.config
|
38
38
|
end
|
39
39
|
|
40
40
|
# You can subscribe to events exactly as with ActiveSupport::Notifications, but there will be an
|
@@ -5,8 +5,8 @@ module Datadog
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@hostname = ENV['INSTRUMENTATION_HOSTNAME'] || Socket.gethostname
|
8
|
-
@statsd_host = ENV['STATSD_HOST'] || ::Datadog::Statsd::DEFAULT_HOST
|
9
|
-
@statsd_port = (ENV['STATSD_PORT'] || ::Datadog::Statsd::DEFAULT_PORT).to_i
|
8
|
+
@statsd_host = ENV['STATSD_HOST'] || ::Datadog::Statsd::Connection::DEFAULT_HOST
|
9
|
+
@statsd_port = (ENV['STATSD_PORT'] || ::Datadog::Statsd::Connection::DEFAULT_PORT).to_i
|
10
10
|
@socket_path = ENV['SOCKET_PATH']
|
11
11
|
@reporter = Datadog::Notifications::Reporter
|
12
12
|
@tags = []
|
@@ -9,7 +9,7 @@ module Datadog::Notifications::Plugins
|
|
9
9
|
# *<tt>:tags</tt> - additional tags
|
10
10
|
def initialize(opts={})
|
11
11
|
super
|
12
|
-
@metric_name = opts[:metric_name] ||
|
12
|
+
@metric_name = opts[:metric_name] || 'rails.request'
|
13
13
|
|
14
14
|
Datadog::Notifications.subscribe 'process_action.action_controller' do |reporter, event|
|
15
15
|
record reporter, event
|
@@ -9,7 +9,7 @@ module Datadog::Notifications::Plugins
|
|
9
9
|
# *<tt>:tags</tt> - additional tags
|
10
10
|
def initialize(opts={})
|
11
11
|
super
|
12
|
-
@metric_name = opts[:metric_name] ||
|
12
|
+
@metric_name = opts[:metric_name] || 'activejob.perform'
|
13
13
|
|
14
14
|
Datadog::Notifications.subscribe 'perform.active_job' do |reporter, event|
|
15
15
|
record reporter, event
|
@@ -11,7 +11,7 @@ module Datadog::Notifications::Plugins
|
|
11
11
|
# *<tt>:tags</tt> - additional tags
|
12
12
|
def initialize(opts={})
|
13
13
|
super
|
14
|
-
@metric_name = opts[:metric_name] ||
|
14
|
+
@metric_name = opts[:metric_name] || 'activerecord.sql'
|
15
15
|
@include_schema = opts[:include_schema] == true
|
16
16
|
@include_generic = opts[:include_generic] == true
|
17
17
|
@include_raw = opts[:include_raw] == true
|
@@ -26,10 +26,10 @@ module Datadog::Notifications::Plugins
|
|
26
26
|
def record(reporter, event)
|
27
27
|
payload = event.payload
|
28
28
|
name = payload[:name]
|
29
|
-
return if (name.nil? || name ==
|
30
|
-
return if name ==
|
29
|
+
return if (name.nil? || name == 'SQL') && !@include_generic
|
30
|
+
return if name == 'SCHEMA' && !@include_schema
|
31
31
|
|
32
|
-
name = name.downcase.split(/\W/).join(
|
32
|
+
name = name.downcase.split(/\W/).join('.') if name
|
33
33
|
tags = self.tags.dup
|
34
34
|
tags.push "query:#{name}" if name
|
35
35
|
|
@@ -14,7 +14,7 @@ module Datadog::Notifications::Plugins
|
|
14
14
|
# *<tt>:tags</tt> - additional tags
|
15
15
|
def initialize(opts={})
|
16
16
|
super
|
17
|
-
@metric_name = opts[:metric_name] ||
|
17
|
+
@metric_name = opts[:metric_name] || 'grape.request'
|
18
18
|
@exception_handler = opts[:exception_handler] || ->(e) { self.class.exception_status(e) }
|
19
19
|
|
20
20
|
Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
|
@@ -55,7 +55,7 @@ module Datadog::Notifications::Plugins
|
|
55
55
|
|
56
56
|
path = endpoint.route.path.dup
|
57
57
|
path.sub!(/\(\.\:format\)$/, '')
|
58
|
-
path.sub!(
|
58
|
+
path.sub!(':version/', '') if endpoint.version
|
59
59
|
path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
|
60
60
|
path
|
61
61
|
end
|
@@ -4,23 +4,23 @@ describe Datadog::Notifications::Config do
|
|
4
4
|
|
5
5
|
it 'should be connect!' do
|
6
6
|
subject.reporter = Mock::Reporter
|
7
|
-
subject.hostname =
|
8
|
-
subject.tags = [
|
7
|
+
subject.hostname = 'test.host'
|
8
|
+
subject.tags = ['custom:tag']
|
9
9
|
|
10
10
|
client = subject.send(:connect!)
|
11
11
|
expect(client).to be_instance_of(Mock::Reporter)
|
12
|
-
expect(subject.tags).to eq([
|
12
|
+
expect(subject.tags).to eq(['custom:tag', 'env:test', 'host:test.host'])
|
13
13
|
end
|
14
14
|
|
15
15
|
RSpec.shared_examples 'host tag is not picked up' do |hostname|
|
16
16
|
it 'should not pick up the host tag' do
|
17
17
|
subject.reporter = Mock::Reporter
|
18
18
|
subject.hostname = hostname
|
19
|
-
subject.tags = [
|
19
|
+
subject.tags = ['custom:tag']
|
20
20
|
|
21
21
|
client = subject.send(:connect!)
|
22
22
|
expect(client).to be_instance_of(Mock::Reporter)
|
23
|
-
expect(subject.tags).to eq([
|
23
|
+
expect(subject.tags).to eq(['custom:tag', 'env:test'])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -5,16 +5,16 @@ describe Datadog::Notifications::Plugins::ActiveRecord do
|
|
5
5
|
it 'should send an increment and timing event for each query' do
|
6
6
|
Post.all.to_a
|
7
7
|
expect(buffered).to eq [
|
8
|
-
|
9
|
-
|
8
|
+
'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
|
9
|
+
'activerecord.sql.time:333|ms|#custom:tag,env:test,host:test.host,query:post.load',
|
10
10
|
]
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should support custom queries' do
|
14
|
-
Post.find_by_sql(
|
14
|
+
Post.find_by_sql('SELECT * FROM posts LIMIT 1').to_a
|
15
15
|
expect(buffered).to eq [
|
16
|
-
|
17
|
-
|
16
|
+
'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
|
17
|
+
'activerecord.sql.time:333|ms|#custom:tag,env:test,host:test.host,query:post.load',
|
18
18
|
]
|
19
19
|
end
|
20
20
|
|
@@ -10,13 +10,13 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
10
10
|
version 'v1'
|
11
11
|
prefix 'api'
|
12
12
|
|
13
|
-
get('versioned') {
|
13
|
+
get('versioned') { 'OK' }
|
14
14
|
end
|
15
15
|
|
16
16
|
Class.new(Grape::API) do
|
17
17
|
|
18
18
|
rescue_from unauthorized do |_e|
|
19
|
-
error!({ message:
|
19
|
+
error!({ message: 'unauthorized', error: '401 Unauthorized' }, 401)
|
20
20
|
end
|
21
21
|
|
22
22
|
get 'echo/:key1/:key2' do
|
@@ -24,14 +24,14 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
get '/rescued' do
|
27
|
-
raise unauthorized,
|
27
|
+
raise unauthorized, 'unauthorized'
|
28
28
|
end
|
29
29
|
|
30
30
|
namespace :sub do
|
31
31
|
mount sub_api
|
32
32
|
|
33
33
|
namespace :secure do
|
34
|
-
get(
|
34
|
+
get('/resource') { error!('forbidden', 403) }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -43,9 +43,9 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
43
43
|
expect(last_response.body).to eq('1 1234')
|
44
44
|
|
45
45
|
expect(buffered).to eq([
|
46
|
-
|
47
|
-
|
48
|
-
]
|
46
|
+
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
|
47
|
+
'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
|
48
|
+
])
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should support namespaces and versioning' do
|
@@ -54,9 +54,9 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
54
54
|
expect(last_response.body).to eq('OK')
|
55
55
|
|
56
56
|
expect(buffered).to eq([
|
57
|
-
|
58
|
-
|
59
|
-
]
|
57
|
+
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
|
58
|
+
'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
|
59
|
+
])
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should support deep nesting' do
|
@@ -65,9 +65,9 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
65
65
|
expect(last_response.body).to eq('forbidden')
|
66
66
|
|
67
67
|
expect(buffered).to eq([
|
68
|
-
|
69
|
-
|
70
|
-
]
|
68
|
+
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
|
69
|
+
'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
|
70
|
+
])
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should handle rescued errors' do
|
@@ -75,9 +75,9 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
75
75
|
expect(last_response.status).to eq(401)
|
76
76
|
|
77
77
|
expect(buffered).to eq([
|
78
|
-
|
79
|
-
|
80
|
-
]
|
78
|
+
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
|
79
|
+
'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
|
80
|
+
])
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should handle invalid method' do
|
@@ -85,9 +85,9 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
85
85
|
|
86
86
|
expect(last_response.status).to eq(405)
|
87
87
|
expect(buffered).to eq([
|
88
|
-
|
89
|
-
|
90
|
-
]
|
88
|
+
'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
|
89
|
+
'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
|
90
|
+
])
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should not report paths on 404s' do
|
@@ -6,14 +6,14 @@ describe Datadog::Notifications do
|
|
6
6
|
after { ActiveSupport::Notifications.unsubscribe(subscription) }
|
7
7
|
|
8
8
|
let!(:subscription) do
|
9
|
-
subject.subscribe(
|
9
|
+
subject.subscribe('mock.perform') do |reporter, event|
|
10
10
|
status = event.payload[:status]
|
11
11
|
method = event.payload[:method]
|
12
12
|
tags = ["status:#{status}", "method:#{method}"]
|
13
13
|
|
14
14
|
reporter.batch do
|
15
|
-
reporter.increment
|
16
|
-
reporter.timing
|
15
|
+
reporter.increment 'web.render', tags: tags
|
16
|
+
reporter.timing 'web.render.time', event.duration, tags: tags
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -25,9 +25,9 @@ describe Datadog::Notifications do
|
|
25
25
|
it 'should subscribe and report' do
|
26
26
|
Mock::Instrumentable.new(method: 'GET').perform
|
27
27
|
expect(buffered).to eq([
|
28
|
-
|
29
|
-
|
30
|
-
]
|
28
|
+
'web.render:1|c|#custom:tag,env:test,host:test.host,status:200,method:GET',
|
29
|
+
'web.render.time:333|ms|#custom:tag,env:test,host:test.host,status:200,method:GET',
|
30
|
+
])
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'sqlite3'
|
|
10
10
|
|
11
11
|
### Active-record test preparation
|
12
12
|
|
13
|
-
ActiveRecord::Base.configurations[
|
13
|
+
ActiveRecord::Base.configurations['test'] = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
|
14
14
|
ActiveRecord::Base.establish_connection(:test)
|
15
15
|
ActiveRecord::Base.connection.create_table :posts do |t|
|
16
16
|
t.string :title
|
@@ -26,8 +26,13 @@ module Mock
|
|
26
26
|
super(stat, 333, opts)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def send_stat(message)
|
30
|
+
messages.push message
|
31
|
+
end
|
32
|
+
|
33
|
+
def messages
|
34
|
+
@messages ||= []
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
class Instrumentable
|
@@ -36,8 +41,8 @@ module Mock
|
|
36
41
|
end
|
37
42
|
|
38
43
|
def perform
|
39
|
-
ActiveSupport::Notifications.instrument(
|
40
|
-
ActiveSupport::Notifications.instrument(
|
44
|
+
ActiveSupport::Notifications.instrument('mock.start', @opts)
|
45
|
+
ActiveSupport::Notifications.instrument('mock.perform', @opts) do |payload|
|
41
46
|
payload[:status] = 200
|
42
47
|
end
|
43
48
|
end
|
@@ -49,7 +54,7 @@ end
|
|
49
54
|
RSpec.configure do |c|
|
50
55
|
helpers = Module.new do
|
51
56
|
def buffered
|
52
|
-
Datadog::Notifications.instance.send(:reporter).
|
57
|
+
Datadog::Notifications.instance.send(:reporter).messages
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
@@ -60,14 +65,14 @@ RSpec.configure do |c|
|
|
60
65
|
end
|
61
66
|
|
62
67
|
Datadog::Notifications.configure do |c|
|
63
|
-
c.hostname =
|
68
|
+
c.hostname = 'test.host'
|
64
69
|
c.reporter = Mock::Reporter
|
65
|
-
c.tags = [
|
70
|
+
c.tags = ['custom:tag']
|
66
71
|
|
67
72
|
c.use Datadog::Notifications::Plugins::ActiveRecord
|
68
73
|
c.use Datadog::Notifications::Plugins::Grape,
|
69
|
-
tags: [
|
70
|
-
metric_name:
|
74
|
+
tags: ['more:tags'],
|
75
|
+
metric_name: 'api.request',
|
71
76
|
exception_handler: lambda {|e|
|
72
77
|
if e.message.include?('unauthorized')
|
73
78
|
401
|
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.6.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: 2019-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.0.2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.0.2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rack-test
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +159,7 @@ extra_rdoc_files: []
|
|
159
159
|
files:
|
160
160
|
- ".editorconfig"
|
161
161
|
- ".gitignore"
|
162
|
+
- ".rake_tasks~"
|
162
163
|
- ".rubocop.yml"
|
163
164
|
- ".travis.yml"
|
164
165
|
- Gemfile
|
@@ -195,15 +196,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
196
|
requirements:
|
196
197
|
- - ">="
|
197
198
|
- !ruby/object:Gem::Version
|
198
|
-
version: '
|
199
|
+
version: '2.3'
|
199
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
201
|
requirements:
|
201
202
|
- - ">="
|
202
203
|
- !ruby/object:Gem::Version
|
203
204
|
version: '0'
|
204
205
|
requirements: []
|
205
|
-
|
206
|
-
rubygems_version: 2.7.6
|
206
|
+
rubygems_version: 3.0.2
|
207
207
|
signing_key:
|
208
208
|
specification_version: 4
|
209
209
|
summary: Generic ActiveSupport::Notifications Datadog handler
|