datadog-notifications 0.5.3 → 0.6.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fad10b73b565812d444474c765e3f8e1054776e7f35205ca0b3e1d81e79413ad
4
- data.tar.gz: db63472562524db432806070e6c6c64f32fbf848eed7fd775761fb7fe0189cbe
3
+ metadata.gz: c2373f5f441b07227d05a8b6835726b0ce9df3eaf7b3329019814ad2b389dc0f
4
+ data.tar.gz: 52973ed82c2720bc02da8c6337de4efa242ac91f5021dad4913cef1842203b45
5
5
  SHA512:
6
- metadata.gz: 7f872dfd2ea075f5e2562f81ff149a7e5434d603cbda8013d1faf323fa33800543fb48c5ef5434fe40f51b4bf3ef6baa71437dd73947dcf0131a3acd96da0000
7
- data.tar.gz: b650ab31ce04c9383e88b4eda57cfd7d3d907ebd5b62a0e44ae8258b820131fbf721bbc3fd10927299bb328786e0f6580e42c17ff80d9dbb8b0bb356e70bbac5
6
+ metadata.gz: c0603c9150fbd6ec40ed62c0b4ea1261e81b869c803a34531bdca51f19df41379fb908d3c2ddfa3661e458e3ae34f9ba01305ce4e4d9dba3cfab972334a29284
7
+ data.tar.gz: 8c5902469f500ffe2dbe7c245fdbb530d97e7b4f3f50123aa91d0e80c9ebb56c68e93d91cee25b2cfdaad5bdf94a8fa2057e5dac6e8a3339ca207f89d5a919c6
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ .rubocop-*
@@ -0,0 +1,9 @@
1
+ build
2
+ clean
3
+ clobber
4
+ install
5
+ install:local
6
+ release[remote]
7
+ rubocop
8
+ rubocop:auto_correct
9
+ spec
@@ -1,70 +1,10 @@
1
+ inherit_from:
2
+ - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: "2.5"
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
@@ -1,7 +1,8 @@
1
- sudo: false
1
+ cache: bundler
2
2
  language: ruby
3
+ before_install:
4
+ - gem install bundler
3
5
  rvm:
4
- - 2.5.x
5
- - 2.4.x
6
- - 2.3.x
7
- - 2.2.x
6
+ - 2.7
7
+ - 2.6
8
+ - 2.5
@@ -1,97 +1,107 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datadog-notifications (0.5.3)
4
+ datadog-notifications (0.6.3)
5
5
  activesupport
6
- dogstatsd-ruby (~> 3.1)
6
+ dogstatsd-ruby (>= 4.2, < 5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.2.1)
12
- activesupport (= 5.2.1)
13
- activerecord (5.2.1)
14
- activemodel (= 5.2.1)
15
- activesupport (= 5.2.1)
16
- arel (>= 9.0)
17
- activesupport (5.2.1)
11
+ activemodel (6.0.3.1)
12
+ activesupport (= 6.0.3.1)
13
+ activerecord (6.0.3.1)
14
+ activemodel (= 6.0.3.1)
15
+ activesupport (= 6.0.3.1)
16
+ activesupport (6.0.3.1)
18
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
18
  i18n (>= 0.7, < 2)
20
19
  minitest (~> 5.1)
21
20
  tzinfo (~> 1.1)
22
- arel (9.0.0)
21
+ zeitwerk (~> 2.2, >= 2.2.2)
23
22
  ast (2.4.0)
24
- axiom-types (0.1.1)
25
- descendants_tracker (~> 0.0.4)
26
- ice_nine (~> 0.11.0)
27
- thread_safe (~> 0.3, >= 0.3.1)
28
- builder (3.2.3)
29
- coercible (1.0.0)
30
- descendants_tracker (~> 0.0.1)
31
- concurrent-ruby (1.0.5)
32
- descendants_tracker (0.0.4)
33
- thread_safe (~> 0.3, >= 0.3.1)
23
+ builder (3.2.4)
24
+ concurrent-ruby (1.1.6)
34
25
  diff-lcs (1.3)
