datadog-notifications 0.5.0 → 0.5.1
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 +5 -5
- data/.rubocop.yml +69 -0
- data/.travis.yml +4 -3
- data/Gemfile.lock +36 -20
- data/Rakefile +6 -3
- data/datadog-notifications.gemspec +15 -14
- data/lib/datadog/notifications.rb +3 -3
- data/lib/datadog/notifications/config.rb +1 -1
- data/lib/datadog/notifications/plugins.rb +1 -1
- data/lib/datadog/notifications/plugins/action_controller.rb +2 -2
- data/lib/datadog/notifications/plugins/active_job.rb +2 -2
- data/lib/datadog/notifications/plugins/active_record.rb +1 -1
- data/lib/datadog/notifications/plugins/base.rb +1 -1
- data/lib/datadog/notifications/plugins/grape.rb +29 -16
- data/lib/datadog/notifications/version.rb +1 -1
- data/spec/datadog/notifications/plugins/active_record_spec.rb +2 -2
- data/spec/datadog/notifications/plugins/grape_spec.rb +24 -14
- data/spec/datadog/notifications_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -3
- metadata +24 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2257233489d7e6bc50b0e9a88e111d2ad44137f1cd0c88b03a98d8a9ab6d76b0
|
|
4
|
+
data.tar.gz: fdc4b3eb8f0e94024793a0d0d6c2b9820050a3a0e7aa3501db4427579b23a5d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5aeb2e55053f293e7f590607466953ff4eceba1d6fd534d9c7925813d09799a1a88af1b3cb1c61e6d77ef625e9c4e5a0d95a7e4e9bbb07554601e12612d8cb83
|
|
7
|
+
data.tar.gz: 97a00586b27ff4ae6f2fd98ba5e7b054f0b7be1f644fa0567fa164417446703fc64f398ece8313efa30391689babdd496caaf268ac4456febd9b52b036a1261c
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Naming/FileName:
|
|
2
|
+
Exclude:
|
|
3
|
+
- "lib/datadog-notifications.rb"
|
|
4
|
+
|
|
5
|
+
Metrics/AbcSize:
|
|
6
|
+
Enabled: false
|
|
7
|
+
Metrics/BlockLength:
|
|
8
|
+
Exclude:
|
|
9
|
+
- "**/*_spec.rb"
|
|
10
|
+
Metrics/ClassLength:
|
|
11
|
+
Max: 1500
|
|
12
|
+
Metrics/CyclomaticComplexity:
|
|
13
|
+
Enabled: false
|
|
14
|
+
Metrics/PerceivedComplexity:
|
|
15
|
+
Enabled: false
|
|
16
|
+
Metrics/LineLength:
|
|
17
|
+
Max: 160
|
|
18
|
+
Metrics/MethodLength:
|
|
19
|
+
Max: 20
|
|
20
|
+
Metrics/ModuleLength:
|
|
21
|
+
Exclude:
|
|
22
|
+
- "**/*_spec.rb"
|
|
23
|
+
|
|
24
|
+
Layout/AlignHash:
|
|
25
|
+
EnforcedHashRocketStyle: table
|
|
26
|
+
Layout/AlignParameters:
|
|
27
|
+
EnforcedStyle: with_fixed_indentation
|
|
28
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
29
|
+
Exclude:
|
|
30
|
+
- "**/*_spec.rb"
|
|
31
|
+
Layout/EmptyLinesAroundClassBody:
|
|
32
|
+
Enabled: false
|
|
33
|
+
Layout/IndentArray:
|
|
34
|
+
EnforcedStyle: consistent
|
|
35
|
+
Layout/MultilineOperationIndentation:
|
|
36
|
+
Enabled: false
|
|
37
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
38
|
+
EnforcedStyle: no_space
|
|
39
|
+
Layout/SpaceInsideBlockBraces:
|
|
40
|
+
SpaceBeforeBlockParameters: false
|
|
41
|
+
|
|
42
|
+
Style/BlockDelimiters:
|
|
43
|
+
Enabled: false
|
|
44
|
+
Style/ClassAndModuleChildren:
|
|
45
|
+
Enabled: false
|
|
46
|
+
Style/Documentation:
|
|
47
|
+
Enabled: false
|
|
48
|
+
Style/FrozenStringLiteralComment:
|
|
49
|
+
Enabled: false
|
|
50
|
+
Style/HashSyntax:
|
|
51
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
|
52
|
+
Style/MultilineIfModifier:
|
|
53
|
+
Enabled: false
|
|
54
|
+
Style/NumericLiterals:
|
|
55
|
+
Enabled: false
|
|
56
|
+
Style/Semicolon:
|
|
57
|
+
AllowAsExpressionSeparator: true
|
|
58
|
+
Style/SingleLineBlockParams:
|
|
59
|
+
Enabled: false
|
|
60
|
+
Style/StringLiterals:
|
|
61
|
+
Enabled: false
|
|
62
|
+
Style/SymbolArray:
|
|
63
|
+
Enabled: true
|
|
64
|
+
Style/TrailingCommaInArguments:
|
|
65
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
66
|
+
Style/TrailingCommaInArrayLiteral:
|
|
67
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
68
|
+
Style/TrailingCommaInHashLiteral:
|
|
69
|
+
EnforcedStyleForMultiline: consistent_comma
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
datadog-notifications (0.5.
|
|
4
|
+
datadog-notifications (0.5.1)
|
|
5
5
|
activesupport
|
|
6
6
|
dogstatsd-ruby (~> 3.1)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activemodel (5.1.
|
|
12
|
-
activesupport (= 5.1.
|
|
13
|
-
activerecord (5.1.
|
|
14
|
-
activemodel (= 5.1.
|
|
15
|
-
activesupport (= 5.1.
|
|
11
|
+
activemodel (5.1.6)
|
|
12
|
+
activesupport (= 5.1.6)
|
|
13
|
+
activerecord (5.1.6)
|
|
14
|
+
activemodel (= 5.1.6)
|
|
15
|
+
activesupport (= 5.1.6)
|
|
16
16
|
arel (~> 8.0)
|
|
17
|
-
activesupport (5.1.
|
|
17
|
+
activesupport (5.1.6)
|
|
18
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
|
-
i18n (
|
|
19
|
+
i18n (>= 0.7, < 2)
|
|
20
20
|
minitest (~> 5.1)
|
|
21
21
|
tzinfo (~> 1.1)
|
|
22
22
|
arel (8.0.0)
|
|
23
|
+
ast (2.4.0)
|
|
23
24
|
axiom-types (0.1.1)
|
|
24
25
|
descendants_tracker (~> 0.0.4)
|
|
25
26
|
ice_nine (~> 0.11.0)
|
|
@@ -31,33 +32,38 @@ GEM
|
|
|
31
32
|
descendants_tracker (0.0.4)
|
|
32
33
|
thread_safe (~> 0.3, >= 0.3.1)
|
|
33
34
|
diff-lcs (1.3)
|
|
34
|
-
dogstatsd-ruby (3.
|
|
35
|
+
dogstatsd-ruby (3.3.0)
|
|
35
36
|
equalizer (0.0.11)
|
|
36
|
-
grape (1.0.
|
|
37
|
+
grape (1.0.2)
|
|
37
38
|
activesupport
|
|
38
39
|
builder
|
|
39
40
|
mustermann-grape (~> 1.0.0)
|
|
40
41
|
rack (>= 1.3.0)
|
|
41
42
|
rack-accept
|
|
42
43
|
virtus (>= 1.0.0)
|
|
43
|
-
i18n (0.
|
|
44
|
+
i18n (1.0.0)
|
|
44
45
|
concurrent-ruby (~> 1.0)
|
|
45
46
|
ice_nine (0.11.2)
|
|
46
|
-
minitest (5.11.
|
|
47
|
-
mustermann (1.0.
|
|
47
|
+
minitest (5.11.3)
|
|
48
|
+
mustermann (1.0.2)
|
|
48
49
|
mustermann-grape (1.0.0)
|
|
49
50
|
mustermann (~> 1.0.0)
|
|
50
|
-
|
|
51
|
+
parallel (1.12.1)
|
|
52
|
+
parser (2.5.0.5)
|
|
53
|
+
ast (~> 2.4.0)
|
|
54
|
+
powerpack (0.1.1)
|
|
55
|
+
rack (2.0.4)
|
|
51
56
|
rack-accept (0.4.5)
|
|
52
57
|
rack (>= 0.4)
|
|
53
|
-
rack-test (0.
|
|
58
|
+
rack-test (1.0.0)
|
|
54
59
|
rack (>= 1.0, < 3)
|
|
55
|
-
|
|
60
|
+
rainbow (3.0.0)
|
|
61
|
+
rake (12.3.1)
|
|
56
62
|
rspec (3.7.0)
|
|
57
63
|
rspec-core (~> 3.7.0)
|
|
58
64
|
rspec-expectations (~> 3.7.0)
|
|
59
65
|
rspec-mocks (~> 3.7.0)
|
|
60
|
-
rspec-core (3.7.
|
|
66
|
+
rspec-core (3.7.1)
|
|
61
67
|
rspec-support (~> 3.7.0)
|
|
62
68
|
rspec-expectations (3.7.0)
|
|
63
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
@@ -65,11 +71,20 @@ GEM
|
|
|
65
71
|
rspec-mocks (3.7.0)
|
|
66
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
67
73
|
rspec-support (~> 3.7.0)
|
|
68
|
-
rspec-support (3.7.
|
|
74
|
+
rspec-support (3.7.1)
|
|
75
|
+
rubocop (0.54.0)
|
|
76
|
+
parallel (~> 1.10)
|
|
77
|
+
parser (>= 2.5)
|
|
78
|
+
powerpack (~> 0.1)
|
|
79
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
80
|
+
ruby-progressbar (~> 1.7)
|
|
81
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
82
|
+
ruby-progressbar (1.9.0)
|
|
69
83
|
sqlite3 (1.3.13)
|
|
70
84
|
thread_safe (0.3.6)
|
|
71
|
-
tzinfo (1.2.
|
|
85
|
+
tzinfo (1.2.5)
|
|
72
86
|
thread_safe (~> 0.1)
|
|
87
|
+
unicode-display_width (1.3.0)
|
|
73
88
|
virtus (1.0.5)
|
|
74
89
|
axiom-types (~> 0.1)
|
|
75
90
|
coercible (~> 1.0)
|
|
@@ -87,7 +102,8 @@ DEPENDENCIES
|
|
|
87
102
|
rack-test
|
|
88
103
|
rake
|
|
89
104
|
rspec
|
|
105
|
+
rubocop
|
|
90
106
|
sqlite3
|
|
91
107
|
|
|
92
108
|
BUNDLED WITH
|
|
93
|
-
1.16.
|
|
109
|
+
1.16.1
|
data/Rakefile
CHANGED
|
@@ -3,8 +3,8 @@ require "bundler/gem_tasks"
|
|
|
3
3
|
begin
|
|
4
4
|
Bundler.setup(:default, :development)
|
|
5
5
|
rescue Bundler::BundlerError => e
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
warn e.message
|
|
7
|
+
warn "Run `bundle install` to install missing gems"
|
|
8
8
|
exit e.status_code
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -17,4 +17,7 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
|
17
17
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
require 'rubocop/rake_task'
|
|
21
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
22
|
+
|
|
23
|
+
task default: %i[spec rubocop]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
lib = File.expand_path('
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'datadog/notifications/version'
|
|
5
5
|
|
|
@@ -8,22 +8,23 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.version = Datadog::Notifications::VERSION.dup
|
|
9
9
|
s.authors = ["Dimitrij Denissenko"]
|
|
10
10
|
s.email = ["dimitrij@blacksquaremedia.com"]
|
|
11
|
-
s.description =
|
|
12
|
-
s.summary =
|
|
11
|
+
s.description = 'Datadog instrumnetation for ActiveSupport::Notifications'
|
|
12
|
+
s.summary = 'Generic ActiveSupport::Notifications Datadog handler'
|
|
13
13
|
s.homepage = "https://github.com/bsm/datadog-notifications"
|
|
14
14
|
|
|
15
|
-
s.files = `git ls-files`.split(
|
|
15
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
16
16
|
s.test_files = s.files.grep(%r{^(spec)/})
|
|
17
17
|
s.require_paths = ["lib"]
|
|
18
18
|
|
|
19
|
-
s.add_runtime_dependency(
|
|
20
|
-
s.add_runtime_dependency(
|
|
19
|
+
s.add_runtime_dependency('activesupport')
|
|
20
|
+
s.add_runtime_dependency('dogstatsd-ruby', "~> 3.1")
|
|
21
21
|
|
|
22
|
-
s.add_development_dependency(
|
|
23
|
-
s.add_development_dependency(
|
|
24
|
-
s.add_development_dependency(
|
|
25
|
-
s.add_development_dependency(
|
|
26
|
-
s.add_development_dependency(
|
|
27
|
-
s.add_development_dependency(
|
|
28
|
-
s.add_development_dependency(
|
|
22
|
+
s.add_development_dependency('activerecord')
|
|
23
|
+
s.add_development_dependency('bundler')
|
|
24
|
+
s.add_development_dependency('grape', ">= 0.16")
|
|
25
|
+
s.add_development_dependency('rack-test')
|
|
26
|
+
s.add_development_dependency('rake')
|
|
27
|
+
s.add_development_dependency('rspec')
|
|
28
|
+
s.add_development_dependency('rubocop')
|
|
29
|
+
s.add_development_dependency('sqlite3')
|
|
29
30
|
end
|
|
@@ -31,7 +31,7 @@ module Datadog
|
|
|
31
31
|
# * <tt>reporter</tt> - custom reporter class, defaults to `Datadog::Notifications::Reporter`
|
|
32
32
|
def self.configure(&block)
|
|
33
33
|
if instance.instance_variable_defined?(:@reporter)
|
|
34
|
-
warn "#{
|
|
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
37
|
block.call instance.config if block
|
|
@@ -62,9 +62,9 @@ module Datadog
|
|
|
62
62
|
@config = Config.new
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def subscribe(pattern
|
|
65
|
+
def subscribe(pattern)
|
|
66
66
|
ActiveSupport::Notifications.subscribe(pattern) do |*args|
|
|
67
|
-
|
|
67
|
+
yield reporter, ActiveSupport::Notifications::Event.new(*args)
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
@@ -7,7 +7,7 @@ module Datadog::Notifications::Plugins
|
|
|
7
7
|
#
|
|
8
8
|
# *<tt>:metric_name</tt> - the metric name, defaults to "rails.request"
|
|
9
9
|
# *<tt>:tags</tt> - additional tags
|
|
10
|
-
def initialize(opts
|
|
10
|
+
def initialize(opts={})
|
|
11
11
|
super
|
|
12
12
|
@metric_name = opts[:metric_name] || "rails.request"
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ module Datadog::Notifications::Plugins
|
|
|
25
25
|
action = payload[:action]
|
|
26
26
|
ctrl = payload[:controller].sub(/Controller$/, '').underscore
|
|
27
27
|
format = payload[:format]
|
|
28
|
-
tags = self.tags + %W
|
|
28
|
+
tags = self.tags + %W[method:#{method} status:#{status} action:#{action} controller:#{ctrl} format:#{format}]
|
|
29
29
|
|
|
30
30
|
reporter.batch do
|
|
31
31
|
reporter.increment metric_name, tags: tags
|
|
@@ -7,7 +7,7 @@ module Datadog::Notifications::Plugins
|
|
|
7
7
|
#
|
|
8
8
|
# *<tt>:metric_name</tt> - the metric name, defaults to "activejob.perform"
|
|
9
9
|
# *<tt>:tags</tt> - additional tags
|
|
10
|
-
def initialize(opts
|
|
10
|
+
def initialize(opts={})
|
|
11
11
|
super
|
|
12
12
|
@metric_name = opts[:metric_name] || "activejob.perform"
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ module Datadog::Notifications::Plugins
|
|
|
21
21
|
def record(reporter, event)
|
|
22
22
|
job = event.payload[:job]
|
|
23
23
|
name = job.class.name.sub(/Job$/, '').underscore
|
|
24
|
-
tags = self.tags + %W
|
|
24
|
+
tags = self.tags + %W[job:#{name} queue:#{job.queue_name}]
|
|
25
25
|
|
|
26
26
|
reporter.batch do
|
|
27
27
|
reporter.increment metric_name, tags: tags
|
|
@@ -9,7 +9,7 @@ module Datadog::Notifications::Plugins
|
|
|
9
9
|
# *<tt>:include_schema</tt> - record schema queries, off by default
|
|
10
10
|
# *<tt>:include_generic</tt> - record general (nameless) queries, off by default
|
|
11
11
|
# *<tt>:tags</tt> - additional tags
|
|
12
|
-
def initialize(opts
|
|
12
|
+
def initialize(opts={})
|
|
13
13
|
super
|
|
14
14
|
@metric_name = opts[:metric_name] || "activerecord.sql"
|
|
15
15
|
@include_schema = opts[:include_schema] == true
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
module Datadog::Notifications::Plugins
|
|
2
2
|
class Grape < Base
|
|
3
3
|
|
|
4
|
+
def self.exception_status(err)
|
|
5
|
+
err.respond_to?(:status) ? err.status : 500
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
attr_reader :metric_name, :exception_handler
|
|
5
9
|
|
|
6
10
|
# Options:
|
|
@@ -8,10 +12,10 @@ module Datadog::Notifications::Plugins
|
|
|
8
12
|
# *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
|
|
9
13
|
# *<tt>:exception_handler</tt> - a custom exception handler proc which accepts an exception object and returns a status
|
|
10
14
|
# *<tt>:tags</tt> - additional tags
|
|
11
|
-
def initialize(opts
|
|
15
|
+
def initialize(opts={})
|
|
12
16
|
super
|
|
13
17
|
@metric_name = opts[:metric_name] || "grape.request"
|
|
14
|
-
@exception_handler = opts[:exception_handler] || ->
|
|
18
|
+
@exception_handler = opts[:exception_handler] || ->(e) { self.class.exception_status(e) }
|
|
15
19
|
|
|
16
20
|
Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
|
|
17
21
|
record reporter, event
|
|
@@ -23,23 +27,17 @@ module Datadog::Notifications::Plugins
|
|
|
23
27
|
def record(reporter, event)
|
|
24
28
|
payload = event.payload
|
|
25
29
|
endpoint = payload[:endpoint]
|
|
26
|
-
|
|
27
|
-
version = route.version
|
|
28
|
-
method = route.request_method
|
|
29
|
-
status = endpoint.status
|
|
30
|
+
method = endpoint.request.request_method
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
32
|
+
status = endpoint.status
|
|
33
|
+
status = exception_handler.call(payload[:exception_object]) if payload[:exception_object]
|
|
34
34
|
|
|
35
|
-
path =
|
|
36
|
-
path.
|
|
37
|
-
path.sub!(":version/", "") if version
|
|
38
|
-
path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
|
|
39
|
-
path.gsub!(/[^\w\/\-]+/, '_')
|
|
35
|
+
path = extract_path(endpoint)
|
|
36
|
+
path.gsub!(%r{[^\w\/\-]+}, '_')
|
|
40
37
|
|
|
41
|
-
tags = self.tags + %W
|
|
42
|
-
tags.push "
|
|
38
|
+
tags = self.tags + %W[method:#{method} status:#{status}]
|
|
39
|
+
tags.push "path:#{path}" if path
|
|
40
|
+
tags.push "version:#{endpoint.version}" if endpoint.version
|
|
43
41
|
|
|
44
42
|
reporter.batch do
|
|
45
43
|
reporter.increment metric_name, tags: tags
|
|
@@ -47,5 +45,20 @@ module Datadog::Notifications::Plugins
|
|
|
47
45
|
end
|
|
48
46
|
end
|
|
49
47
|
|
|
48
|
+
def extract_path(endpoint)
|
|
49
|
+
route = begin
|
|
50
|
+
endpoint.route
|
|
51
|
+
rescue NoMethodError
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
return endpoint.request.path unless route
|
|
55
|
+
|
|
56
|
+
path = endpoint.route.path.dup
|
|
57
|
+
path.sub!(/\(\.\:format\)$/, '')
|
|
58
|
+
path.sub!(":version/", "") if endpoint.version
|
|
59
|
+
path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
|
|
60
|
+
path
|
|
61
|
+
end
|
|
62
|
+
|
|
50
63
|
end
|
|
51
64
|
end
|
|
@@ -7,7 +7,7 @@ describe Datadog::Notifications::Plugins::ActiveRecord do
|
|
|
7
7
|
expect(buffered).to eq([
|
|
8
8
|
"activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load",
|
|
9
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 skip unnamed by default' do
|
|
@@ -20,7 +20,7 @@ describe Datadog::Notifications::Plugins::ActiveRecord do
|
|
|
20
20
|
expect(buffered).to eq([
|
|
21
21
|
"activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load",
|
|
22
22
|
"activerecord.sql.time:333|ms|#custom:tag,env:test,host:test.host,query:post.load",
|
|
23
|
-
])
|
|
23
|
+
],)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
end
|
|
@@ -15,7 +15,7 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
|
15
15
|
|
|
16
16
|
Class.new(Grape::API) do
|
|
17
17
|
|
|
18
|
-
rescue_from unauthorized do |
|
|
18
|
+
rescue_from unauthorized do |_e|
|
|
19
19
|
error!({ message: "unauthorized", error: '401 Unauthorized' }, 401)
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ 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
|
|
@@ -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
|
-
"api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/echo/KEY1/KEY2
|
|
47
|
-
"api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/echo/KEY1/KEY2
|
|
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
|
-
"api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/api/sub/versioned,
|
|
58
|
-
"api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/api/sub/versioned,
|
|
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
|
-
"api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/sub/secure/resource
|
|
69
|
-
"api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/sub/secure/resource
|
|
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,19 @@ describe Datadog::Notifications::Plugins::Grape do
|
|
|
75
75
|
expect(last_response.status).to eq(401)
|
|
76
76
|
|
|
77
77
|
expect(buffered).to eq([
|
|
78
|
-
"api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/rescued
|
|
79
|
-
"api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/rescued
|
|
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
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should handle invalid method' do
|
|
84
|
+
post '/rescued'
|
|
85
|
+
|
|
86
|
+
expect(last_response.status).to eq(405)
|
|
87
|
+
expect(buffered).to eq([
|
|
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
|
+
],)
|
|
81
91
|
end
|
|
82
92
|
|
|
83
93
|
it 'should not report paths on 404s' do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -22,13 +22,16 @@ end
|
|
|
22
22
|
|
|
23
23
|
module Mock
|
|
24
24
|
class Reporter < Datadog::Notifications::Reporter
|
|
25
|
-
def timing(stat,
|
|
25
|
+
def timing(stat, _ms, opts={})
|
|
26
|
+
super(stat, 333, opts)
|
|
27
|
+
end
|
|
28
|
+
|
|
26
29
|
def flush_buffer; end
|
|
27
30
|
@should_batch = true
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
class Instrumentable
|
|
31
|
-
def initialize(opts
|
|
34
|
+
def initialize(opts={})
|
|
32
35
|
@opts = opts
|
|
33
36
|
end
|
|
34
37
|
|
|
@@ -65,5 +68,11 @@ Datadog::Notifications.configure do |c|
|
|
|
65
68
|
c.use Datadog::Notifications::Plugins::Grape,
|
|
66
69
|
tags: ["more:tags"],
|
|
67
70
|
metric_name: "api.request",
|
|
68
|
-
exception_handler:
|
|
71
|
+
exception_handler: lambda {|e|
|
|
72
|
+
if e.message.include?('unauthorized')
|
|
73
|
+
401
|
|
74
|
+
else
|
|
75
|
+
Datadog::Notifications::Plugins::Grape.exception_status(e)
|
|
76
|
+
end
|
|
77
|
+
}
|
|
69
78
|
end
|
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.5.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dimitrij Denissenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -39,7 +39,21 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '3.1'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: activerecord
|
|
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'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
44
58
|
requirements:
|
|
45
59
|
- - ">="
|
|
@@ -67,7 +81,7 @@ dependencies:
|
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
82
|
version: '0.16'
|
|
69
83
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
84
|
+
name: rack-test
|
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
|
72
86
|
requirements:
|
|
73
87
|
- - ">="
|
|
@@ -81,7 +95,7 @@ dependencies:
|
|
|
81
95
|
- !ruby/object:Gem::Version
|
|
82
96
|
version: '0'
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
98
|
+
name: rake
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
|
86
100
|
requirements:
|
|
87
101
|
- - ">="
|
|
@@ -95,7 +109,7 @@ dependencies:
|
|
|
95
109
|
- !ruby/object:Gem::Version
|
|
96
110
|
version: '0'
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
|
-
name:
|
|
112
|
+
name: rspec
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
100
114
|
requirements:
|
|
101
115
|
- - ">="
|
|
@@ -109,7 +123,7 @@ dependencies:
|
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
124
|
version: '0'
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
|
-
name:
|
|
126
|
+
name: rubocop
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
114
128
|
requirements:
|
|
115
129
|
- - ">="
|
|
@@ -123,7 +137,7 @@ dependencies:
|
|
|
123
137
|
- !ruby/object:Gem::Version
|
|
124
138
|
version: '0'
|
|
125
139
|
- !ruby/object:Gem::Dependency
|
|
126
|
-
name:
|
|
140
|
+
name: sqlite3
|
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
|
128
142
|
requirements:
|
|
129
143
|
- - ">="
|
|
@@ -145,6 +159,7 @@ extra_rdoc_files: []
|
|
|
145
159
|
files:
|
|
146
160
|
- ".editorconfig"
|
|
147
161
|
- ".gitignore"
|
|
162
|
+
- ".rubocop.yml"
|
|
148
163
|
- ".travis.yml"
|
|
149
164
|
- Gemfile
|
|
150
165
|
- Gemfile.lock
|
|
@@ -187,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
187
202
|
version: '0'
|
|
188
203
|
requirements: []
|
|
189
204
|
rubyforge_project:
|
|
190
|
-
rubygems_version: 2.
|
|
205
|
+
rubygems_version: 2.7.3
|
|
191
206
|
signing_key:
|
|
192
207
|
specification_version: 4
|
|
193
208
|
summary: Generic ActiveSupport::Notifications Datadog handler
|