datadog-notifications 0.6.2 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38a9e7c3163df4e1427b18ea7216e1b014d7bd3ba51a1aa0ff133de1990a6227
4
- data.tar.gz: 0e1f66f6fea54e0934dd85d3e0ac351070ebd7652c6e0577e55aee10b887c067
3
+ metadata.gz: 0fe55c10d1c135748c2a818187431d0f316a8cf0192cefdf7ab45d6245e6add9
4
+ data.tar.gz: f9449725f5768bb0e75eb02363f12eda4235e474d7fb00e6f7cc4c2b54c599d2
5
5
  SHA512:
6
- metadata.gz: 5362759bfa74f7cc6878861099b77eca4e933221f1f7eec74bff99a40551a21ed1bc5366895d1896ff79cc048d3e3fe00001a6fea20587b7ef4483caf45b220b
7
- data.tar.gz: b58dc570f252838b4ad991345652218cd9026d3d78a70ef25d1dfca91577836267a054bbe56b42d45fb2ddb07c269ba10f369e28431fa899a6453db7abdfbe0d
6
+ metadata.gz: e649e3040acec1a88eb92075b555ed4ba7c2c7533544ba2c4da01d41627dcd570bede8315c1759018351803eca2b9f00e84b95533ebb5d6412f7ada6705dac3d
7
+ data.tar.gz: 1077d3018207521015a4f4c5025c032b84405377d43a789a27b1153154eafac83e955abc75a5d4cb558073242caed193e3a018ae8251058ce88379a5c7e078ec
@@ -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.6", "2.7", "3.0"]
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
- inherit_from:
2
- - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
1
+ inherit_gem:
2
+ rubocop-bsm:
3
+ - default.yml
4
+ inherit_mode:
5
+ merge:
6
+ - Exclude
3
7
 
4
8
  AllCops:
5
- TargetRubyVersion: "2.5"
9
+ TargetRubyVersion: "2.6"
6
10
 
7
11
  Naming/FileName:
8
12
  Exclude:
data/Gemfile.lock CHANGED
@@ -1,100 +1,133 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datadog-notifications (0.6.2)
4
+ datadog-notifications (0.6.7)
5
5
  activesupport
6
- dogstatsd-ruby (>= 4.2, < 5.0)
6
+ dogstatsd-ruby (>= 4.8, < 5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.2.1)
12
- activesupport (= 6.0.2.1)
13
- activerecord (6.0.2.1)
14
- activemodel (= 6.0.2.1)
15
- activesupport (= 6.0.2.1)
16
- activesupport (6.0.2.1)
11
+ activejob (6.1.3)
12
+ activesupport (= 6.1.3)
13
+ globalid (>= 0.3.6)
14
+ activemodel (6.1.3)
15
+ activesupport (= 6.1.3)
16
+ activerecord (6.1.3)
17
+ activemodel (= 6.1.3)
18
+ activesupport (= 6.1.3)
19
+ activesupport (6.1.3)
17
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (>= 0.7, < 2)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- zeitwerk (~> 2.2)
22
- ast (2.4.0)
23
- axiom-types (0.1.1)
24
- descendants_tracker (~> 0.0.4)
25
- ice_nine (~> 0.11.0)
26
- thread_safe (~> 0.3, >= 0.3.1)
21
+ i18n (>= 1.6, < 2)
22
+ minitest (>= 5.1)
23
+ tzinfo (~> 2.0)
24
+ zeitwerk (~> 2.3)
25
+ ast (2.4.2)
27
26
  builder (3.2.4)