35
- dogstatsd-ruby (3.3.0)
36
- equalizer (0.0.11)
37
- grape (1.1.0)
26
+ dogstatsd-ruby (4.8.1)
27
+ dry-configurable (0.11.5)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-core (~> 0.4, >= 0.4.7)
30
+ dry-equalizer (~> 0.2)
31
+ dry-container (0.7.2)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-configurable (~> 0.1, >= 0.1.3)
34
+ dry-core (0.4.9)
35
+ concurrent-ruby (~> 1.0)
36
+ dry-equalizer (0.3.0)
37
+ dry-inflector (0.2.0)
38
+ dry-logic (1.0.6)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-core (~> 0.2)
41
+ dry-equalizer (~> 0.2)
42
+ dry-types (1.4.0)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-container (~> 0.3)
45
+ dry-core (~> 0.4, >= 0.4.4)
46
+ dry-equalizer (~> 0.3)
47
+ dry-inflector (~> 0.1, >= 0.1.2)
48
+ dry-logic (~> 1.0, >= 1.0.2)
49
+ grape (1.3.3)
38
50
  activesupport
39
51
  builder
52
+ dry-types (>= 1.1)
40
53
  mustermann-grape (~> 1.0.0)
41
54
  rack (>= 1.3.0)
42
55
  rack-accept
43
- virtus (>= 1.0.0)
44
- i18n (1.1.0)
56
+ i18n (1.8.2)
45
57
  concurrent-ruby (~> 1.0)
46
- ice_nine (0.11.2)
47
- jaro_winkler (1.5.1)
48
- minitest (5.11.3)
49
- mustermann (1.0.3)
50
- mustermann-grape (1.0.0)
51
- mustermann (~> 1.0.0)
52
- parallel (1.12.1)
53
- parser (2.5.1.2)
58
+ minitest (5.14.1)
59
+ mustermann (1.1.1)
60
+ ruby2_keywords (~> 0.0.1)
61
+ mustermann-grape (1.0.1)
62
+ mustermann (>= 1.0.0)
63
+ parallel (1.19.1)
64
+ parser (2.7.1.3)
54
65
  ast (~> 2.4.0)
55
- powerpack (0.1.2)
56
- rack (2.0.5)
66
+ rack (2.2.2)
57
67
  rack-accept (0.4.5)
58
68
  rack (>= 0.4)
59
69
  rack-test (1.1.0)
60
70
  rack (>= 1.0, < 3)
61
71
  rainbow (3.0.0)
62
- rake (12.3.1)
63
- rspec (3.8.0)
64
- rspec-core (~> 3.8.0)
65
- rspec-expectations (~> 3.8.0)
66
- rspec-mocks (~> 3.8.0)
67
- rspec-core (3.8.0)
68
- rspec-support (~> 3.8.0)
69
- rspec-expectations (3.8.1)
72
+ rake (13.0.1)
73
+ rexml (3.2.4)
74
+ rspec (3.9.0)
75
+ rspec-core (~> 3.9.0)
76
+ rspec-expectations (~> 3.9.0)
77
+ rspec-mocks (~> 3.9.0)
78
+ rspec-core (3.9.2)
79
+ rspec-support (~> 3.9.3)
80
+ rspec-expectations (3.9.2)
70
81
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.8.0)
72
- rspec-mocks (3.8.0)
82
+ rspec-support (~> 3.9.0)
83
+ rspec-mocks (3.9.1)
73
84
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.8.0)
75
- rspec-support (3.8.0)
76
- rubocop (0.59.0)
77
- jaro_winkler (~> 1.5.1)
85
+ rspec-support (~> 3.9.0)
86
+ rspec-support (3.9.3)
87
+ rubocop (0.84.0)
78
88
  parallel (~> 1.10)
79
- parser (>= 2.5, != 2.5.1.1)
80
- powerpack (~> 0.1)
89
+ parser (>= 2.7.0.1)
81
90
  rainbow (>= 2.2.2, < 4.0)
91
+ rexml
92
+ rubocop-ast (>= 0.0.3)
82
93
  ruby-progressbar (~> 1.7)
83
- unicode-display_width (~> 1.0, >= 1.0.1)
84
- ruby-progressbar (1.10.0)
85
- sqlite3 (1.3.13)
94
+ unicode-display_width (>= 1.4.0, < 2.0)
95
+ rubocop-ast (0.0.3)
96
+ parser (>= 2.7.0.1)
97
+ ruby-progressbar (1.10.1)
98
+ ruby2_keywords (0.0.2)
99
+ sqlite3 (1.4.2)
86
100
  thread_safe (0.3.6)
