dogstatsd-instrumentation 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: b95073d9c8cc7193cc51917e5bfb94169758cdc2
4
- data.tar.gz: 5532096dec46a67a85e61dd456fcbd50c62a8118
3
+ metadata.gz: 7db0d56432676e3ada7e935438162daaee78f837
4
+ data.tar.gz: 77778a0c9f8048e7333e1d0af61aa1f8a925052d
5
5
  SHA512:
6
- metadata.gz: cdd0ff0dab6c84f8f5e360d1e042a209598bdc3ce04114768359447764b112f195b042a52b7f39d8dbe7f44f55f17ee997656a0ce6e36cdb1586bcb7512f934b
7
- data.tar.gz: 214210fa8d42de1872b3bc9e77fdbbb2f6ea86c1feafeb8a231778cff4ed347ddb5802937d2ecc9ac72a629a100cfb39ebc7e584723e311249cd30507766045f
6
+ metadata.gz: e17e56309a7a2138dfc3607aae45718bfdb80672b2cfc60b7d7f21a8acd5f0dbaf75bd5145211d9f89ba85f9ae47526a96f8aac9d19248c83ed718936467031e
7
+ data.tar.gz: 10b077d6d128fae8976f722c6018cf7fdb1b680f14300cb79c73806dbfc57dcdc64f8afbb043ccb4606665912bff06c8f0690ee39a74331e29d60bc71f85c2a8
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal true
2
+
3
+ require 'active_support'
4
+ require 'gem_config'
5
+ require 'datadog/statsd'
6
+ require_relative 'dogstatsd/instrumentation/client_provider'
7
+
8
+ module DogStatsd
9
+ PUBLIC_METHODS = %w(increment decrement count gauge histogram timing time set service_check format_service_check event batch format_event).freeze
10
+
11
+ class << self
12
+ extend Forwardable
13
+
14
+ def_delegators :statsd, *PUBLIC_METHODS
15
+
16
+ def statsd
17
+ Thread.current[:_dogstatsd_instrumentation_client] ||= Instrumentation::ClientProvider.new
18
+ end
19
+ end
20
+ end
@@ -2,3 +2,4 @@
2
2
 
3
3
  require "dogstatsd/instrumentation/identity"
4
4
  require "dogstatsd/instrumentation/request"
5
+ require "dogstatsd"
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'gem_config'
5
+ require 'datadog/statsd'
6
+
7
+ module DogStatsd
8
+ module Instrumentation
9
+ module ClientProvider
10
+ include GemConfig::Base
11
+
12
+ with_configuration do
13
+ has :enabled, classes: [TrueClass, FalseClass], default: true
14
+ has :tags, classes: Array, default: []
15
+ has :tags_h, classes: Hash, default: {}
16
+ has :namespace, classes: String
17
+
18
+ has :host, classes: String, default: Datadog::Statsd::DEFAULT_HOST
19
+ has :port, classes: Integer, default: Datadog::Statsd::DEFAULT_PORT
20
+ has :opts, classes: Hash, default: {}
21
+ has :max_buffer_size, classes: Integer, default: 50
22
+ end
23
+
24
+ def self.new
25
+ client = Datadog::Statsd.new(
26
+ configuration.host,
27
+ configuration.port,
28
+ configuration.opts.merge(namespace: configuration.namespace, tags: configuration.tags + tagify(configuration.tags_h)),
29
+ configuration.max_buffer_size
30
+ )
31
+
32
+ def client.send_stats(stat, delta, type, opts={})
33
+ super if ClientProvider.configuration.enabled
34
+ end
35
+
36
+ client
37
+ end
38
+
39
+ def self.tagify(hash)
40
+ hash.select { |_, value| value.present? }.map { |key, value| "#{key}:#{value}" }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -13,7 +13,7 @@ module DogStatsd
13
13
  end
14
14
 
15
15
  def self.version
16
- "0.1.3"
16
+ "0.1.4"
17
17
  end
18
18
 
19
19
  def self.version_label
@@ -3,6 +3,7 @@
3
3
  require 'active_support'
4
4
  require 'gem_config'
5
5
  require 'datadog/statsd'
6
+ require_relative 'client_provider'
6
7
 
7
8
  module DogStatsd
8
9
  module Instrumentation
@@ -10,34 +11,22 @@ module DogStatsd
10
11
  include GemConfig::Base
11
12
 
12
13
  with_configuration do
13
- has :enabled, classes: [TrueClass, FalseClass], default: true
14
- has :base_tags, classes: Hash, default: {}
15
-
16
- has :host, classes: String, default: Datadog::Statsd::DEFAULT_HOST
17
- has :port, classes: Integer, default: Datadog::Statsd::DEFAULT_PORT
18
- has :opts, classes: Hash, default: {}
19
- has :max_buffer_size, classes: Integer, default: 50
14
+ has :statsd, classes: Object
20
15
  end
21
16
 
22
17
  # From GemConfig::Base
23
18
  def self.configure
24
19
  super
25
- @@subscriber = @@subscriber.unsubscribe if @@subscriber
26
- @@subscriber = Subscriber.new(configuration) if configuration.enabled
20
+ @@subscriber.unsubscribe if @@subscriber
21
+
22
+ @@subscriber = Subscriber.new(configuration.statsd || ClientProvider.new)
27
23
  end
28
24
 
29
25
  @@subscriber = nil
30
26
 
31
27
  class Subscriber
32
- def initialize(configuration)
33
- @base_tags = configuration.base_tags
34
-
35
- @statsd = Datadog::Statsd.new(
36
- configuration.host,
37
- configuration.port,
38
- configuration.opts,
39
- configuration.max_buffer_size
40
- )
28
+ def initialize(statsd)
29
+ @statsd = statsd
41
30
 
42
31
  @subscriber = ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args|
43
32
  event = ActiveSupport::Notifications::Event.new(*args)
@@ -58,7 +47,7 @@ module DogStatsd
58
47
  end
59
48
 
60
49
  def instrument(stat:, value:, tags:)
61
- @statsd.histogram stat, value, tags: Subscriber.tagify(@base_tags.merge(tags))
50
+ @statsd.histogram stat, value, tags: Subscriber.tagify(tags)
62
51
  end
63
52
 
64
53
  def self.tagify(hash)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogstatsd-instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dogstatsd-ruby
@@ -176,7 +176,9 @@ extra_rdoc_files:
176
176
  files:
177
177
  - LICENSE.md
178
178
  - README.md
179
+ - lib/dogstatsd.rb
179
180
  - lib/dogstatsd/instrumentation.rb
181
+ - lib/dogstatsd/instrumentation/client_provider.rb
180
182
  - lib/dogstatsd/instrumentation/identity.rb
181
183
  - lib/dogstatsd/instrumentation/request.rb
182
184
  - lib/tasks/reek.rake