tremolo 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: e7dfce98c352baef3925e7d7fd7852819a14dbb9
4
- data.tar.gz: b45fc0011cc43ede092f8c490c82636a3d8a55f8
3
+ metadata.gz: 32a54e2c56f4c0dc08262bed5ff4b8bf74ad037d
4
+ data.tar.gz: 5781e18979cf200095c21a4a6abca08473055917
5
5
  SHA512:
6
- metadata.gz: eb56f8c4590bb28e8225ca6374dcf44b403cc0c03d91d96bc4973678dbedf17b18ede5b9ac2361691fc8f603c60af6c08c0e44a34ac40f7b602559db741fb5c3
7
- data.tar.gz: a8631daa572cc518bb8d37fad625f3097048e1946bb82e8e2810ab2e731658db431e90b3b762a4a085f3513b80602e3ff0f8e7619435f61db1a1aeb457c1205a
6
+ metadata.gz: 59cd090fc5980557f1dec2608bac50d2f9bafae025e811dbee903fb7ab944ef3f9c9375e378023ea98df9bee9799cff0581a1c932ebc95a128478a756bd3a9f5
7
+ data.tar.gz: d3936ce56375039d9a769fd6cd1b1bf440a2b49eba236a4140c763d000a9d08a47649e68b8b49c7ce8c282ddaf2cf5745292752a4e5fe3ad0bd9c23130978bec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## Tremolo 0.0.4 ##
2
+
3
+ * Make Tremolo::Tracker a Celluloid actor so that it can be supervised if desired
4
+ * Trap a dying Sender in Tracker and set to nil to let it reload
5
+ * Create Sender on the fly in the Tracker using `new_link`
6
+ * Add Tremolo.supervised_tracker
7
+
8
+ *Tony Pitale*
9
+
1
10
  ## Tremolo 0.0.3 ##
2
11
 
3
12
  * Bump celluloid-io requirement to support `UDPSocket.connect`
data/README.md CHANGED
@@ -16,17 +16,28 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install tremolo
18
18
 
19
+ ## Is it any good?
20
+
21
+ It's getting there, but some of the nuance of the method API and Celluloid's behavior are still being worked out. I'll let you know when it's settled down a bit more.
22
+
19
23
  ## Usage
20
24
 