87
- tzinfo (1.2.5)
101
+ tzinfo (1.2.7)
88
102
  thread_safe (~> 0.1)
89
- unicode-display_width (1.4.0)
90
- virtus (1.0.5)
91
- axiom-types (~> 0.1)
92
- coercible (~> 1.0)
93
- descendants_tracker (~> 0.0, >= 0.0.3)
94
- equalizer (~> 0.0, >= 0.0.9)
103
+ unicode-display_width (1.7.0)
104
+ zeitwerk (2.3.0)
95
105
 
96
106
  PLATFORMS
97
107
  ruby
@@ -100,7 +110,7 @@ DEPENDENCIES
100
110
  activerecord
101
111
  bundler
102
112
  datadog-notifications!
103
- grape (>= 0.16)
113
+ grape (>= 1.0.2)
104
114
  rack-test
105
115
  rake
106
116
  rspec
@@ -108,4 +118,4 @@ DEPENDENCIES
108
118
  sqlite3
109
119
 
110
120
  BUNDLED WITH
111
- 1.16.4
121
+ 2.1.2
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
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 "Run `bundle install` to install missing gems"
7
+ warn 'Run `bundle install` to install missing gems'
8
8
  exit e.status_code
9
9
  end
10
10
 
@@ -3,27 +3,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'datadog/notifications/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "datadog-notifications"
6
+ s.name = 'datadog-notifications'
7
7
  s.version = Datadog::Notifications::VERSION.dup
8
- s.authors = ["Dimitrij Denissenko"]
9
- s.email = ["dimitrij@blacksquaremedia.com"]
8
+ s.authors = ['Dimitrij Denissenko']
9
+ s.email = ['dimitrij@blacksquaremedia.com']
10
10
  s.description = 'Datadog instrumentation for ActiveSupport::Notifications'
11
11
  s.summary = 'Generic ActiveSupport::Notifications Datadog handler'
12
- s.homepage = "https://github.com/bsm/datadog-notifications"
12
+ s.homepage = 'https://github.com/bsm/datadog-notifications'
13
13
 
14
14
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
15
15
  s.test_files = s.files.grep(%r{^(spec)/})
16
- s.require_paths = ["lib"]
16
+ s.require_paths = ['lib']
17
+ s.required_ruby_version = '>= 2.5'
17
18
 
18
- s.add_runtime_dependency('activesupport')
19
- s.add_runtime_dependency('dogstatsd-ruby', "~> 3.1")
19
+ s.add_runtime_dependency 'activesupport'
20
+ s.add_runtime_dependency 'dogstatsd-ruby', '>= 4.2', '< 5.0'
20
21
 
21
- s.add_development_dependency('activerecord')
22
- s.add_development_dependency('bundler')
23
- s.add_development_dependency('grape', ">= 0.16")
24
- s.add_development_dependency('rack-test')
25
- s.add_development_dependency('rake')
26
- s.add_development_dependency('rspec')
27
- s.add_development_dependency('rubocop')
28
- s.add_development_dependency('sqlite3')
22
+ s.add_development_dependency 'activerecord'
23
+ s.add_development_dependency 'bundler'
24
+ s.add_development_dependency 'grape', '>= 1.0.2'
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
@@ -1 +1 @@
1
- require "datadog/notifications"
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.call instance.config if 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']
9
+ @statsd_port = ENV['STATSD_PORT']
10
10
  @socket_path = ENV['SOCKET_PATH']
11
11
  @reporter = Datadog::Notifications::Reporter
12
12
  @tags = []
@@ -14,8 +14,8 @@ 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
@@ -29,7 +29,6 @@ module Datadog
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
@@ -28,6 +27,5 @@ module Datadog::Notifications::Plugins
28
27
  reporter.timing "#{metric_name}.time", event.duration, tags: tags
29
28
  end
30
29
  end
31
-
32
30
  end
33
31
  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
@@ -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 == "SQL") && !@include_generic
30
- return if name == "SCHEMA" && !@include_schema
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(".") if name
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
 
@@ -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,6 +1,5 @@
1
1
  module Datadog::Notifications::Plugins
2
2
  class Grape < Base
3
-
4
3
  def self.exception_status(err)
5
4
  err.respond_to?(:status) ? err.status : 500
6
5
  end
@@ -12,10 +11,11 @@ module Datadog::Notifications::Plugins
12
11
  # *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