28
- coercible (1.0.0)
29
- descendants_tracker (~> 0.0.1)
30
- concurrent-ruby (1.1.5)
31
- descendants_tracker (0.0.4)
32
- thread_safe (~> 0.3, >= 0.3.1)
33
- diff-lcs (1.3)
34
- dogstatsd-ruby (4.5.0)
35
- equalizer (0.0.11)
36
- grape (1.2.5)
27
+ concurrent-ruby (1.1.8)
28
+ diff-lcs (1.4.4)
29
+ dogstatsd-ruby (4.8.3)
30
+ dry-configurable (0.12.1)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-core (~> 0.5, >= 0.5.0)
33
+ dry-container (0.7.2)
34
+ concurrent-ruby (~> 1.0)
35
+ dry-configurable (~> 0.1, >= 0.1.3)
36
+ dry-core (0.5.0)
37
+ concurrent-ruby (~> 1.0)
38
+ dry-inflector (0.2.0)
39
+ dry-logic (1.1.0)
40
+ concurrent-ruby (~> 1.0)
41
+ dry-core (~> 0.5, >= 0.5)
42
+ dry-types (1.5.1)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-container (~> 0.3)
45
+ dry-core (~> 0.5, >= 0.5)
46
+ dry-inflector (~> 0.1, >= 0.1.2)
47
+ dry-logic (~> 1.0, >= 1.0.2)
48
+ globalid (0.4.2)
49
+ activesupport (>= 4.2.0)
50
+ grape (1.5.2)
37
51
  activesupport
38
52
  builder
53
+ dry-types (>= 1.1)
39
54
  mustermann-grape (~> 1.0.0)
40
55
  rack (>= 1.3.0)
41
56
  rack-accept
42
- virtus (>= 1.0.0)
43
- i18n (1.7.0)
57
+ i18n (1.8.9)
44
58
  concurrent-ruby (~> 1.0)
45
- ice_nine (0.11.2)
46
- jaro_winkler (1.5.4)
47
- minitest (5.13.0)
48
- mustermann (1.0.3)
49
- mustermann-grape (1.0.0)
50
- mustermann (~> 1.0.0)
51
- parallel (1.19.1)
52
- parser (2.7.0.1)
53
- ast (~> 2.4.0)
54
- rack (2.0.8)
59
+ minitest (5.14.4)
60
+ mustermann (1.1.1)
61
+ ruby2_keywords (~> 0.0.1)
62
+ mustermann-grape (1.0.1)
63
+ mustermann (>= 1.0.0)
64
+ parallel (1.20.1)
65
+ parser (3.0.0.0)
66
+ ast (~> 2.4.1)
67
+ rack (2.2.3)
55
68
  rack-accept (0.4.5)
56
69
  rack (>= 0.4)
57
70
  rack-test (1.1.0)
58
71
  rack (>= 1.0, < 3)
59
72
  rainbow (3.0.0)
60
- rake (13.0.1)
61
- rspec (3.9.0)
62
- rspec-core (~> 3.9.0)
63
- rspec-expectations (~> 3.9.0)
64
- rspec-mocks (~> 3.9.0)
65
- rspec-core (3.9.1)
66
- rspec-support (~> 3.9.1)
67
- rspec-expectations (3.9.0)
73
+ rake (13.0.3)
74
+ regexp_parser (2.1.1)
75
+ rexml (3.2.5)
76
+ rspec (3.10.0)
77
+ rspec-core (~> 3.10.0)
78
+ rspec-expectations (~> 3.10.0)
79
+ rspec-mocks (~> 3.10.0)
80
+ rspec-core (3.10.1)
81
+ rspec-support (~> 3.10.0)
82
+ rspec-expectations (3.10.1)
68
83
  diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.9.0)
70
- rspec-mocks (3.9.1)
84
+ rspec-support (~> 3.10.0)
85
+ rspec-mocks (3.10.2)
71
86
  diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.9.0)
73
- rspec-support (3.9.2)
74
- rubocop (0.78.0)
75
- jaro_winkler (~> 1.5.1)
87
+ rspec-support (~> 3.10.0)
88
+ rspec-support (3.10.2)
89
+ rubocop (1.11.0)
76
90
  parallel (~> 1.10)
