appdash 0.6.1 → 0.6.2

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: 600ac6a714c1c25d63a282f1e2995c280e858b19
4
- data.tar.gz: d465ba502a447dea8b85236887dcda663f3aa811
3
+ metadata.gz: 9ad7c405c963438df0518090edb4fe540a0b1001
4
+ data.tar.gz: 3fda9cf94875dce0d5b65b6b9e4ca190aca0ee39
5
5
  SHA512:
6
- metadata.gz: 912e56d21fbe32ae827d509357f631735f95068e1a85122f59d8f6826177acf96cd474a76b26b63fa13c731fcd22655ea3a0914a5063cb3a7b3c6691fd5e1b00
7
- data.tar.gz: 583bd30c42842628bfc8ad7e7422353a003a8d719569109ea9028b1345a3511b7fb2cd6d4a76d988e6e0b2f714d18f6fbbeba0a8bc57ba03fad360a42ef0b45b
6
+ metadata.gz: db2a7a74f651e4f30011b4f2e2c30f942f1a1a49f4c4b92d67aabcfa13c02c4a3bbe0aa748da6f542414596e9dcbc10d0b2b5771ee0ea048f4bfc69d78b0b567
7
+ data.tar.gz: 32e1b82da195f0179f294fa214b5b37f41d1fa8f1aa95f26b1aeadfaa037c891e6a83254847c2abd2085af818385fac6b6c4f66fbca780e55dbadc3669a30217
data/Gemfile.lock CHANGED
@@ -1,49 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- appdash (0.6.1)
5
- protobuf
4
+ appdash (0.6.2)
5
+ ruby-protocol-buffers
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activesupport (4.2.5)
11
- i18n (~> 0.7)
12
- json (~> 1.7, >= 1.7.7)
13
- minitest (~> 5.1)
14
- thread_safe (~> 0.3, >= 0.3.4)
15
- tzinfo (~> 1.1)
16
- diff-lcs (1.2.5)
17
- i18n (0.7.0)
18
- json (1.8.3)
19
- middleware (0.1.0)
20
- minitest (5.8.3)
21
- protobuf (3.5.5)
22
- activesupport (>= 3.2)
23
- middleware
24
- thor
25
- thread_safe
26
- rack (1.6.4)
10
+ diff-lcs (1.3)
11
+ rack (2.0.1)
27
12
  rack-test (0.6.3)
28
13
  rack (>= 1.0)
29
- rake (10.4.2)
30
- rspec (3.4.0)
31
- rspec-core (~> 3.4.0)
32
- rspec-expectations (~> 3.4.0)
33
- rspec-mocks (~> 3.4.0)
34
- rspec-core (3.4.1)
35
- rspec-support (~> 3.4.0)
36
- rspec-expectations (3.4.0)
14
+ rake (12.0.0)
15
+ rspec (3.5.0)
16
+ rspec-core (~> 3.5.0)
17
+ rspec-expectations (~> 3.5.0)
18
+ rspec-mocks (~> 3.5.0)
19
+ rspec-core (3.5.4)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-expectations (3.5.0)
37
22
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.4.0)
39
- rspec-mocks (3.4.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-mocks (3.5.0)
40
25
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.4.0)
42
- rspec-support (3.4.1)
43
- thor (0.19.1)
44
- thread_safe (0.3.5)
45
- tzinfo (1.2.2)
46
- thread_safe (~> 0.1)
26
+ rspec-support (~> 3.5.0)
27
+ rspec-support (3.5.0)
28
+ ruby-protocol-buffers (1.6.1)
47
29
 
48
30
  PLATFORMS
49
31
  ruby
@@ -57,4 +39,4 @@ DEPENDENCIES
57
39
  rspec
58
40
 
59
41
  BUNDLED WITH
60
- 1.10.6
42
+ 1.14.5
data/appdash.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "appdash"
5
- s.version = "0.6.1"
5
+ s.version = "0.6.2"
6
6
  s.authors = ["Black Square Media"]
