pliny-librato 0.5.0 → 0.5.1

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: d96c0fdc1c319b07e42ee4dc5eba2bad209a7726
4
- data.tar.gz: 5b29955485124e99c6e5e0b8b6c8d40d1cd431e6
3
+ metadata.gz: 5dad320432446a53b261cac33b5fc636eeb492c8
4
+ data.tar.gz: 234d35819926bb0ddb1b27be431478d2b7f43a3a
5
5
  SHA512:
6
- metadata.gz: ea01e6cfa6c5539e079550ac03262c308dafa5dc7700b3a7904cee6e97410f76e8869375795b9466fd17d2508158828ed2487b4529d367bdd28aafa2265d2036
7
- data.tar.gz: 496100d0f6960734f8c32ae7803ed494c371c9a456c1bb1c9bb37d19da02c89bedb220319074f7fdfb65979457b5be333738030e519b133f226fb74120e93768
6
+ metadata.gz: fd225bebe9d5c1539da97b63072b33da4b1698946f4f75a4ac3dee9924951b957a23cd74185de160ad4abcb1d64d2f437cc58cc102076ed8d605a5f394c119b6
7
+ data.tar.gz: 4250c8362aa9d8e91e2aad1ba85f83193fe76453263baa3955942a7b0d83cf177918ea5f58f33489fa6aa68ef4f05bab7e473b1946ad71cf10bc9b4b1188c22e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ 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
8
+
9
+ ## 0.5.1
10
+
11
+ ### Changed
12
+
13
+ - The default submission interval is now 60 seconds for consistency with
14
+ l2met and this project's README.
15
+ - Metrics are now regularly submitted on the desired interval. Previously,
16
+ a new metric would need to be queued after the interval expired.
17
+
7
18
  ## 0.5.0
8
19
 
9
20
  ### Added
data/README.md CHANGED
@@ -43,15 +43,16 @@ Pliny::Metrics.measure(:bar) do
43
43
  end
44
44
  ```
45
45
 
46
- By default, it will send queued metrics every minute, or whenever the
47
- queue reaches 1000 metrics. These settings can be configured on initialization.
46
+ By default, it will send queued metrics every minute, and anytime the
47
+ queue reaches 500 metrics. These settings can be configured on initialization.
48
48
 
49
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.
50
+ By default, any unsubmitted metrics on the queue will not be sent at shutdown.
51
+ It is the responsibility of the caller to trigger this.
51
52
 
52
53
  ```ruby
53
54
  # In the main process
54
- Signal.trap('TERM') do
55
+ Kernel.on_exit do
55
56
  librato_backend.stop
56
57
  end
57
58
 
@@ -9,7 +9,7 @@ module Pliny
9
9
  class Backend
10
10
  POISON_PILL = :'❨╯°□°❩╯︵┻━┻'
11
11
 
12
- def initialize(source: nil, interval: 10, count: 500)
12
+ def initialize(source: nil, interval: 60, count: 500)
13
13
  @source = source
14
14
  @interval = interval
15
15
  @count = count
@@ -24,61 +24,66 @@ module Pliny
24
24
  end
25
25
 
26
26
  def start
27
- start_thread
27
+ start_counter
28
+ start_timer
28
29
  self
29
30
  end
30
31
 
31
32
  def stop
32
33
  metrics_queue.push(POISON_PILL)
33
- thread.join
34
+ timer.terminate
35
+ counter.join
36
+ flush_librato
34
37
  end
35
38
 
36
39
  private
37
40
 
38
- attr_reader :source, :interval, :count, :thread
41
+ attr_reader :source, :interval, :count, :timer, :counter
39
42
 
40
- def start_thread
41
- @thread = Thread.new do
43
+ def start_timer
44
+ @timer = Thread.new do
42
45
  loop do
43
- msg = metrics_queue.pop
44
- break unless process(msg)
46
+ sleep interval
47
+ flush_librato
45
48
  end
46
49
  end
47
50
  end
48
51
 
49
- def process(msg)
50
- if msg == POISON_PILL
51
- flush_librato
52
- false
53
- else
54
- enqueue_librato(msg)
55
- true
52
+ def start_counter
53
+ @counter = Thread.new do
54
+ loop do
55
+ msg = metrics_queue.pop
56
+ msg == POISON_PILL ? break : enqueue_librato(msg)
57
+ end
56
58
  end
57
59
  end
58
60
 
59
61
  def enqueue_librato(msg)
60
- with_error_report { librato_queue.add(msg) }
62
+ sync { librato_queue.add(msg) }
61
63
  end
62
64
 
63
65
  def flush_librato
64
- with_error_report { librato_queue.submit }
66
+ sync { librato_queue.submit }
65
67
  end
66
68
 
67
- def with_error_report
68
- yield
69
+ def sync(&block)
70
+ mutex.synchronize(&block)
69
71
  rescue => error
70
72
  Pliny::ErrorReporters.notify(error)
71
73
  end
72
74
 
75
+ def mutex
76
+ @mutex ||= Mutex.new
77
+ end
78
+
73
79
  def metrics_queue
74
80
  @metrics_queue ||= Queue.new
75
81
  end
76
82
 
77
83
  def librato_queue
78
84
  @librato_queue ||= ::Librato::Metrics::Queue.new(
79
- source: source,
80
- autosubmit_interval: interval,
81
- autosubmit_count: count
85
+ source: source,
86
+ autosubmit_count: count
82
87
  )
83
88
  end
84
89
  end
@@ -1,5 +1,5 @@
1
1
  module Pliny
2
2
  module Librato
3
- VERSION = "0.5.0"
3
+ VERSION = '0.5.1'
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.5.0
4
+ version: 0.5.1
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: 2017-01-04 00:00:00.000000000 Z
12
+ date: 2017-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librato-metrics