raindrops 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/GIT-VERSION-GEN CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.9.0.GIT
4
+ DEF_VER=v0.10.0.GIT
5
5
 
6
6
  LF='
7
7
  '
@@ -8,6 +8,8 @@
8
8
  # Instead of snapshotting, Raindrops::Aggregate::LastDataRecv may be used
9
9
  # to aggregate statistics from +all+ accepted sockets as they arrive
10
10
  # based on the +last_data_recv+ field in Raindrops::TCP_Info
11
+ require 'pathname'
12
+
11
13
  module Raindrops::Linux
12
14
 
13
15
  # The standard proc path for active UNIX domain sockets, feel free to call
@@ -42,18 +44,30 @@ module Raindrops::Linux
42
44
  paths = paths.map do |path|
43
45
  path = path.dup
44
46
  path.force_encoding(Encoding::BINARY) if defined?(Encoding)
45
- rv[path]
47
+ if File.symlink?(path)
48
+ link = path
49
+ path = Pathname.new(link).realpath.to_s
50
+ rv[link] = rv[path] # vivify ListenerStats
51
+ else
52
+ rv[path] # vivify ListenerStats
53
+ end
46
54
  Regexp.escape(path)
47
55
  end
48
56
  end
49
- paths = /^\w+: \d+ \d+ 00000000 \d+ (\d+)\s+\d+ (#{paths.join('|')})$/n
57
+ paths = /^\w+: \d+ \d+ (\d+) \d+ (\d+)\s+\d+ (#{paths.join('|')})$/n
50
58
 
51
59
  # no point in pread since we can't stat for size on this file
52
60
  File.read(*PROC_NET_UNIX_ARGS).scan(paths) do |s|
53
61
  path = s[-1]
54
- case s[0].to_i
55
- when 2 then rv[path].queued += 1
56
- when 3 then rv[path].active += 1
62
+ case s[0]
63
+ when "00000000" # client sockets
64
+ case s[1].to_i
65
+ when 2 then rv[path].queued += 1
66
+ when 3 then rv[path].active += 1
67
+ end
68
+ else
69
+ # listeners, vivify empty stats
70
+ rv[path]
57
71
  end
58
72
  end
59
73
 
@@ -35,6 +35,6 @@ class Raindrops::Middleware::Proxy
35
35
  # Avoid breaking users of non-standard extensions (e.g. #body)
36
36
  # Rack::BodyProxy does the same.
37
37
  def method_missing(*args, &block)
38
- @body.send(*args, &block)
38
+ @body.__send__(*args, &block)
39
39
  end
40
40
  end
@@ -143,8 +143,12 @@ class Raindrops::Watcher
143
143
  def call(env)
144
144
  @start.synchronize { @thr ||= aggregator_thread(env["rack.logger"]) }
145
145
  case env["REQUEST_METHOD"]
146
- when "HEAD", "GET"
146
+ when "GET"
147
147
  get env
148
+ when "HEAD"
149
+ r = get(env)
150
+ r[2] = []
151
+ r
148
152
  when "POST"
149
153
  post env
150
154
  else
@@ -337,7 +341,9 @@ class Raindrops::Watcher
337
341
  "<table><tr>" \
338
342
  "<th>address</th><th>active</th><th>queued</th><th>reset</th>" \
339
343
  "</tr>" <<
340
- all.map do |addr,stats|
344
+ all.sort do |a,b|
345
+ a[0] <=> b[0] # sort by addr
346
+ end.map do |addr,stats|
341
347
  e_addr = escape addr
342
348
  "<tr>" \
343
349
  "<td><a href='/tail/#{e_addr}.txt' " \
data/test/test_linux.rb CHANGED
@@ -67,6 +67,45 @@ class TestLinux < Test::Unit::TestCase
67
67
  assert_equal 1, stats[tmp.path].queued
68
68
  end
69
69
 
70
+ def test_unix_all_unused
71
+ tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
72
+ File.unlink(tmp.path)
73
+ us = UNIXServer.new(tmp.path)
74
+ stats = unix_listener_stats
75
+ assert stats.keys.include?(tmp.path), stats.inspect
76
+
77
+ assert_equal 0, stats[tmp.path].active
78
+ assert_equal 0, stats[tmp.path].queued
79
+ end
80
+
81
+ def test_unix_resolves_symlinks
82
+ tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
83
+ File.unlink(tmp.path)
84
+ us = UNIXServer.new(tmp.path)
85
+
86
+ # Create a symlink
87
+ link = Tempfile.new("somethingelse")
88
+ File.unlink(link.path) # We need an available name, not an actual file
89
+ File.symlink(tmp.path, link.path)
90
+
91
+ @to_close << UNIXSocket.new(tmp.path)
92
+ stats = unix_listener_stats
93
+ assert_equal 0, stats[tmp.path].active
94
+ assert_equal 1, stats[tmp.path].queued
95
+
96
+ @to_close << UNIXSocket.new(link.path)
97
+ stats = unix_listener_stats([link.path])
98
+ assert_equal 0, stats[link.path].active
99
+ assert_equal 2, stats[link.path].queued
100
+
101
+ assert_equal stats[link.path].object_id, stats[tmp.path].object_id
102
+
103
+ @to_close << us.accept
104
+ stats = unix_listener_stats
105
+ assert_equal 1, stats[tmp.path].active
106
+ assert_equal 1, stats[tmp.path].queued
107
+ end
108
+
70
109
  def test_tcp
71
110
  s = TCPServer.new(TEST_ADDR, 0)
72
111
  port = s.addr[1]
data/test/test_watcher.rb CHANGED
@@ -156,6 +156,7 @@ class TestWatcher < Test::Unit::TestCase
156
156
  @ios << @srv.accept
157
157
  assert_raises(Errno::EAGAIN) { @srv.accept_nonblock }
158
158
  sleep 0.1
159
+ env = @req.class.env_for "/queued/#@addr.txt"
159
160
  status, headers, body = @app.call(env.dup)
160
161
  assert headers["X-Last-Peak-At"], headers.inspect
161
162
  assert_nothing_raised { Time.parse(headers["X-Last-Peak-At"]) }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raindrops
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 9
8
+ - 10
9
9
  - 0
10
- version: 0.9.0
10
+ version: 0.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - raindrops hackers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-21 00:00:00 Z
18
+ date: 2012-06-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bundler