21
25
  ```ruby
22
- # Get a tracker
26
+ # Get an unsupervised tracker
23
27
  tracker = Tremolo.tracker('0.0.0.0', 4444)
24
28
 
25
29
  # options that can be set on the tracker:
26
30
  # namespace, a string prefix for all series names on this tracker, joined with '.' (default="")
27
-
28
31
  tracker = Tremolo.tracker('0.0.0.0', 4444, namespace: 'appname')
29
32
 
33
+ # tracker is a Celluloid Actor, it will not be GC'd like you would expect so I'd advise against doing it this way.
34
+
35
+ # Because we're using celluloid, we probably want to create a supervised tracker
36
+ Tremolo.supervised_tracker(:tracker, '0.0.0.0', 4444, namespace: 'appname')
37
+
38
+ # whenever you want to use this supervised tracker, you can always ask Celluloid
39
+ tracker = Celluloid::Actor[:tracker]
40
+
30
41
  # Write a point to 'series-name' series
31
42
  tracker.write_point('series-name', {:value => 121, :otherdata => 998142})
32
43
 
@@ -1,6 +1,5 @@
1
1
  module Tremolo
2
2
  class Sender
3
- # include Celluloid::Logger
4
3
  include Celluloid::IO
5
4
 
6
5
  def initialize(host, port)
@@ -11,8 +10,7 @@ module Tremolo
11
10
  def write_points(series_name, data)
12
11
  begin
13
12
  @socket.send(prepare(series_name, data), 0)
14
- rescue Errno::ECONNREFUSED => e
15
- # debug "Connection refused. Ignoring."
13
+ rescue Errno::ECONNREFUSED
16
14
  nil
17
15
  end
18
16
  end
@@ -1,5 +1,7 @@
1
1
  module Tremolo
2
2
  class Series
3
+ include Celluloid
4
+
3
5
  attr_reader :tracker, :series_name
4
6
 
5
7
  def initialize(tracker, series_name)
@@ -1,9 +1,13 @@
1
1
  module Tremolo
2
2
  class Tracker
3
+ include Celluloid
4
+
5
+ trap_exit :sender_died
6
+
3
7
  attr_reader :namespace
4
8
 
5
9
  def initialize(host, port, options={})
6
- @sender = Sender.new(host, port)
10
+ @host, @port = host, port
7
11
 
8
12
  @namespace = options[:namespace]
9
13
  end
@@ -37,7 +41,16 @@ module Tremolo
37
41
  end
38
42
 
39
43
  def write_points(series_name, data)
40
- @sender.write_points([namespace, series_name].compact.join('.'), data)
44
+ sender.async.write_points([namespace, series_name].compact.join('.'), data)
45
+ end
46
+
47
+ private
48
+ def sender
49
+ @sender ||= Sender.new_link(@host, @port)
50
+ end
51
+
52
+ def sender_died(actor, reason=nil)
53
+ @sender = nil
41
54
  end
42
55
  end
43
56
  end
@@ -1,3 +1,3 @@
1
1
  module Tremolo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/tremolo.rb CHANGED
@@ -11,7 +11,18 @@ module Tremolo
11
11
  Tracker.new(host, port, options)
12
12
  end
13
13
  end
14
+
15
+ def supervised_tracker(as, host, port, options={})
16
+ if host.nil? || port.nil?
17
+ NoopTracker.new(host, port, options)
18
+ else
19
+ Tracker.supervise_as as.to_sym, host, port, options
20
+ Celluloid::Actor[as.to_sym]
21
+ end
22
+ end
23
+
14
24
  module_function :tracker
25
+ module_function :supervised_tracker
15
26
  end
16
27
 
17
28
  require 'tremolo/data_point'
@@ -40,4 +40,8 @@ describe Tremolo::NoopTracker do
40
40
  expect(returned).to eq('returning a thing')
41
41
  expect(socket).to have_received(:send).never
42
42
  end
43
+
44
+ it 'makes a series for itself', :celluloid => true do
45
+ expect(tracker.series('timing.accounts')).to be_kind_of(Tremolo::Series)
46
+ end
43
47
  end
@@ -1,49 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Tremolo::Tracker do
3
+ describe Tremolo::Series do
4
4
  let(:socket) {stub(:connect => true, :send => true)}
5
- let(:tracker) {Tremolo.tracker('0.0.0.0', 4444)}
5
+ let(:tracker) {
6
+ Tremolo.supervised_tracker(:tracker, '0.0.0.0', 4444)
7
+ }
6
8
  let(:series) {tracker.series('accounts.created')}
7
9
 
8
10
  before(:each) do
9
11
  Celluloid::IO::UDPSocket.stubs(:new).returns(socket)
10
12
  end
11
13
 
12
- it 'sends point data formatted for InfluxDB' do
14
+ it 'sends point data formatted for InfluxDB', :celluloid => true do
13
15
  series.write_point({value: 111, associated_id: 81102})
14
16
 
15
17
  json = '[{"name":"accounts.created","columns":["associated_id","value"],"points":[[81102,111]]}]'
16
18
 
19
+ sleep 0.1
17
20
  expect(socket).to have_received(:send).with(json, 0)
18
21
  end
19
22
 
20
- it 'sends single point with value 1' do
23
+ it 'sends single point with value 1', :celluloid => true do
21
24
  series.increment
22
25
 
23
26
  json = '[{"name":"accounts.created","columns":["value"],"points":[[1]]}]'
24
27
 
28
+ sleep 0.1
25
29
  expect(socket).to have_received(:send).with(json, 0)
26
30
  end
27
31
 
28
- it 'sends single point with value -1' do
32
+ it 'sends single point with value -1', :celluloid => true do
29
33
  series.decrement
30
34
 
31
35
  json = '[{"name":"accounts.created","columns":["value"],"points":[[-1]]}]'
32
36
 
37
+ sleep 0.1
33
38
  expect(socket).to have_received(:send).with(json, 0)
34
39
  end
35
40
 
36
- it 'tracks timing value for ms' do
41
+ it 'tracks timing value for ms', :celluloid => true do
37
42
  series.timing(89)
38
43
 
39
44
  json = '[{"name":"accounts.created","columns":["value"],"points":[[89]]}]'
40
45
 
46
+ sleep 0.1
41
47
  expect(socket).to have_received(:send).with(json, 0)
42
48
  end
43
49
 
44
- it 'tracks block timing value for ms' do
50
+ it 'tracks block timing value for ms', :celluloid => true do
45
51
  # PREVENT Timers in Celluloid from calling Time.now all the time
46
- Timers.any_instance.stubs(:wait_interval).returns(nil)
52
+ Timers.stubs(:wait_interval).returns(nil)
47
53
 
48
54
  start_at = Time.now
49
55
  end_at = start_at + 1.05 # 1013.5 ms, rounds to 1014
@@ -56,6 +62,7 @@ describe Tremolo::Tracker do
56
62
 
57
63
  json = '[{"name":"accounts.created","columns":["value"],"points":[[1050]]}]'
58
64
 
65
+ sleep 0.1
59
66
  expect(returned).to eq('returning another thing')
60
67
  expect(socket).to have_received(:send).with(json, 0)
61
68
  end
@@ -2,47 +2,54 @@ require 'spec_helper'
2
2
 
3
3
  describe Tremolo::Tracker do
4
4
  let(:socket) {stub(:connect => true, :send => true)}
5
- let(:tracker) {Tremolo.tracker('0.0.0.0', 4444)}
5
+ let(:tracker) {
6
+ Tremolo.supervised_tracker(:tracker, '0.0.0.0', 4444)
7
+ }
6
8
 
7
9
  before(:each) do
8
10
  Celluloid::IO::UDPSocket.stubs(:new).returns(socket)
9
11
  end
10
12
 
11
- it 'sends point data formatted for InfluxDB' do
13
+ it 'sends point data formatted for InfluxDB', :celluloid => true do
12
14
  tracker.write_point('accounts.created', {value: 111, associated_id: 81102})
13
15
 
14
16
  json = '[{"name":"accounts.created","columns":["associated_id","value"],"points":[[81102,111]]}]'
15
17
 
18
+
19
+ sleep 0.1
16
20
  expect(socket).to have_received(:send).with(json, 0)
17
21
  end
18
22
 
19
- it 'sends single point with value 1' do
23
+ it 'sends single point with value 1', :celluloid => true do
20
24
  tracker.increment('accounts.created')
21
25
 
22
26
  json = '[{"name":"accounts.created","columns":["value"],"points":[[1]]}]'
23
27
 
28
+ sleep 0.1
24
29
  expect(socket).to have_received(:send).with(json, 0)
25
30
  end
26
31
 
27
- it 'sends single point with value -1' do
32
+ it 'sends single point with value -1', :celluloid => true do
28
33
  tracker.decrement('accounts.created')
29
34
 
30
35
  json = '[{"name":"accounts.created","columns":["value"],"points":[[-1]]}]'
31
36
 
37
+ sleep 0.1
32
38
  expect(socket).to have_received(:send).with(json, 0)
33
39
  end
34
40
 
35
- it 'tracks timing value for ms' do
41
+ it 'tracks timing value for ms', :celluloid => true do
36
42
  tracker.timing('timing.accounts.created', 89)
37
43
 
38
44
  json = '[{"name":"timing.accounts.created","columns":["value"],"points":[[89]]}]'
39
45
 
46
+ sleep 0.1
40
47
  expect(socket).to have_received(:send).with(json, 0)
41
48
  end
42
49
 
43
- it 'tracks block timing value for ms' do
50
+ it 'tracks block timing value for ms', :celluloid => true do
44
51
  # PREVENT Timers in Celluloid from calling Time.now all the time
45
- Timers.any_instance.stubs(:wait_interval).returns(nil)
52
+ Timers.stubs(:wait_interval).returns(nil)
46
53
 
47
54
  start_at = Time.now
48
55
  end_at = start_at + 1.0135 # 1013.5 ms, rounds to 1014
@@ -55,6 +62,7 @@ describe Tremolo::Tracker do
55
62
 
56
63
  json = '[{"name":"timing.accounts.created","columns":["value"],"points":[[1014]]}]'
57
64
 
65
+ sleep 0.1
58
66
  expect(returned).to eq('returning a thing')
59
67
  expect(socket).to have_received(:send).with(json, 0)
60
68
  end
@@ -62,11 +70,12 @@ describe Tremolo::Tracker do
62
70
  context "with a namespace" do
63
71
  let(:tracker) {Tremolo.tracker('0.0.0.0', 4444, namespace: 'alf')}
64
72
 
65
- it 'tracks timing value for ms' do
73
+ it 'tracks timing value for ms', :celluloid => true do
66
74
  tracker.timing('timing.accounts.created', 14)
67
75
 
68
76
  json = '[{"name":"alf.timing.accounts.created","columns":["value"],"points":[[14]]}]'
69
77
 
78
+ sleep 0.1
70
79
  expect(socket).to have_received(:send).with(json, 0)
71
80
  end
72
81
  end
data/spec/spec_helper.rb CHANGED
@@ -6,10 +6,20 @@ require 'bundler/setup'
6
6
  require 'rspec'
7
7
  require 'mocha/api'
8
8
  require 'bourne'
9
+ require 'celluloid/test'
10
+
11
+ $CELLULOID_DEBUG = false
9
12
 
10
13
  require File.expand_path('../../lib/tremolo', __FILE__)
11
14
 
12
15
  RSpec.configure do |config|
13
16
  config.mock_with :mocha
14
17
  config.order = 'random'
18
+
19
+ config.around :celluloid => true do |e|
20
+ Celluloid.boot
21
+ e.run
22
+ Celluloid.shutdown
23
+ Celluloid::Actor.clear_registry
24
+ end
15
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tremolo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-io