77
- parser (>= 2.6)
91
+ parser (>= 3.0.0.0)
78
92
  rainbow (>= 2.2.2, < 4.0)
93
+ regexp_parser (>= 1.8, < 3.0)
94
+ rexml
95
+ rubocop-ast (>= 1.2.0, < 2.0)
79
96
  ruby-progressbar (~> 1.7)
80
- unicode-display_width (>= 1.4.0, < 1.7)
81
- ruby-progressbar (1.10.1)
97
+ unicode-display_width (>= 1.4.0, < 3.0)
98
+ rubocop-ast (1.4.1)
99
+ parser (>= 2.7.1.5)
100
+ rubocop-bsm (0.5.4)
101
+ rubocop (~> 1.0)
102
+ rubocop-performance
103
+ rubocop-rails
104
+ rubocop-rake
105
+ rubocop-rspec
106
+ rubocop-performance (1.10.1)
107
+ rubocop (>= 0.90.0, < 2.0)
108
+ rubocop-ast (>= 0.4.0)
109
+ rubocop-rails (2.9.1)
110
+ activesupport (>= 4.2.0)
111
+ rack (>= 1.1)
112
+ rubocop (>= 0.90.0, < 2.0)
113
+ rubocop-rake (0.5.1)
114
+ rubocop
115
+ rubocop-rspec (2.2.0)
116
+ rubocop (~> 1.0)
117
+ rubocop-ast (>= 1.1.0)
118
+ ruby-progressbar (1.11.0)
119
+ ruby2_keywords (0.0.4)
82
120
  sqlite3 (1.4.2)
83
- thread_safe (0.3.6)
84
- tzinfo (1.2.6)
85
- thread_safe (~> 0.1)
86
- unicode-display_width (1.6.0)
87
- virtus (1.0.5)
88
- axiom-types (~> 0.1)
89
- coercible (~> 1.0)
90
- descendants_tracker (~> 0.0, >= 0.0.3)
91
- equalizer (~> 0.0, >= 0.0.9)
92
- zeitwerk (2.2.2)
121
+ tzinfo (2.0.4)
122
+ concurrent-ruby (~> 1.0)
123
+ unicode-display_width (2.0.0)
124
+ zeitwerk (2.4.2)
93
125
 
94
126
  PLATFORMS
95
127
  ruby
96
128
 
97
129
  DEPENDENCIES
130
+ activejob
98
131
  activerecord
99
132
  bundler
100
133
  datadog-notifications!
@@ -102,8 +135,8 @@ DEPENDENCIES
102
135
  rack-test
103
136
  rake
104
137
  rspec
105
- rubocop
138
+ rubocop-bsm
106
139
  sqlite3
107
140
 
108
141
  BUNDLED WITH
109
- 2.1.2
142
+ 2.2.16
@@ -14,17 +14,18 @@ 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.5'
17
+ s.required_ruby_version = '>= 2.6'
18
18
 
19
19
  s.add_runtime_dependency 'activesupport'
20
- s.add_runtime_dependency 'dogstatsd-ruby', '>= 4.2', '< 5.0'
20
+ s.add_runtime_dependency 'dogstatsd-ruby', '>= 4.8', '< 5.0'
21
21
 
22
+ s.add_development_dependency 'activejob'
22
23
  s.add_development_dependency 'activerecord'
23
24
  s.add_development_dependency 'bundler'
24
25
  s.add_development_dependency 'grape', '>= 1.0.2'
25
26
  s.add_development_dependency 'rack-test'
26
27
  s.add_development_dependency 'rake'
27
28
  s.add_development_dependency 'rspec'
28
- s.add_development_dependency 'rubocop'
29
+ s.add_development_dependency 'rubocop-bsm'
29
30
  s.add_development_dependency 'sqlite3'
30
31
  end
@@ -14,22 +14,21 @@ module Datadog
14
14
  end
15
15
 
16
16
  # Use a plugin