13
12
  # *<tt>:exception_handler</tt> - a custom exception handler proc which accepts an exception object and returns a status
14
13
  # *<tt>:tags</tt> - additional tags
15
- def initialize(opts={})
14
+ def initialize(metric_name: 'grape.request', exception_handler:, **opts)
16
15
  super
17
- @metric_name = opts[:metric_name] || "grape.request"
18
- @exception_handler = opts[:exception_handler] || ->(e) { self.class.exception_status(e) }
16
+
17
+ @metric_name = metric_name
18
+ @exception_handler = exception_handler || ->(e) { self.class.exception_status(e) }
19
19
 
20
20
  Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
21
21
  record reporter, event
@@ -55,10 +55,9 @@ module Datadog::Notifications::Plugins
55
55
 
56
56
  path = endpoint.route.path.dup
57
57
  path.sub!(/\(\.\:format\)$/, '')
58
- path.sub!(":version/", "") if endpoint.version
58
+ path.sub!(':version/', '') if endpoint.version
59
59
  path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
60
60
  path
61
61
  end
62
-
63
62
  end
64
63
  end
@@ -1,19 +1,18 @@
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'
7
6
  # *<tt>:tags</tt> - additional tags
8
7
  #
9
8
  # It expects ActiveSupport instrumented notifications named 'process_action.grpc'.
10
- # Each such notification should have an :action key with gRPC action (method) name.
9
+ # Notification payload should have :service (service name, string) and :action (service action/method name, string) keys.
11
10
  #
12
- # Compatible instrumentation is implemented in grpcx gem: https://github.com/bsm/grpcx
13
- def initialize(opts={})
11
+ # Compatible instrumentation is implemented in grpcx gem: https://github.com/bsm/grpcx (>= 0.2.0)
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
@@ -23,16 +22,16 @@ module Datadog::Notifications::Plugins
23
22
 
24
23
  def record(reporter, event)
25
24
  payload = event.payload
25
+ service = payload[:service]
26
26
  action = payload[:action]
27
27
  status = payload[:exception] ? 'error' : 'ok'
28
28
 
