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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +13 -2
- data/lib/tremolo/sender.rb +1 -3
- data/lib/tremolo/series.rb +2 -0
- data/lib/tremolo/tracker.rb +15 -2
- data/lib/tremolo/version.rb +1 -1
- data/lib/tremolo.rb +11 -0
- data/spec/lib/tremolo/noop_tracker_spec.rb +4 -0
- data/spec/lib/tremolo/series_spec.rb +15 -8
- data/spec/lib/tremolo/tracker_spec.rb +17 -8
- data/spec/spec_helper.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a54e2c56f4c0dc08262bed5ff4b8bf74ad037d
|
4
|
+
data.tar.gz: 5781e18979cf200095c21a4a6abca08473055917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
data/lib/tremolo/sender.rb
CHANGED
@@ -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
|
15
|
-
# debug "Connection refused. Ignoring."
|
13
|
+
rescue Errno::ECONNREFUSED
|
16
14
|
nil
|
17
15
|
end
|
18
16
|
end
|
data/lib/tremolo/series.rb
CHANGED
data/lib/tremolo/tracker.rb
CHANGED
@@ -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
|
-
@
|
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
|
-
|
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
|
data/lib/tremolo/version.rb
CHANGED
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::
|
3
|
+
describe Tremolo::Series do
|
4
4
|
let(:socket) {stub(:connect => true, :send => true)}
|
5
|
-
let(:tracker) {
|
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.
|
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) {
|
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.
|
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.
|
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-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|