17
- def use(klass, opts={})
18
- @plugins.push klass.new(opts)
17
+ def use(klass, **opts)
18
+ @plugins.push klass.new(**opts)
19
19
  end
20
20
 
21
21
  protected
22
22
 
23
23
  def connect!
24
24
  env = ENV['RAILS_ENV'] || ENV['RACK_ENV']
25
- tags.push("env:#{env}") if env && tags.none? {|t| t =~ /^env\:/ }
25
+ tags.push("env:#{env}") if env && tags.none? {|t| t =~ /^env:/ }
26
26
 
27
27
  enable_hostname = hostname && hostname != 'false'
28
- tags.push("host:#{hostname}") if enable_hostname && tags.none? {|t| t =~ /^host\:/ }
28
+ tags.push("host:#{hostname}") if enable_hostname && tags.none? {|t| t =~ /^host:/ }
29
29
 
30
30
  reporter.new statsd_host, statsd_port, namespace: namespace, tags: tags, socket_path: socket_path
31
31
  end
32
-
33
32
  end
34
33
  end
35
34
  end
@@ -1,16 +1,15 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class ActionController < Base
3
-
4
3
  attr_reader :metric_name
5
4
 
6
5
  # Options:
7
6
  #
8
7
  # *<tt>:metric_name</tt> - the metric name, defaults to "rails.request"
9
8
  # *<tt>:tags</tt> - additional tags
10
- def initialize(opts={})
9
+ def initialize(metric_name: 'rails.request', **opts)
11
10
  super
12
- @metric_name = opts[:metric_name] || 'rails.request'
13
11
 
12
+ @metric_name = metric_name
14
13
  Datadog::Notifications.subscribe 'process_action.action_controller' do |reporter, event|
15
14
  record reporter, event
16
15
  end
@@ -34,6 +33,5 @@ module Datadog::Notifications::Plugins
34
33
  reporter.timing "#{metric_name}.time.view", payload[:view_runtime], tags: tags
35
34
  end
36
35
  end
37
-
38
36
  end
39
37
  end
@@ -1,16 +1,15 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class ActiveJob < Base
3
-
4
3
  attr_reader :metric_name
5
4
 
6
5
  # Options:
7
6
  #
8
7
  # *<tt>:metric_name</tt> - the metric name, defaults to "activejob.perform"
9
8
  # *<tt>:tags</tt> - additional tags
10
- def initialize(opts={})
9
+ def initialize(metric_name: 'activejob.perform', **opts)
11
10
  super
12
- @metric_name = opts[:metric_name] || 'activejob.perform'
13
11
 
12
+ @metric_name = metric_name
14
13
  Datadog::Notifications.subscribe 'perform.active_job' do |reporter, event|
15
14
  record reporter, event
16
15
  end
@@ -19,15 +18,15 @@ module Datadog::Notifications::Plugins
19
18
  private
20
19
 
21
20
  def record(reporter, event)
22
- job = event.payload[:job]
23
- name = job.class.name.sub(/Job$/, '').underscore
24
- tags = self.tags + %W[job:#{name} queue:#{job.queue_name}]
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}]
25
25
 
26
26
  reporter.batch do
27
27
  reporter.increment metric_name, tags: tags
28
28
  reporter.timing "#{metric_name}.time", event.duration, tags: tags
29
29
  end
30
30
  end
31
-
32
31
  end
33
32
  end
@@ -1,6 +1,5 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class ActiveRecord < Base
3
-
4
3
  attr_reader :metric_name
5
4
 
6
5
  # Options:
@@ -9,9 +8,10 @@ module Datadog::Notifications::Plugins
9
8
  # *<tt>:include_schema</tt> - record schema queries, off by default
10
9
  # *<tt>:include_generic</tt> - record general (nameless) queries, off by default
11
10
  # *<tt>:tags</tt> - additional tags
12
- def initialize(opts={})
11
+ def initialize(metric_name: 'activerecord.sql', **opts)
13
12
  super