29
- tags = self.tags + %W[action:#{action} status:#{status}]
29
+ tags = self.tags + %W[service:#{service} action:#{action} status:#{status}]
30
30
 
31
31
  reporter.batch do
32
32
  reporter.increment @metric_name, tags: tags
33
33
  reporter.timing "#{@metric_name}.time", event.duration, tags: tags
34
34
  end
35
35
  end
36
-
37
36
  end
38
37
  end
@@ -1,5 +1,5 @@
1
1
  module Datadog
2
2
  class Notifications
3
- VERSION = '0.5.3'.freeze
3
+ VERSION = '0.6.3'.freeze
4
4
  end
5
5
  end
@@ -1,26 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications::Config do
4
-
5
4
  it 'should be connect!' do
6
5
  subject.reporter = Mock::Reporter
7
- subject.hostname = "test.host"
8
- subject.tags = ["custom:tag"]
6
+ subject.hostname = 'test.host'
7
+ subject.tags = ['custom:tag']
9
8
 
10
9
  client = subject.send(:connect!)
11
10
  expect(client).to be_instance_of(Mock::Reporter)
12
- expect(subject.tags).to eq(["custom:tag", "env:test", "host:test.host"])
11
+ expect(subject.tags).to eq(['custom:tag', 'env:test', 'host:test.host'])
13
12
  end
14
13
 
15
14
  RSpec.shared_examples 'host tag is not picked up' do |hostname|
16
15
  it 'should not pick up the host tag' do
17
16
  subject.reporter = Mock::Reporter
18
17
  subject.hostname = hostname
19
- subject.tags = ["custom:tag"]
18
+ subject.tags = ['custom:tag']
20
19
 
21
20
  client = subject.send(:connect!)
22
21
  expect(client).to be_instance_of(Mock::Reporter)
23
- expect(subject.tags).to eq(["custom:tag", "env:test"])
22
+ expect(subject.tags).to eq(['custom:tag', 'env:test'])
24
23
  end
25
24
  end
26
25
 
@@ -32,5 +31,4 @@ describe Datadog::Notifications::Config do
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
@@ -1,21 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications::Plugins::ActiveRecord do
4
-
5
4
  it 'should send an increment and timing event for each query' do
6
5
  Post.all.to_a
7
6
  expect(buffered).to eq [
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",
7
+ 'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
8
+ 'activerecord.sql.time:333|ms|#custom:tag,env:test,host:test.host,query:post.load',
10
9
  ]
11
10
  end
12
11
 
13
12
  it 'should support custom queries' do
14
- Post.find_by_sql("SELECT * FROM posts LIMIT 1").to_a
13
+ Post.find_by_sql('SELECT * FROM posts LIMIT 1').to_a
15
14
  expect(buffered).to eq [
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",
15
+ 'activerecord.sql:1|c|#custom:tag,env:test,host:test.host,query:post.load',
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
@@ -10,13 +10,12 @@ describe Datadog::Notifications::Plugins::Grape do
10
10
  version 'v1'
11
11
  prefix 'api'
12
12
 
13
- get('versioned') { "OK" }
13
+ get('versioned') { 'OK' }
14
14
  end
15
15
 
16
16
  Class.new(Grape::API) do
17
-
18
17
  rescue_from unauthorized do |_e|
19
- error!({ message: "unauthorized", error: '401 Unauthorized' }, 401)
18
+ error!({ message: 'unauthorized', error: '401 Unauthorized' }, 401)
20
19
  end
21
20
 
22
21
  get 'echo/:key1/:key2' do
@@ -24,14 +23,14 @@ describe Datadog::Notifications::Plugins::Grape do
24
23
  end
25
24
 
26
25
  get '/rescued' do
27
- raise unauthorized, "unauthorized"
26
+ raise unauthorized, 'unauthorized'
28
27
  end
29
28
 
30
29
  namespace :sub do
31
30
  mount sub_api
32
31
 
33
32
  namespace :secure do
34
- get("/resource") { error!("forbidden", 403) }
33
+ get('/resource') { error!('forbidden', 403) }
35
34
  end
36
35
  end
37
36
  end
@@ -43,9 +42,9 @@ describe Datadog::Notifications::Plugins::Grape do
43
42
  expect(last_response.body).to eq('1 1234')
44
43
 
45
44
  expect(buffered).to eq([
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
- ],)
45
+ 'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
46
+ 'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/echo/KEY1/KEY2',
47
+ ])
49
48
  end
50
49
 
51
50
  it 'should support namespaces and versioning' do
@@ -54,9 +53,9 @@ describe Datadog::Notifications::Plugins::Grape do
54
53
  expect(last_response.body).to eq('OK')
55
54
 
56
55
  expect(buffered).to eq([
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
- ],)
56
+ 'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
57
+ 'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:200,path:/api/sub/versioned,version:v1',
58
+ ])
60
59
  end
61
60
 
62
61
  it 'should support deep nesting' do
@@ -65,9 +64,9 @@ describe Datadog::Notifications::Plugins::Grape do
65
64
  expect(last_response.body).to eq('forbidden')
66
65
 
67
66
  expect(buffered).to eq([
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
- ],)
67
+ 'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
68
+ 'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:403,path:/sub/secure/resource',
69
+ ])
71
70
  end
72
71
 
73
72
  it 'should handle rescued errors' do
@@ -75,9 +74,9 @@ describe Datadog::Notifications::Plugins::Grape do
75
74
  expect(last_response.status).to eq(401)
76
75
 
77
76
  expect(buffered).to eq([
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
- ],)
77
+ 'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
78
+ 'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:GET,status:401,path:/rescued',
79
+ ])
81
80
  end
82
81
 
83
82
  it 'should handle invalid method' do
@@ -85,9 +84,9 @@ describe Datadog::Notifications::Plugins::Grape do
85
84
 
86
85
  expect(last_response.status).to eq(405)
87
86
  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
- ],)
87
+ 'api.request:1|c|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
88
+ 'api.request.time:333|ms|#custom:tag,env:test,host:test.host,more:tags,method:POST,status:405,path:/rescued',
89
+ ])
91
90
  end
92
91
 
93
92
  it 'should not report paths on 404s' do
@@ -96,5 +95,4 @@ describe Datadog::Notifications::Plugins::Grape do
96
95
 
97
96
  expect(buffered).to eq([])
98
97
  end
99
-
100
98
  end
@@ -1,19 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Datadog::Notifications do
4
-
5
4
  subject { described_class.instance }
6
5
  after { ActiveSupport::Notifications.unsubscribe(subscription) }