7
7
  s.email = ["dimitrij@blacksquaremedia.com"]
8
8
  s.summary = %q{Appdash client for ruby}
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.test_files = s.files.grep(%r{^(spec)/})
15
15
  s.require_paths = ["lib"]
16
16
 
17
- s.add_dependency(%q<protobuf>)
17
+ s.add_dependency(%q<ruby-protocol-buffers>)
18
18
 
19
19
  s.add_development_dependency(%q<rake>)
20
20
  s.add_development_dependency(%q<rack>)
@@ -0,0 +1,37 @@
1
+ require 'stringio'
2
+
3
+ module Appdash
4
+ class Buffer < ::StringIO
5
+
6
+ def initialize
7
+ super
8
+ binmode
9
+ end
10
+
11
+ def push(packet)
12
+ payload = packet.serialize_to_string
13
+ write_uvarint payload.bytesize
14
+ write payload
15
+ end
16
+
17
+ def bytesize
18
+ string.bytesize
19
+ end
20
+
21
+ def reset
22
+ truncate(0)
23
+ rewind
24
+ end
25
+
26
+ private
27
+
28
+ def write_uvarint(x)
29
+ while x >= 0x80
30
+ write ((x & 0xFF) | 0x80).chr
31
+ x >>= 7
32
+ end
33
+ write (x & 0xFF).chr
34
+ end
35
+
36
+ end
37
+ end
@@ -1,5 +1,6 @@
1
1
  require 'socket'
2
2
  require 'thread'
3
+ require 'appdash/buffer'
3
4
 
4
5
  module Appdash
5
6
  class Client
@@ -8,19 +9,19 @@ module Appdash
8
9
  DEFAULTS = {
9
10
  host: 'localhost',
10
11
  port: 7701,
11
- max_buffer_size: 1,
12
+ max_buffer_size: 0,
12
13
  }.freeze
13
14
 
14
15
  # Initializes a new client
15
16
  # @param [Hash] opts
16
17
  # @option opts [String] :host the hostname, defaults to localhost
17
18
  # @option opts [Integer] :port the port, defaults to 7701
18
- # @option opts [Integer] :max_buffer_size number of spans in the buffer before flushing, defaults to 1 (= no buffering)
19
+ # @option opts [Integer] :max_buffer_size maximum buffer size in bytes, defaults to 0 (= no buffering, flushes on every span)
19
20
  def initialize(opts = {})
20
21
  @config = DEFAULTS.merge(opts)
21
- @sock = TCPSocket.new @config[:host], @config[:port]
22
- @buffer = []
22
+ @buffer = Buffer.new
23
23
  @mutex = Mutex.new
24
+ reconnect!
24
25
  end
25
26
 
26
27
  # Traces a new span with a series of associated events. Accepts an optional block. If no block is given you must flush
@@ -50,28 +51,42 @@ module Appdash
50
51
  end
51
52
  end
52
53
 
53
- # Shutdown flushes any remaining buffered packets and closes the connection
54
- def shutdown
54
+ # Close flushes any remaining buffered packets and closes the connection
55
+ def close
55
56
  flush_buffer!
56
- @sock.shutdown
57
+ @sock.close
57
58
  end
58
59
 
59
60
  private
60
61
 
61
62
  def write(packets)
62
63
  packets.each do |packet|
63
- raw = Protobuf::Field::VarintField.encode(packet.bytesize)+packet
64
- @buffer.push(raw)
64
+ @buffer.push(packet)
65
65
  end
66
- flush_buffer! unless @buffer.size < @config[:max_buffer_size]
66
+ flush_buffer! if @buffer.bytesize > @config[:max_buffer_size]
67
67
  end
68
68
 
69
69
  def flush_buffer!
70
- @mutex.synchronize do
71
- @sock.write @buffer.join("\n") unless @buffer.empty?
72
- @buffer.clear
70
+ with_reconnect do
71
+ @mutex.synchronize do
72
+ @sock.write @buffer.string unless @buffer.bytesize.zero?
73
+ @buffer.reset
74
+ end
73
75
  end
