pliny-librato 0.4.0 → 0.5.0

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: 362932985964ab9a8467c82061e5a6950a6d12ef
4
- data.tar.gz: 1243663968f6966454a4a537185654f30725f9c3
3
+ metadata.gz: d96c0fdc1c319b07e42ee4dc5eba2bad209a7726
4
+ data.tar.gz: 5b29955485124e99c6e5e0b8b6c8d40d1cd431e6
5
5
  SHA512:
6
- metadata.gz: c666a43801fda7e4730e8933dfdec3c76aecb2d31a681d6448f08506ece4c45c4bfcba8873aec9ce5e31b8b5ca6528206fe1e4a9f119a4755f60103b94d47f43
7
- data.tar.gz: 96e7b31fe8e42ef8e7bc61b14306546ebaea28547c607f4d5c638b5b3711c4d6fd4e83429227a044fca6f17a35149a5224984de4c9a7ee6c35cc4e3b8a604e1b
6
+ metadata.gz: ea01e6cfa6c5539e079550ac03262c308dafa5dc7700b3a7904cee6e97410f76e8869375795b9466fd17d2508158828ed2487b4529d367bdd28aafa2265d2036
7
+ data.tar.gz: 496100d0f6960734f8c32ae7803ed494c371c9a456c1bb1c9bb37d19da02c89bedb220319074f7fdfb65979457b5be333738030e519b133f226fb74120e93768
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pliny-librato*.gem
2
+ Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
- ## [Unreleased]
7
+ ## 0.5.0
8
+
9
+ ### Added
10
+
11
+ - Metrics are now reported to Librato from within a thread to prevent blocking
12
+
13
+ ### Changed
14
+
15
+ - The backend must be started with `#start` and stopped with `#stop`. For example
16
+ `backend = Backend.new(opts).start`, `backend.stop`.
8
17
 
9
18
  ## 0.4.0