7
6
 
8
7
  let!(:subscription) do
9
- subject.subscribe("mock.perform") do |reporter, event|
8
+ subject.subscribe('mock.perform') do |reporter, event|
10
9
  status = event.payload[:status]
11
10
  method = event.payload[:method]
12
11
  tags = ["status:#{status}", "method:#{method}"]
13
12
 
14
13
  reporter.batch do
15
- reporter.increment "web.render", tags: tags
16
- reporter.timing "web.render.time", event.duration, tags: tags
14
+ reporter.increment 'web.render', tags: tags
15
+ reporter.timing 'web.render.time', event.duration, tags: tags
17
16
  end
18
17
  end
19
18
  end
@@ -25,9 +24,8 @@ describe Datadog::Notifications do
25
24
  it 'should subscribe and report' do
26
25
  Mock::Instrumentable.new(method: 'GET').perform
27
26
  expect(buffered).to eq([
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
- ],)
27
+ 'web.render:1|c|#custom:tag,env:test,host:test.host,status:200,method:GET',
28
+ 'web.render.time:333|ms|#custom:tag,env:test,host:test.host,status:200,method:GET',
29
+ ])
31
30
  end
32
-
33
31
  end
@@ -10,7 +10,7 @@ require 'sqlite3'
10
10
 
11
11
  ### Active-record test preparation
12
12
 
13
- ActiveRecord::Base.configurations["test"] = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
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
@@ -22,22 +22,27 @@ end
22
22
 
23
23
  module Mock
24
24
  class Reporter < Datadog::Notifications::Reporter
25
- def timing(stat, _ms, opts={})
26
- super(stat, 333, opts)
25
+ def timing(stat, _millis, **opts)
26
+ super(stat, 333, **opts)
27
27
  end
28
28
 
29
- def flush_buffer; end
30
- @should_batch = true
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
34
- def initialize(opts={})
39
+ def initialize(**opts)
35
40
  @opts = opts
36
41
  end
37
42
 
38
43
  def perform
39
- ActiveSupport::Notifications.instrument("mock.start", @opts)
40
- ActiveSupport::Notifications.instrument("mock.perform", @opts) do |payload|
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).buffer
57
+ Datadog::Notifications.instance.send(:reporter).messages
53
58
  end
54
59
  end
55
60
 
@@ -60,19 +65,19 @@ RSpec.configure do |c|
60
65
  end
61
66
 
62
67
  Datadog::Notifications.configure do |c|
63
- c.hostname = "test.host"
68
+ c.hostname = 'test.host'
64
69
  c.reporter = Mock::Reporter
65
- c.tags = ["custom:tag"]
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: ["more:tags"],
70
- metric_name: "api.request",
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
- }
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
+ }
78
83
  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.3
4
+ version: 0.6.3
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-09-10 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: dogstatsd-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ - - "<"
32
35
  - !ruby/object:Gem::Version
33
- version: '3.1'
36
+ version: '5.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
- version: '3.1'
43
+ version: '4.2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: activerecord
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +78,14 @@ dependencies:
72
78
  requirements:
73
79
  - - ">="
74
80
  - !ruby/object:Gem::Version
75
- version: '0.16'
81
+ version: 1.0.2
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - ">="
81
87
  - !ruby/object:Gem::Version
82
- version: '0.16'
88
+ version: 1.0.2
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: rack-test
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +165,7 @@ extra_rdoc_files: []
159
165
  files:
160
166
  - ".editorconfig"
161
167
  - ".gitignore"
168
+ - ".rake_tasks~"
162
169
  - ".rubocop.yml"
163
170
  - ".travis.yml"
164
171
  - Gemfile
@@ -195,15 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
202
  requirements:
196
203
  - - ">="
197
204
  - !ruby/object:Gem::Version
198
- version: '0'
205
+ version: '2.5'
199
206
  required_rubygems_version: !ruby/object:Gem::Requirement
200
207
  requirements:
201
208
  - - ">="
202
209
  - !ruby/object:Gem::Version
203
210
  version: '0'
204
211
  requirements: []
205
- rubyforge_project:
206
- rubygems_version: 2.7.6
212
+ rubygems_version: 3.1.2
207
213
  signing_key:
208
214
  specification_version: 4
209
215
  summary: Generic ActiveSupport::Notifications Datadog handler