14
- @metric_name = opts[:metric_name] || 'activerecord.sql'
13
+
14
+ @metric_name = metric_name
15
15
  @include_schema = opts[:include_schema] == true
16
16
  @include_generic = opts[:include_generic] == true
17
17
  @include_raw = opts[:include_raw] == true
@@ -38,6 +38,5 @@ module Datadog::Notifications::Plugins
38
38
  reporter.timing "#{metric_name}.time", event.duration, tags: tags
39
39
  end
40
40
  end
41
-
42
41
  end
43
42
  end
@@ -5,9 +5,8 @@ module Datadog::Notifications::Plugins
5
5
  # Options:
6
6
  #
7
7
  # *<tt>:tags</tt> - additional tags
8
- def initialize(opts={})
9
- @tags = opts[:tags] || []
8
+ def initialize(tags: [], **_opts)
9
+ @tags = tags
10
10
  end
11
-
12
11
  end
13
12
  end
@@ -1,5 +1,6 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class Grape < Base
3
+ DEFAULT_EXCEPTION_HANDLER = ->(e) { Grape.exception_status(e) }
3
4
 
4
5
  def self.exception_status(err)
5
6
  err.respond_to?(:status) ? err.status : 500
@@ -12,10 +13,11 @@ module Datadog::Notifications::Plugins
12
13
  # *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
13
14
  # *<tt>:exception_handler</tt> - a custom exception handler proc which accepts an exception object and returns a status
14
15
  # *<tt>:tags</tt> - additional tags
15
- def initialize(opts={})
16
+ def initialize(metric_name: 'grape.request', exception_handler: DEFAULT_EXCEPTION_HANDLER, **opts)
16
17
  super
17
- @metric_name = opts[:metric_name] || 'grape.request'
18
- @exception_handler = opts[:exception_handler] || ->(e) { self.class.exception_status(e) }
18
+
19
+ @metric_name = metric_name
20
+ @exception_handler = exception_handler
19
21
 
20
22
  Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
21
23
  record reporter, event
@@ -33,7 +35,7 @@ module Datadog::Notifications::Plugins
33
35
  status = exception_handler.call(payload[:exception_object]) if payload[:exception_object]
34
36
 
35
37
  path = extract_path(endpoint)
36
- path.gsub!(%r{[^\w\/\-]+}, '_')
38
+ path.gsub!(%r{[^\w/\-]+}, '_')
37
39
 