74
76
  end
75
77
 
78
+ def reconnect!
79
+ @sock.close if @sock
80
+ @sock = TCPSocket.new @config[:host], @config[:port]
81
+ end
82
+
83
+ def with_reconnect(attempt = 0, &block)
84
+ yield
85
+ rescue Errno::EPIPE
86
+ raise if attempt > 1
87
+ reconnect!
88
+ with_reconnect(attempt+1, &block)
89
+ end
90
+
76
91
  end
77
92
  end
@@ -1,41 +1,37 @@
1
- # encoding: utf-8
1
+ #!/usr/bin/env ruby
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
3
 
3
- ##
4
- # This file is auto-generated. DO NOT EDIT!
5
- #
6
- require 'protobuf/message'
4
+ require 'protocol_buffers'
7
5
 
8
6
  module Appdash
7
+ # forward declarations
8
+ class CollectPacket < ::ProtocolBuffers::Message; end
9
9
 
10
- ##
11
- # Message Classes
12
- #
13
- class CollectPacket < ::Protobuf::Message
14
- class SpanID < ::Protobuf::Message; end
15
- class Annotation < ::Protobuf::Message; end
16
-
17
- end
10
+ class CollectPacket < ::ProtocolBuffers::Message
11
+ # forward declarations
12
+ class SpanID < ::ProtocolBuffers::Message; end
13
+ class Annotation < ::ProtocolBuffers::Message; end
18
14
 
15
+ set_fully_qualified_name "appdash.CollectPacket"
19
16
 
17
+ # nested messages
18
+ class SpanID < ::ProtocolBuffers::Message
19
+ set_fully_qualified_name "appdash.CollectPacket.SpanID"
20
20
 
21
- ##
22
- # Message Fields
23
- #
24
- class CollectPacket
25
- class SpanID
26
21
  required :fixed64, :trace, 2
27
22
  required :fixed64, :span, 3
28
23
  optional :fixed64, :parent, 4
29
24
  end
30
25
 
31
- class Annotation
26
+ class Annotation < ::ProtocolBuffers::Message
27
+ set_fully_qualified_name "appdash.CollectPacket.Annotation"
28
+
32
29
  required :string, :key, 6
33
30
  optional :bytes, :value, 7
34
31
  end
35
32
 
36
- required ::Appdash::CollectPacket::SpanID, :spanid, 1
37
- repeated ::Appdash::CollectPacket::Annotation, :annotation, 5
33
+ required ::Appdash::CollectPacket::SpanID, :spanid, 1, :group => true
34
+ repeated ::Appdash::CollectPacket::Annotation, :annotation, 5, :group => true
38
35
  end
39
36
 
40
37
  end
41
-
@@ -4,7 +4,7 @@ module Appdash
4
4
  module Event
5
5
 
6
6
  # RackServer represents a HTTP event where a client's request was served via Rack.
7
- class RackServer < Appdash::Event::Base
7
+ class RackServer < Base
8
8
 
9
9
  # @param [Rack::Request] req a Rack request object
10
10
  # @param [Rack::Response] resp an optional Rack response object
data/lib/appdash/span.rb CHANGED
@@ -33,7 +33,7 @@ module Appdash
33
33
 
34
34
  # Appends a generic Appdash::Event event
35
35
  def event(evt)
36
- @packets.push Appdash::CollectPacket.encode(evt, @id)
36
+ @packets.push Appdash::CollectPacket.build(evt, @id)
37
37
  @id = @id.child
38
38
  end
39
39
 
data/lib/appdash/wire.rb CHANGED
@@ -1,12 +1,11 @@
1
- require 'protobuf'
2
1
  require 'appdash/collector.pb.rb'
3
2
 
4
3
  module Appdash
5
4
  class CollectPacket
6
5
 
7
- def self.encode(event, id)
6
+ def self.build(event, id)
8
7
  wired = SpanID.new(trace: id.trace, span: id.span, parent: id.parent)