10
19
 
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A [Librato](https://librato.com) metrics reporter backend for [pliny](https://github.com/interagent/pliny).
4
4
 
5
+
6
+ This backend will push reported metrics onto a queue, then periodically
7
+ submit them asynchronously.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -24,7 +28,9 @@ Add a new initializer `config/initializers/librato.rb`:
24
28
 
25
29
  ```ruby
26
30
  Librato::Metrics.authenticate(Config.librato_email, Config.librato_key)
27
- Pliny::Metrics.backends << Pliny::Librato::Metrics::Backend.new(source: "myapp.production")
31
+ librato_backend = Pliny::Librato::Metrics::Backend.new(source: "myapp.production")
32
+ librato_backend.start
33
+ Pliny::Metrics.backends << librato_backend
28
34
  ```
29
35
 
30
36
  Now `Pliny::Metrics` methods will build a queue and automatically send metrics
@@ -40,6 +46,28 @@ end
40
46
  By default, it will send queued metrics every minute, or whenever the
41
47
  queue reaches 1000 metrics. These settings can be configured on initialization.
42
48
 
49
+ ## Shutdown
50
+ By default, any unsubmitted metrics on the queue will not be sent at shutdown. It is the responsibility of the caller to trigger this.
51
+
52
+ ```ruby
53
+ # In the main process
54
+ Signal.trap('TERM') do
55
+ librato_backend.stop
56
+ end
57
+
58
+ # e.g. in Puma
59
+ on_worker_shutdown do
60
+ librato_backend.stop
61
+ end
62
+
63
+ # e.g. in Sidekiq
64
+ Sidekiq.configure_server do |config|
65
+ config.on(:shutdown) do
66
+ librato_backend.stop
67
+ end
68
+ end
69
+ ```
70
+
43
71
  ## Development
44
72
 
45
73
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,35 +7,79 @@ module Pliny
7
7
  # Implements the Pliny::Metrics.backends API. Puts any metrics sent
8
8
  # from Pliny::Metrics onto a queue that gets submitted in batches.
9
9
  class Backend
10
- attr_reader :queue
10
+ POISON_PILL = :'❨╯°□°❩╯︵┻━┻'
11
11
 
12
- def initialize(source: nil, interval: 60, count: 1000, queue: nil)
13
- @queue = queue || ::Librato::Metrics::Queue.new(
14
- source: source,
15
- autosubmit_interval: interval,
16
- autosubmit_count: count
17
- )
18
- flush_on_shutdown
12
+ def initialize(source: nil, interval: 10, count: 500)
13
+ @source = source
14
+ @interval = interval
15
+ @count = count
19
16
  end
20
17
 
21
18
  def report_counts(counts)
22
- report(counts)
19
+ metrics_queue.push(counts)
23
20
  end
24
21
 
25
22
  def report_measures(measures)
26
- report(measures)
23
+ metrics_queue.push(measures)
24
+ end
25
+
26
+ def start
27
+ start_thread
28
+ self
29
+ end
30
+
31
+ def stop
32
+ metrics_queue.push(POISON_PILL)
33
+ thread.join
27
34
  end
28
35
 
29
36
  private
30
37
 
31
- def report(metrics)
32
- queue.add(metrics)
38
+ attr_reader :source, :interval, :count, :thread
39
+
40
+ def start_thread
41
+ @thread = Thread.new do
42
+ loop do
43
+ msg = metrics_queue.pop
44
+ break unless process(msg)
45
+ end
46
+ end
47
+ end
48
+
49
+ def process(msg)
50
+ if msg == POISON_PILL
51
+ flush_librato
52
+ false
53
+ else
54
+ enqueue_librato(msg)
55
+ true
56
+ end
57
+ end
58
+
59
+ def enqueue_librato(msg)
60
+ with_error_report { librato_queue.add(msg) }
61
+ end
62
+
63
+ def flush_librato
64
+ with_error_report { librato_queue.submit }
65
+ end
66
+
67
+ def with_error_report
68
+ yield
33
69
  rescue => error
34
70
  Pliny::ErrorReporters.notify(error)
35
71
  end
36
72
 
37
- def flush_on_shutdown
38
- Signal.trap('TERM') { queue.submit }
73
+ def metrics_queue
74
+ @metrics_queue ||= Queue.new
75
+ end
76
+
77
+ def librato_queue
78
+ @librato_queue ||= ::Librato::Metrics::Queue.new(
79
+ source: source,
80
+ autosubmit_interval: interval,
81
+ autosubmit_count: count
82
+ )
39
83
  end
40
84
  end
41
85
  end
@@ -1,5 +1,5 @@
1
1
  module Pliny
2
2
  module Librato
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pliny-librato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Appleton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-12-16 00:00:00.000000000 Z
12
+ date: 2017-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librato-metrics
@@ -133,7 +133,6 @@ files:
133
133
  - ".rspec"
134
134
  - CHANGELOG.md
135
135
  - Gemfile
136
- - Gemfile.lock
137
136
  - README.md
138
137
  - Rakefile
139
138
  - bin/console
data/Gemfile.lock DELETED
@@ -1,97 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- pliny-librato (0.3.0)
5
- librato-metrics (~> 2.0)
6
- pliny (>= 0.20.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (4.2.7.1)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- aggregate (0.2.2)
18
- byebug (9.0.6)
19
- coderay (1.1.1)
20
- diff-lcs (1.2.5)
21
- erubis (2.7.0)
22
- faraday (0.10.0)
23
- multipart-post (>= 1.2, < 3)
24
- http_accept (0.1.6)
25
- i18n (0.7.0)
26
- json (1.8.3)
27
- json_schema (0.16.0)
28
- librato-metrics (2.0.2)
29
- aggregate (~> 0.2.2)
30
- faraday
31
- method_source (0.8.2)
32
- minitest (5.10.1)
33
- multi_json (1.12.1)
34
- multipart-post (2.0.0)
35
- pliny (0.21.0)
36
- activesupport (~> 4.1, >= 4.1.0)
37
- http_accept (~> 0.1, >= 0.1.5)
38
- multi_json (~> 1.9, >= 1.9.3)
39
- prmd (~> 0.11, >= 0.11.4)
40
- sinatra (~> 1.4, >= 1.4.7)
41
- sinatra-router (~> 0.2, >= 0.2.3)
42
- thor (~> 0.19, >= 0.19.1)
43
- prmd (0.13.0)
44
- erubis (~> 2.7)
45
- json_schema (~> 0.3, >= 0.3.1)
46
- pry (0.10.4)
47
- coderay (~> 1.1.0)
48
- method_source (~> 0.8.1)
49
- slop (~> 3.4)
50
- pry-byebug (3.4.1)
51
- byebug (~> 9.0)
52
- pry (~> 0.10)
53
- rack (1.6.5)
54
- rack-protection (1.5.3)
55
- rack
56
- rake (10.5.0)
57
- rspec (3.5.0)
58
- rspec-core (~> 3.5.0)
59
- rspec-expectations (~> 3.5.0)
60
- rspec-mocks (~> 3.5.0)
61
- rspec-core (3.5.4)
62
- rspec-support (~> 3.5.0)
63
- rspec-expectations (3.5.0)
64
- diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.5.0)
66
- rspec-mocks (3.5.0)
67
- diff-lcs (>= 1.2.0, < 2.0)
68
- rspec-support (~> 3.5.0)
69
- rspec-support (3.5.0)
70
- sinatra (1.4.7)
71
- rack (~> 1.5)
72
- rack-protection (~> 1.4)
73
- tilt (>= 1.3, < 3)
74
- sinatra-router (0.2.3)
75
- sinatra (~> 1.4)
76
- slop (3.6.0)
77
- thor (0.19.4)
78
- thread_safe (0.3.5)
79
- tilt (2.0.5)
80
- timecop (0.8.1)
81
- tzinfo (1.2.2)
82
- thread_safe (~> 0.1)
83
-
84
- PLATFORMS
85
- ruby
86
-
87
- DEPENDENCIES
88
- bundler (~> 1.13)
89
- pliny-librato!
90
- pry (~> 0.10)
91
- pry-byebug (~> 3.4)
92
- rake (~> 10.0)
93
- rspec (~> 3.3)
94
- timecop (~> 0.8.1)
95
-
96
- BUNDLED WITH
97
- 1.13.6