38
40
  tags = self.tags + %W[method:#{method} status:#{status}]
39
41
  tags.push "path:#{path}" if path
@@ -47,18 +49,17 @@ module Datadog::Notifications::Plugins
47
49
 
48
50
  def extract_path(endpoint)
49
51
  route = begin
50
- endpoint.route
51
- rescue NoMethodError
52
- nil
53
- end
52
+ endpoint.route
53
+ rescue NoMethodError
54
+ nil
55
+ end
54
56
  return endpoint.request.path unless route
55
57
 
56
58
  path = endpoint.route.path.dup
57
- path.sub!(/\(\.\:format\)$/, '')
59
+ path.sub!(/\(\.:format\)$/, '')
58
60
  path.sub!(':version/', '') if endpoint.version
59
- path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
61
+ path.gsub!(/:(\w+)/) {|m| m[1..].upcase }
60
62
  path
61
63
  end
62
-
63
64
  end
64
65
  end
@@ -1,6 +1,5 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class GRPC < Base
3
-
4
3
  # Options:
5
4
  #
6
5
  # *<tt>:metric_name</tt> - the metric name, defaults to 'grpc.request'
@@ -10,10 +9,10 @@ module Datadog::Notifications::Plugins
10
9
  # Notification payload should have :service (service name, string) and :action (service action/method name, string) keys.
11
10
  #
12
11
  # Compatible instrumentation is implemented in grpcx gem: https://github.com/bsm/grpcx (>= 0.2.0)
13
- def initialize(opts={})
12
+ def initialize(metric_name: 'grpc.request', **opts)
14
13
  super
15
- @metric_name = opts[:metric_name] || 'grpc.request'
16
14
 
15
+ @metric_name = metric_name
17
16
  Datadog::Notifications.subscribe 'process_action.grpc' do |reporter, event|
18
17
  record reporter, event
19
18
  end
@@ -34,6 +33,5 @@ module Datadog::Notifications::Plugins
34
33
  reporter.timing "#{@metric_name}.time", event.duration, tags: tags
35
34
  end
36
35
  end
37
-
38
36
  end
39
37
  end
@@ -1,5 +1,5 @@
1
1
  module Datadog
2
2
  class Notifications
3
- VERSION = '0.6.2'.freeze
3
+ VERSION = '0.6.7'.freeze
4
4
  end
5
5
  end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications::Config do
4
-
5
- it 'should be connect!' do
4
+ it 'is connect!' do
6
5
  subject.reporter = Mock::Reporter
7
6
  subject.hostname = 'test.host'
8
7
  subject.tags = ['custom:tag']
@@ -13,7 +12,7 @@ describe Datadog::Notifications::Config do
13
12
  end
14
13
 
15
14
  RSpec.shared_examples 'host tag is not picked up' do |hostname|
16
- it 'should not pick up the host tag' do
15
+ it 'does not pick up the host tag' do
17
16
  subject.reporter = Mock::Reporter
18
17
  subject.hostname = hostname
19
18
  subject.tags = ['custom:tag']
@@ -27,10 +26,9 @@ describe Datadog::Notifications::Config do
27
26
  include_examples 'host tag is not picked up', false
28
27
  include_examples 'host tag is not picked up', 'false'
29
28
 
30
- it 'should instantiate plugins on use' do
29
+ it 'instantiates plugins on use' do
31
30
  subject.use Datadog::Notifications::Plugins::ActionController
32
31
  expect(subject.plugins.size).to eq(1)
33
32
  expect(subject.plugins.first).to be_instance_of(Datadog::Notifications::Plugins::ActionController)
34
33
  end
35
-
36
34
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Datadog::Notifications::Plugins::ActiveJob do
4
+ it 'sanitizes tags' do
5
+ NoopJob.perform_now
6
+ expect(buffered).to eq [
7
+ 'activejob.perform:1|c|#custom:tag,env:test,host:test.host,job:noop,queue:test_queue',
8
+ 'activejob.perform.time:333|ms|#custom:tag,env:test,host:test.host,job:noop,queue:test_queue',
9
+ ]
10
+ end
11
+ end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications::Plugins::ActiveRecord do
4
-
5
- it 'should send an increment and timing event for each query' do
4
+ it 'sends an increment and timing event for each query' do
6
5
  Post.all.to_a
7
6
  expect(buffered).to eq [
8
7
  'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
@@ -10,12 +9,11 @@ describe Datadog::Notifications::Plugins::ActiveRecord do
10
9
  ]
11
10
  end
12
11
 
13
- it 'should support custom queries' do
12
+ it 'supports custom queries' do
14
13
  Post.find_by_sql('SELECT * FROM posts LIMIT 1').to_a
15
14
  expect(buffered).to eq [
16
15
  'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
17
16
  'activerecord.sql.time:333|ms|#custom:tag,env:test,host:test.host,query:post.load',
18
17
  ]
19
18
  end
20
-
21
19
  end
@@ -14,7 +14,6 @@ describe Datadog::Notifications::Plugins::Grape do
14
14
  end
15
15
 
16
16
  Class.new(Grape::API) do
17
-
18
17
  rescue_from unauthorized do |_e|
19
18
  error!({ message: 'unauthorized', error: '401 Unauthorized' }, 401)
20
19
  end
@@ -37,7 +36,7 @@ describe Datadog::Notifications::Plugins::Grape do
37
36
  end
38
37
  end
39
38
 
40
- it 'should send an increment and timing event for each request' do
39
+ it 'sends an increment and timing event for each request' do
41
40
  get '/echo/1/1234'
42
41
  expect(last_response.status).to eq(200)
43
42
  expect(last_response.body).to eq('1 1234')
@@ -48,7 +47,7 @@ describe Datadog::Notifications::Plugins::Grape do
48
47
  ])
