datadog-notifications 0.5.0 → 0.5.1

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
- SHA1:
3
- metadata.gz: 3943b130b68fe53f30758de998b556506505521e
4
- data.tar.gz: ff8c6d33b47d1067040344ab2f2306b48fda70ab
2
+ SHA256:
3
+ metadata.gz: 2257233489d7e6bc50b0e9a88e111d2ad44137f1cd0c88b03a98d8a9ab6d76b0
4
+ data.tar.gz: fdc4b3eb8f0e94024793a0d0d6c2b9820050a3a0e7aa3501db4427579b23a5d9
5
5
  SHA512:
6
- metadata.gz: 9e6dfb6604042676d8550dac8bf978ad64c17bbb1f3c29bd998cbe1f4804d7af4e1595919c30a87493c419fd356633f0b397a6992bb16b0c82ce2227bfae8329
7
- data.tar.gz: 6074e39f9e3ff6b3fdea446090f8bb0375b1dc8b9e5b8f612bce5097f2525819fcc04b41ce5be351ec7007ec73db8d0092fc6ed903ed698e25a687109e2414fb
6
+ metadata.gz: 5aeb2e55053f293e7f590607466953ff4eceba1d6fd534d9c7925813d09799a1a88af1b3cb1c61e6d77ef625e9c4e5a0d95a7e4e9bbb07554601e12612d8cb83
7
+ data.tar.gz: 97a00586b27ff4ae6f2fd98ba5e7b054f0b7be1f644fa0567fa164417446703fc64f398ece8313efa30391689babdd496caaf268ac4456febd9b52b036a1261c
@@ -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
@@ -1,6 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
5
- - 2.3.3
6
- - 2.2.6
4
+ - 2.5
5
+ - 2.4
6
+ - 2.3
7
+ - 2.2
@@ -1,25 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datadog-notifications (0.5.0)
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.4)
12
- activesupport (= 5.1.4)
13
- activerecord (5.1.4)
14
- activemodel (= 5.1.4)
15
- activesupport (= 5.1.4)
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.4)
17
+ activesupport (5.1.6)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
- i18n (~> 0.7)
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.2.0)
35
+ dogstatsd-ruby (3.3.0)
35
36
  equalizer (0.0.11)
36
- grape (1.0.1)
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.9.1)
44
+ i18n (1.0.0)
44
45
  concurrent-ruby (~> 1.0)
45
46
  ice_nine (0.11.2)
46
- minitest (5.11.0)
47
- mustermann (1.0.1)
47
+ minitest (5.11.3)
48
+ mustermann (1.0.2)
48
49
  mustermann-grape (1.0.0)
49
50
  mustermann (~> 1.0.0)
50
- rack (2.0.3)
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.8.2)
58
+ rack-test (1.0.0)
54
59
  rack (>= 1.0, < 3)
55
- rake (12.3.0)
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.0)
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.0)
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.4)
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.0
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
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
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
- task :default => :spec
20
+ require 'rubocop/rake_task'
21
+ RuboCop::RakeTask.new(:rubocop)
22
+
23
+ task default: %i[spec rubocop]
@@ -1,5 +1,5 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
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 = %q{Datadog instrumnetation for ActiveSupport::Notifications}
12
- s.summary = %q{Generic ActiveSupport::Notifications Datadog handler}
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(%q<activesupport>)
20
- s.add_runtime_dependency(%q<dogstatsd-ruby>, "~> 3.1")
19
+ s.add_runtime_dependency('activesupport')
20
+ s.add_runtime_dependency('dogstatsd-ruby', "~> 3.1")
21
21
 
22
- s.add_development_dependency(%q<rack-test>)
23
- s.add_development_dependency(%q<grape>, ">= 0.16")
24
- s.add_development_dependency(%q<sqlite3>)
25
- s.add_development_dependency(%q<activerecord>)
26
- s.add_development_dependency(%q<rake>)
27
- s.add_development_dependency(%q<bundler>)
28
- s.add_development_dependency(%q<rspec>)
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 "#{self.name} cannot be reconfigured once it has subscribed to notifications, called from: #{caller[1]}"
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, &block)
65
+ def subscribe(pattern)
66
66
  ActiveSupport::Notifications.subscribe(pattern) do |*args|