9
- new(spanid: wired, annotation: event.to_a).encode
8
+ new(spanid: wired, annotation: event.to_a)
10
9
  end
11
10
 
12
11
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Appdash::Client do
4
4
 
5
- let(:mock_socket) { double("TCPSocket", shutdown: nil) }
5
+ let(:mock_socket) { double("TCPSocket", close: nil) }
6
6
  before { allow(TCPSocket).to receive(:new).and_return(mock_socket) }
7
7
 
8
8
  it "should collect spans" do
@@ -17,16 +17,17 @@ RSpec.describe Appdash::Client do
17
17
  end
18
18
 
19
19
  it "should support buffering" do
20
- subject = described_class.new(max_buffer_size: 3)
20
+ subject = described_class.new(max_buffer_size: 1000)
21
21
  subject.span do |s|
22
22
  s.message("Message A")
23
23
  s.message("Message B")
24
24
  end
25
25
 
26
26
  expect(mock_socket).to receive(:write) do |raw|
27
- expect(raw.bytesize).to eq(118)
27
+ expect(raw.bytesize).to eq(117)
28
28
  end
29
- subject.shutdown
29
+ subject.close
30
30
  end
31
31
 
32
32
  end
33
+
@@ -24,8 +24,8 @@ RSpec.describe Appdash::Span do
24
24
 
25
25
  expect(mock_client).to receive(:write) do |packets|
26
26
  expect(packets.size).to eq(2)
27
- expect(packets[0].bytesize).to eq(50)
28
- expect(packets[1].bytesize).to eq(65)
27
+ expect(packets[0].annotation.map(&:to_hash)).to eq([{key: "Name", value: "test"}, {key: "_schema:name"}])
28
+ expect(packets[1].annotation.map(&:to_hash)).to eq([{key: "Msg", value: "test message"}, {key: "_schema:msg"}])
29
29
  end
30
30
  expect(subject.flush).to eq(2)
31
31
  end
@@ -2,9 +2,19 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Appdash::CollectPacket do
4
4
 
5
- it "should encode" do
6
- packet = described_class.encode Appdash::Event::Message.new("Hello world!"), Appdash::Span::ID.new
7
- expect(packet.bytesize).to eq(56)
5
+ it "should build" do
6
+ packet = described_class.build Appdash::Event::Message.new("Hello world!"), mock_span_id
7
+ expect(packet).to be_instance_of(described_class)
8
+ expect(packet.to_hash).to eq(
9
+ spanid: {
10
+ trace: 5678,
11
+ span: 1234,
12
+ },
13
+ annotation: [
14
+ {key: "Msg", value: "Hello world!"},
15
+ {key: "_schema:msg"},
16
+ ]
17
+ )
8
18
  end
9
19
 
10
20
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,14 @@ helpers = Module.new do
8
8
  def atoh(annotations)
9
9
  annotations.inject({}) {|h, a| h[a.key] = a.value; h }
10
10
  end
11
+
12
+ def mock_span_id
13
+ id = Appdash::Span::ID.new
14
+ id.instance_variable_set(:@span, 1234)
15
+ id.instance_variable_set(:@trace, 5678)
16
+ id
17
+ end
18
+
11
19
  end
12
20
 
13
21
  RSpec.configure do |c|
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appdash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: protobuf
14
+ name: ruby-protocol-buffers
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -113,6 +113,7 @@ files:
113
113
  - appdash.gemspec
114
114
  - defs/appdash/collector.proto
115
115
  - lib/appdash.rb
116
+ - lib/appdash/buffer.rb
116
117
  - lib/appdash/client.rb
117
118
  - lib/appdash/collector.pb.rb
118
119
  - lib/appdash/event/base.rb
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  version: '0'
156
157
  requirements: []
157
158
  rubyforge_project:
158
- rubygems_version: 2.4.8
159
+ rubygems_version: 2.6.8
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: Appdash client for ruby