49
48
  end
50
49
 
51
- it 'should support namespaces and versioning' do
50
+ it 'supports namespaces and versioning' do
52
51
  get '/api/v1/sub/versioned.txt'
53
52
  expect(last_response.status).to eq(200)
54
53
  expect(last_response.body).to eq('OK')
@@ -59,7 +58,7 @@ describe Datadog::Notifications::Plugins::Grape do
59
58
  ])
60
59
  end
61
60
 
62
- it 'should support deep nesting' do
61
+ it 'supports deep nesting' do
63
62
  get '/sub/secure/resource'
64
63
  expect(last_response.status).to eq(403)
65
64
  expect(last_response.body).to eq('forbidden')
@@ -70,7 +69,7 @@ describe Datadog::Notifications::Plugins::Grape do
70
69
  ])
71
70
  end
72
71
 
73
- it 'should handle rescued errors' do
72
+ it 'handles rescued errors' do
74
73
  get '/rescued'
75
74
  expect(last_response.status).to eq(401)
76
75
 
@@ -80,7 +79,7 @@ describe Datadog::Notifications::Plugins::Grape do
80
79
  ])
81
80
  end
82
81
 
83
- it 'should handle invalid method' do
82
+ it 'handles invalid method' do
84
83
  post '/rescued'
85
84
 
86
85
  expect(last_response.status).to eq(405)
@@ -90,11 +89,10 @@ describe Datadog::Notifications::Plugins::Grape do
90
89
  ])
91
90
  end
92
91
 
93
- it 'should not report paths on 404s' do
92
+ it 'does not report paths on 404s' do
94
93
  get '/sub/missing'
95
94
  expect(last_response.status).to eq(404)
96
95
 
97
96
  expect(buffered).to eq([])
98
97
  end
99
-
100
98
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications do
4
-
5
4
  subject { described_class.instance }
5
+
6
6
  after { ActiveSupport::Notifications.unsubscribe(subscription) }
7
7
 
8
8
  let!(:subscription) do
@@ -18,16 +18,15 @@ describe Datadog::Notifications do
18
18
  end
19
19
  end
20
20
 
21
- it 'should have a reporter' do
21
+ it 'has a reporter' do
22
22
  expect(subject.send(:reporter)).to be_instance_of(Mock::Reporter)
23
23
  end
24
24
 
25
- it 'should subscribe and report' do
25
+ it 'subscribes and report' do
26
26
  Mock::Instrumentable.new(method: 'GET').perform
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
-
33
32
  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,12 +19,20 @@ end
18
19
  class Post < ActiveRecord::Base
19
20
  end
20
21
 
22
+ ### Active-job test preparation
23
+
24
+ ActiveJob::Base.queue_adapter = :inline
25
+ class NoopJob < ActiveJob::Base
26
+ self.queue_name = 'test:queue'
27
+ def perform; end
28
+ end
29
+
21
30
  ### Mocks
22
31
 
23
32
  module Mock
24
33
  class Reporter < Datadog::Notifications::Reporter
25
- def timing(stat, _millis, opts={})
26
- super(stat, 333, opts)
34
+ def timing(stat, _millis, **opts)
35
+ super(stat, 333, **opts)
27
36
  end
28
37
 
29
38
  def send_stat(message)
@@ -36,7 +45,7 @@ module Mock
36
45
  end
37
46
 
38
47
  class Instrumentable
39
- def initialize(opts={})
48
+ def initialize(**opts)
40
49
  @opts = opts
41
50
  end
42
51
 
