yabeda-datadog 0.3.0.rc1 → 0.3.0.rc2

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: a2600b842315a1b8dfde3a722c1c6b75b0c88a66146a439d3d2d59e48553bbaa
4
- data.tar.gz: df24c470280a87e6fefdc68d90296a33fc7ce1bdcae900e530cb59106b099ab9
3
+ metadata.gz: fb61ee60dd8cb6880dec64261548efbccadfc94b3db18d399e96effd6b4ed67a
4
+ data.tar.gz: e5261178b107deae7322aa0213364ed3fdc1c0e90a35569b0dbf996ebedc902b
5
5
  SHA512:
6
- metadata.gz: edec9182d5535f62cbd2e38efd3a1f5b2ab11f33f76616d0a8706c8ff79a109cd00e6933a19a20737686891f5c6ea919e253657017c5c1fac05d54bd30dd98d7
7
- data.tar.gz: 67ecae6205e8f9286a563caeb98813359d7e3888d15b02b0ff23711835f429cddbf18096395d9e97d37728d8716de009616ba2f8bf4f16ac968b6d006b632482
6
+ metadata.gz: aca81cd6e6bd2cadb2d69f1157e78e8b47637620ccddf70326310314248844cccd9208f369023a4a6753e4ca1e72a3d655efcc485dbc2b3d6d36cd1d025f3da5
7
+ data.tar.gz: 65efeb747cd54eeb009491e26d9f3ae9fa3f77f880afc36c672af679137c9197fd9663fe795451ec1869cfa3ba12828c730e7bc850cb42e1438cd9c8fd53578f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yabeda-datadog (0.3.0.rc1)
4
+ yabeda-datadog (0.3.0.rc2)
5
5
  anyway_config (~> 1.0)
6
6
  dogapi
7
7
  dogstatsd-ruby
data/README.md CHANGED
@@ -52,6 +52,9 @@ num_threads: 2
52
52
  # Datadog agent host and port
53
53
  agent_host: localhost
54
54
  agent_port: 8125
55
+ # Logging severity threshold, you have to pass integer related to Logger Ruby class
56
+ # has 1 value by default which is Logger::INFO
57
+ log_level: 1
55
58
  ```
56
59
 
57
60
  Example of environment variables:
@@ -71,13 +74,16 @@ YABEDA_DATADOG_NUM_THREADS=2
71
74
  # Datadog agent host and port
72
75
  YABEDA_DATADOG_AGENT_HOST=localhost
73
76
  YABEDA_DATADOG_AGENT_PORT=8125
77
+ # Logging severity threshold, you have to pass integer related to Logger Ruby class
78
+ # has 1 value by default which is Logger::INFO
79
+ YABEDA_DATADOG_LOG_LEVEL=1
74
80
  ```
75
81
 