67
- block.call reporter, ActiveSupport::Notifications::Event.new(*args)
67
+ yield reporter, ActiveSupport::Notifications::Event.new(*args)
68
68
  end
69
69
  end
70
70
 
@@ -14,7 +14,7 @@ module Datadog
14
14
  end
15
15
 
16
16
  # Use a plugin
17
- def use(klass, opts = {})
17
+ def use(klass, opts={})
18
18
  @plugins.push klass.new(opts)
19
19
  end
20
20
 
@@ -5,6 +5,6 @@ module Datadog
5
5
  end
6
6
  end
7
7
 
8
- %w|base grape active_record active_job action_controller|.each do |name|
8
+ %w[base grape active_record active_job action_controller].each do |name|
9
9
  require "datadog/notifications/plugins/#{name}"
10
10
  end
@@ -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|method:#{method} status:#{status} action:#{action} controller:#{ctrl} format:#{format}|
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|job:#{name} queue:#{job.queue_name}|
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
@@ -5,7 +5,7 @@ module Datadog::Notifications::Plugins
5
5
  # Options:
6
6
  #
7
7
  # *<tt>:tags</tt> - additional tags
8
- def initialize(opts = {})
8
+ def initialize(opts={})
9
9
  @tags = opts[:tags] || []
10
10
  end
11
11
 
@@ -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] || ->_ { 500 }
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
- route = endpoint.route
27
- version = route.version
28
- method = route.request_method
29
- status = endpoint.status
30
+ method = endpoint.request.request_method
30
31
 
31
- if payload[:exception_object]
32
- status = exception_handler.call(payload[:exception_object])
33
- end
32
+ status = endpoint.status
33
+ status = exception_handler.call(payload[:exception_object]) if payload[:exception_object]
34
34
 
35
- path = route.pattern.path.dup
36
- path.sub!(/\(\.\:format\)$/, '')
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|method:#{method} path:#{path} status:#{status}|
42
- tags.push "version:#{version}" if version
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
@@ -1,5 +1,5 @@
1
1
  module Datadog
2
2
  class Notifications
3
- VERSION = "0.5.0"
3
+ VERSION = '0.5.1'.freeze
4
4
  end
5
5
  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 |e|
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.new("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,status:200",
47
- "api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/echo/KEY1/KEY2,status:200",
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,status:200,version:v1",
58
- "api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/api/sub/versioned,status:200,version:v1",
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,status:403",
69
- "api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/sub/secure/resource,status:403",
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,status:401",
79
- "api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,path:/rescued,status:401",
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
@@ -27,7 +27,7 @@ describe Datadog::Notifications do
27
27
  expect(buffered).to eq([
28
28
  "web.render:1|c|#custom:tag,env:test,host:test.host,status:200,method:GET",
29
29
  "web.render.time:333|ms|#custom:tag,env:test,host:test.host,status:200,method:GET",
30
- ])
30
+ ],)
31
31
  end
32
32
 
33
33
  end
@@ -22,13 +22,16 @@ end
22
22
 
23
23
  module Mock
24
24
  class Reporter < Datadog::Notifications::Reporter
25
- def timing(stat, ms, opts={}); super(stat, 333, opts); end
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: ->e { e.message.include?("unauthorized") ? 401 : 500 }
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.0
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-01-02 00:00:00.000000000 Z
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: rack-test
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: sqlite3
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: activerecord
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: rake
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: bundler
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: rspec
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.6.11
205
+ rubygems_version: 2.7.3
191
206
  signing_key:
192
207
  specification_version: 4
193
208
  summary: Generic ActiveSupport::Notifications Datadog handler