@@ -70,14 +79,15 @@ Datadog::Notifications.configure do |c|
70
79
  c.tags = ['custom:tag']
71
80
 
72
81
  c.use Datadog::Notifications::Plugins::ActiveRecord
82
+ c.use Datadog::Notifications::Plugins::ActiveJob
73
83
  c.use Datadog::Notifications::Plugins::Grape,
74
- tags: ['more:tags'],
75
- metric_name: 'api.request',
76
- exception_handler: lambda {|e|
77
- if e.message.include?('unauthorized')
78
- 401
79
- else
80
- Datadog::Notifications::Plugins::Grape.exception_status(e)
81
- end
82
- }
84
+ tags: ['more:tags'],
85
+ metric_name: 'api.request',
86
+ exception_handler: lambda {|e|
87
+ if e.message.include?('unauthorized')
88
+ 401
89
+ else
90
+ Datadog::Notifications::Plugins::Grape.exception_status(e)
91
+ end
92
+ }
83
93
  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.6.2
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: '4.8'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '5.0'
@@ -40,10 +40,24 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '4.2'
43
+ version: '4.8'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: activejob
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: activerecord
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -129,7 +143,7 @@ dependencies:
129
143
  - !ruby/object:Gem::Version
130
144
  version: '0'
131
145
  - !ruby/object:Gem::Dependency
132
- name: rubocop
146
+ name: rubocop-bsm
133
147
  requirement: !ruby/object:Gem::Requirement
134
148
  requirements:
135
149
  - - ">="
@@ -164,10 +178,9 @@ extensions: []
164
178
  extra_rdoc_files: []
165
179
  files:
166
180
  - ".editorconfig"
181
+ - ".github/workflows/ruby.yml"
167
182
  - ".gitignore"
168
- - ".rake_tasks~"
169
183
  - ".rubocop.yml"
170
- - ".travis.yml"
171
184
  - Gemfile
172
185
  - Gemfile.lock
173
186
  - MIT-LICENCE
@@ -187,6 +200,7 @@ files:
187
200
  - lib/datadog/notifications/reporter.rb
188
201
  - lib/datadog/notifications/version.rb
189
202
  - spec/datadog/notifications/config_spec.rb
203
+ - spec/datadog/notifications/plugins/active_job_spec.rb
190
204
  - spec/datadog/notifications/plugins/active_record_spec.rb
191
205
  - spec/datadog/notifications/plugins/grape_spec.rb
192
206
  - spec/datadog/notifications_spec.rb
@@ -202,19 +216,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
216
  requirements:
203
217
  - - ">="
204
218
  - !ruby/object:Gem::Version
205
- version: '2.5'
219
+ version: '2.6'
206
220
  required_rubygems_version: !ruby/object:Gem::Requirement
207
221
  requirements:
208
222
  - - ">="
209
223
  - !ruby/object:Gem::Version
210
224
  version: '0'
211
225
  requirements: []
212
- rubygems_version: 3.0.6
226
+ rubygems_version: 3.2.15
213
227
  signing_key:
214
228
  specification_version: 4
215
229
  summary: Generic ActiveSupport::Notifications Datadog handler
216
230
  test_files:
217
231
  - spec/datadog/notifications/config_spec.rb
232
+ - spec/datadog/notifications/plugins/active_job_spec.rb
218
233
  - spec/datadog/notifications/plugins/active_record_spec.rb
219
234
  - spec/datadog/notifications/plugins/grape_spec.rb
220
235
  - spec/datadog/notifications_spec.rb
data/.rake_tasks~ DELETED
@@ -1,9 +0,0 @@
1
- build
2
- clean
3
- clobber
4
- install
5
- install:local
6
- release[remote]
7
- rubocop
8
- rubocop:auto_correct
9
- spec
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- cache: bundler
2
- language: ruby
3
- before_install:
4
- - gem install bundler
5
- rvm:
6
- - 2.7
7
- - 2.6
8
- - 2.5