76
82
  You can obtain your Datadog API keys in [Datadog dashboard](https://app.datadoghq.com/account/settings#api).
77
83
 
78
84
  Please note, when filling the queue (queue size option), your application will be blocked by waiting for a place in the queue.
79
85
 
80
- You may specify `DATADOG_AGENT_HOST` and/or `DATADOG_AGENT_PORT` environment variables if your Datadog agent is running not on the same host as an app/code that collects metrics.
86
+ You may specify `YABEDA_DATADOG_AGENT_HOST` and/or `YABEDA_DATADOG_AGENT_PORT` environment variables if your Datadog agent is running not on the same host as an app/code that collects metrics.
81
87
 
82
88
  ### Start the adapter
83
89
 
data/examples/script.rb CHANGED
@@ -12,12 +12,12 @@ yabeda_datadog = Yabeda::Datadog.start
12
12
  # $ bin/dev
13
13
  #
14
14
  # To Use this script execute it directly with ruby command.
15
- # You have to provide DATADOG_API_KEY and DATADOG_APP_KEY
15
+ # You have to provide YABEDA_DATADOG_API_KEY and YABEDA_DATADOG_APP_KEY
16
16
  # environment variables.
17
17
  #
18
18
  # Example:
19
19
  #
20
- # DATADOG_API_KEY=<your API key> DATADOG_APP_KEY=<your app key> ruby examples/script.rb
20
+ # YABEDA_DATADOG_API_KEY=<your API key> YABEDA_DATADOG_APP_KEY=<your app key> ruby examples/script.rb
21
21
  #
22
22
 
23
23
  Yabeda.configure do
@@ -14,7 +14,7 @@ module Yabeda
14
14
  # Sends yabeda metrics as custom metrics to DataDog.
15
15
  # https://docs.datadoghq.com/integrations/ruby/
16
16
  class Adapter < BaseAdapter
17
- def initialize(worker: Worker.start)
17
+ def initialize(worker:)
18
18
  @worker = worker
19
19
  end
20
20
 
@@ -59,10 +59,12 @@ module Yabeda
59
59
  attr_reader :worker
60
60
 
61
61
  def enqueue_register(metric)
62
+ Logging.instance.debug("enqueue REGISTER action for metric #{metric.name}")
62
63
  worker.enqueue(:REGISTER, metric: metric)
63
64
  end
64
65
 
65
66
  def enqueue_send(metric, value, tags)
67
+ Logging.instance.debug("enqueue SEND action for metric #{metric.name}")
66
68
  worker.enqueue(:SEND, metric: metric, value: value, tags: tags)
67
69
  end
68
70
  end
@@ -6,15 +6,16 @@ module Yabeda
6
6
  module Datadog
7
7
  # = Describes all config variables
8
8
  class Config < Anyway::Config
9
- env_prefix :datadog
10
- config_name :datadog
9
+ env_prefix :yabeda_datadog
10
+ config_name :yabeda_datadog
11
11
  attr_config :api_key,
12
12
  :app_key,
13
13
  agent_host: "localhost",
14
14
  agent_port: 8125,
15
15
  batch_size: 10,
16
16
  queue_size: 1000,
17
- num_threads: 2
17
+ num_threads: 2,
18
+ log_level: Logger::INFO
18
19
  end
19
20
  end
20
21
  end
@@ -10,27 +10,29 @@ module Yabeda
10
10
  include Singleton
11
11
 
12
12
  def initialize
13
- @logger = Logger.new(STDOUT)
13
+ @logger = Logger.new(STDOUT,
14
+ level: Yabeda::Datadog.config.log_level,
15
+ progname: "yabeda_datadog",)
14
16
  end
15
17
 
16
18
  def warn(message)
17
- @logger.warn message
19
+ @logger.warn(message)
18
20
  end
19
21
 
20
22
  def info(message)
21
- @logger.info message
23
+ @logger.info(message)
22
24
  end
23
25
 
24
26
  def debug(message)
25
- @logger.debug message
27
+ @logger.debug(message)
26
28
  end
27
29
 
28
30
  def fatal(message)
29
- @logger.fatal message
31
+ @logger.fatal(message)
30
32
  end
31
33
 
32
34
  def error(message)
33
- @logger.error message
35
+ @logger.error(message)
34
36
  end
35
37
 
36
38
  def level=(level)
@@ -6,9 +6,9 @@ module Yabeda
6
6
  class ResponseHandler
7
7
  class << self
8
8
  def call(metric)
9
- Logging.instance.info "Sending #{metric.name} metric"
9
+ Logging.instance.debug("sending #{metric.name} metric")
10
10
  response = yield
11
- Logging.instance.info "Response on #{metric.name}: #{handle(response)}"
11
+ Logging.instance.debug("response on #{metric.name}: #{handle(response)}")
12
12
  response
13
13
  end
14
14
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Datadog
5
- VERSION = "0.3.0.rc1"
5
+ VERSION = "0.3.0.rc2"
6
6
  end
7
7
  end
@@ -13,8 +13,8 @@ module Yabeda
13
13
  ResponseHandler.call(metric) do
14
14
  metric.update(dogapi)
15
15
  end
16
- rescue StandardError => e
17
- Logging.instance.fatal "Metric sending failed: #{e.message}"
16
+ rescue StandardError => err
17
+ Logging.instance.error("metric registration failed: #{err.message}")
18
18
  end
19
19
  end
20
20
  end
@@ -5,18 +5,23 @@ module Yabeda
5
5
  class Worker
6
6
  SEND = proc do |accumulated_payload|
7
7
  dogstatsd = ::Datadog::Statsd.new(
8
- ENV.fetch("DATADOG_AGENT_HOST", Yabeda::Datadog.config.agent_host),
9
- ENV.fetch("DATADOG_AGENT_PORT", Yabeda::Datadog.config.agent_port),
8
+ Yabeda::Datadog.config.agent_host,
9
+ Yabeda::Datadog.config.agent_port,
10
10
  )
11
11
 
12
- dogstatsd.batch do |stats|
13
- accumulated_payload.each do |payload|
14
- metric = payload.fetch(:metric)
15
- value = payload.fetch(:value)
16
- tags = payload.fetch(:tags)
12
+ Logging.instance.debug("sending batch of #{accumulated_payload.size} metrics")
13
+ begin
14
+ dogstatsd.batch do |stats|
15
+ accumulated_payload.each do |payload|
16
+ metric = payload.fetch(:metric)
17
+ value = payload.fetch(:value)
18
+ tags = payload.fetch(:tags)
17
19
 
18
- stats.send(metric.type, metric.name, value, tags: tags)
20
+ stats.send(metric.type, metric.name, value, tags: tags)
21
+ end
19
22
  end
23
+ rescue StandardError => err
24
+ Logging.instance.error("metric sending failed: #{err.message}")
20
25
  end
21
26
  end
22
27
  end
@@ -7,9 +7,14 @@ module Yabeda
7
7
  module Datadog
8
8
  # = Perform actions async
9
9
  class Worker
10
- def self.start(queue_size: Yabeda::Datadog.config.queue_size)
11
- instance = new(SizedQueue.new(queue_size))
12
- instance.spawn_threads(Yabeda::Datadog.config.num_threads)
10
+ def self.start(config)
11
+ queue_size = config.queue_size
12
+ num_threads = config.num_threads
13
+ Logging.instance.info("start worker; queue size: #{queue_size}; threads #{num_threads} ")
14
+
15
+ queue = SizedQueue.new(queue_size)
16
+ instance = new(queue)
17
+ instance.spawn_threads(num_threads)
13
18
  instance
14
19
  end
15
20
 
@@ -19,7 +24,6 @@ module Yabeda
19
24
  end
20
25
 
21
26
  def enqueue(action, payload)
22
- Logging.instance.info "enqueue action"
23
27
  queue.push([action, payload])
24
28
  end
25
29
 
@@ -66,6 +70,7 @@ module Yabeda
66
70
  end
67
71
 
68
72
  def stop
73
+ Logging.instance.info("stop worker")
69
74
  queue.close
70
75
  threads.each(&:exit)
71
76
  threads.clear
@@ -19,12 +19,18 @@ module Yabeda
19
19
  @config ||= Config.new
20
20
  end
21
21
 
22
- # Prepare the adapter to work
23
- def self.start
22
+ # Check the gem configuration has valid state
23
+ def self.ensure_configured
24
24
  raise ApiKeyError unless config.api_key
25
25
  raise AppKeyError unless config.app_key
26
+ end
27
+
28
+ # Prepare the adapter to work
29
+ def self.start
30
+ ensure_configured
26
31
 
27
- adapter = Yabeda::Datadog::Adapter.new
32
+ worker = Yabeda::Datadog::Worker.start(config)
33
+ adapter = Yabeda::Datadog::Adapter.new(worker: worker)
28
34
  Yabeda.register_adapter(:datadog, adapter)
29
35
  adapter
30
36
  end
@@ -32,11 +38,11 @@ module Yabeda
32
38
  # Start collection metrics from Yabeda collectors
33
39
  def self.start_exporter(collect_interval: COLLECT_INTERVAL)
34
40
  Thread.new do
35
- Logging.instance.info "initilize collectors harvest"
41
+ Logging.instance.debug("initilize collectors harvest")
36
42
  loop do
37
- Logging.instance.info "start collectors harvest"
43
+ Logging.instance.debug("start collectors harvest")
38
44
  Yabeda.collectors.each(&:call)
39
- Logging.instance.info "end collectors harvest"
45
+ Logging.instance.debug("end collectors harvest")
40
46
  sleep(collect_interval)
41
47
  end
42
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-datadog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.rc1
4
+ version: 0.3.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Shvetsov <@shvetsovdm>