blitz 0.1.0 → 0.1.1
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.
- data/blitz.gemspec +2 -1
- data/lib/blitz.rb +3 -1
- data/lib/blitz/command/curl.rb +50 -7
- data/lib/blitz/curl/rush.rb +102 -0
- metadata +4 -3
data/blitz.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{blitz}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["pcapr"]
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/blitz/command/curl.rb",
|
35
35
|
"lib/blitz/command/help.rb",
|
36
36
|
"lib/blitz/curl/error.rb",
|
37
|
+
"lib/blitz/curl/rush.rb",
|
37
38
|
"lib/blitz/curl/sprint.rb",
|
38
39
|
"lib/blitz/helper.rb",
|
39
40
|
"test/helper.rb",
|
data/lib/blitz.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'hexy'
|
3
|
+
require 'pp'
|
3
4
|
|
4
5
|
class Blitz
|
5
6
|
require 'blitz/helper'
|
6
|
-
Version = "0.1.
|
7
|
+
Version = "0.1.1".freeze
|
7
8
|
|
8
9
|
extend Blitz::Helper
|
9
10
|
|
@@ -28,4 +29,5 @@ end
|
|
28
29
|
require 'blitz/client'
|
29
30
|
require 'blitz/curl/error'
|
30
31
|
require 'blitz/curl/sprint'
|
32
|
+
require 'blitz/curl/rush'
|
31
33
|
require 'blitz/command'
|
data/lib/blitz/command/curl.rb
CHANGED
@@ -15,7 +15,7 @@ class Curl < Command
|
|
15
15
|
sprint args
|
16
16
|
return
|
17
17
|
else
|
18
|
-
|
18
|
+
rush args
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -25,19 +25,18 @@ class Curl < Command
|
|
25
25
|
def authorize_error e
|
26
26
|
base_url = "#{e.scheme}://#{e.host}:#{e.port}"
|
27
27
|
puts
|
28
|
-
error "You haven't verified that you are the devops dude for #{e.host}"
|
28
|
+
error "You haven't verified that you are the devops dude for #{e.host}. Make"
|
29
|
+
error "sure the following URL is reachable and returns the string '42'."
|
29
30
|
error ""
|
30
|
-
error "Make sure the following URL is reachable by us and returns the value 42."
|
31
31
|
error "#{base_url}/#{e.uuid}"
|
32
32
|
error ""
|
33
|
-
error "If your app is RESTfully built with sinatra or rails, simply"
|
34
|
-
error "add a route like so:"
|
33
|
+
error "If your app is RESTfully built with sinatra or rails, simply add this route:"
|
35
34
|
error ""
|
36
35
|
error "get '/#{e.uuid}' do"
|
37
36
|
error " '42'"
|
38
37
|
error "end"
|
39
38
|
error ""
|
40
|
-
error "
|
39
|
+
error "Once this is done, you can blitz #{e.host} all you want."
|
41
40
|
puts
|
42
41
|
end
|
43
42
|
|
@@ -101,6 +100,50 @@ class Curl < Command
|
|
101
100
|
end
|
102
101
|
end
|
103
102
|
|
103
|
+
def rush args
|
104
|
+
continue = true
|
105
|
+
begin
|
106
|
+
[ 'INT', 'STOP', 'HUP' ].each do |s|
|
107
|
+
trap(s) { continue = false }
|
108
|
+
end
|
109
|
+
job = ::Blitz::Curl::Rush.execute args
|
110
|
+
msg "rushing from #{job.region}..."
|
111
|
+
job.result do |result|
|
112
|
+
print_rush_result result
|
113
|
+
sleep 1.0 if not continue
|
114
|
+
continue
|
115
|
+
end
|
116
|
+
puts
|
117
|
+
msg "[aborted]" if not continue
|
118
|
+
rescue ::Blitz::Curl::Error::Authorize => e
|
119
|
+
authorize_error e
|
120
|
+
rescue ::Blitz::Curl::Error::Region => e
|
121
|
+
error "#{e.region}: #{e.message}"
|
122
|
+
rescue ::Blitz::Curl::Error => e
|
123
|
+
error e.message
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def print_rush_result result
|
128
|
+
recent = result.timeline[-1]
|
129
|
+
hits = "%u hits" % recent.hits
|
130
|
+
errors = recent.errors ? ", %u errors" % recent.errors : ''
|
131
|
+
timeouts = recent.timeouts ? ", %u timeouts" % recent.timeouts : ''
|
132
|
+
bandwidth = ''
|
133
|
+
if result.timeline.size > 1
|
134
|
+
last = result.timeline[-2]
|
135
|
+
elapsed = recent.timestamp - last.timestamp
|
136
|
+
bps = (recent.rxbytes + recent.txbytes) - (last.rxbytes + last.txbytes)/elapsed
|
137
|
+
bandwidth = " - %.2f bytes/sec" % bps
|
138
|
+
else
|
139
|
+
bps = (recent.rxbytes + recent.txbytes)/recent.timestamp
|
140
|
+
bandwidth = " - %.2f bytes/sec" % bps
|
141
|
+
end
|
142
|
+
duration = recent.duration >= 0 ? " @ %.2f sec" % recent.duration : ''
|
143
|
+
$stdout.print "#{hits}#{errors}#{timeouts}#{bandwidth}#{duration}\n"
|
144
|
+
$stdout.flush
|
145
|
+
end
|
146
|
+
|
104
147
|
def help
|
105
148
|
helps = [
|
106
149
|
{ :short => '-A', :long => '--user-agent', :value => '<string>', :help => 'User-Agent to send to server' },
|
@@ -111,7 +154,7 @@ class Curl < Command
|
|
111
154
|
{ :short => '-h', :long => '--help', :value => '', :help => 'Help on command line options' },
|
112
155
|
{ :short => '-H', :long => '--header', :value => '<string>', :help => 'Custom header to pass to server' },
|
113
156
|
{ :short => '-p', :long => '--pattern', :value => '<s>-<e>:<d>', :help => 'Ramp from s to e concurrent requests in d secs' },
|
114
|
-
{ :short => '-r', :long => '--region', :value => '<string>', :help => '
|
157
|
+
{ :short => '-r', :long => '--region', :value => '<string>', :help => 'california|virginia|singapore|ireland|japan' },
|
115
158
|
{ :short => '-s', :long => '--status', :value => '<number>', :help => 'Assert on the HTTP response status code' },
|
116
159
|
{ :short => '-T', :long => '--timeout', :value => '<ms>', :help => 'Wait time for both connect and responses' },
|
117
160
|
{ :short => '-u', :long => '--user', :value => '<user[:pass]>', :help => 'User and password for authentication' },
|
@@ -0,0 +1,102 @@
|
|
1
|
+
class Blitz
|
2
|
+
module Curl
|
3
|
+
class Rush
|
4
|
+
class Point
|
5
|
+
attr_reader :timestamp
|
6
|
+
attr_reader :duration
|
7
|
+
attr_reader :total
|
8
|
+
attr_reader :hits
|
9
|
+
attr_reader :errors
|
10
|
+
attr_reader :timeouts
|
11
|
+
attr_reader :volume
|
12
|
+
attr_reader :txbytes
|
13
|
+
attr_reader :rxbytes
|
14
|
+
|
15
|
+
def initialize json
|
16
|
+
@timestamp = json['timestamp']
|
17
|
+
@duration = json['duration']
|
18
|
+
@total = json['total']
|
19
|
+
@hits = json['executed']
|
20
|
+
@errors = json['errors']
|
21
|
+
@timeouts = json['timeouts']
|
22
|
+
@volume = json['volume']
|
23
|
+
@txbytes = json['txbytes']
|
24
|
+
@rxbytes = json['rxbytes']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Result
|
29
|
+
attr_reader :region
|
30
|
+
attr_reader :timeline
|
31
|
+
|
32
|
+
def initialize json
|
33
|
+
result = json['result']
|
34
|
+
@region = result['region']
|
35
|
+
@timeline = result['timeline'].map { |p| Point.new p }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.execute args
|
40
|
+
if not args.member? 'pattern'
|
41
|
+
raise ArgumentError, 'missing pattern'
|
42
|
+
end
|
43
|
+
|
44
|
+
res = Command::API.client.curl_execute args
|
45
|
+
raise Error.new(res) if res['error']
|
46
|
+
return self.new res
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_reader :job_id
|
50
|
+
attr_reader :region
|
51
|
+
|
52
|
+
def initialize json
|
53
|
+
@job_id = json['job_id']
|
54
|
+
@region = json['region']
|
55
|
+
end
|
56
|
+
|
57
|
+
def result
|
58
|
+
last = nil
|
59
|
+
while true
|
60
|
+
sleep 2.0
|
61
|
+
|
62
|
+
job = Command::API.client.job_status job_id
|
63
|
+
if job['error']
|
64
|
+
raise Error
|
65
|
+
end
|
66
|
+
|
67
|
+
result = job['result']
|
68
|
+
next if job['status'] == 'queued'
|
69
|
+
next if job['status'] == 'running' and not result
|
70
|
+
|
71
|
+
raise Error if not result
|
72
|
+
|
73
|
+
error = result['error']
|
74
|
+
if error
|
75
|
+
if error == 'dns'
|
76
|
+
raise Error::DNS.new(result)
|
77
|
+
elsif error == 'authorize'
|
78
|
+
raise Error::Authorize.new(result)
|
79
|
+
else
|
80
|
+
raise Error
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
last = Result.new(job)
|
85
|
+
continue = yield last rescue false
|
86
|
+
if not continue
|
87
|
+
abort!
|
88
|
+
break
|
89
|
+
end
|
90
|
+
|
91
|
+
break if job['status'] == 'completed'
|
92
|
+
end
|
93
|
+
|
94
|
+
return last
|
95
|
+
end
|
96
|
+
|
97
|
+
def abort!
|
98
|
+
Command::API.client.abort_job job_id rescue nil
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end # Curl
|
102
|
+
end # Blitz
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blitz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pcapr
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/blitz/command/curl.rb
|
140
140
|
- lib/blitz/command/help.rb
|
141
141
|
- lib/blitz/curl/error.rb
|
142
|
+
- lib/blitz/curl/rush.rb
|
142
143
|
- lib/blitz/curl/sprint.rb
|
143
144
|
- lib/blitz/helper.rb
|
144
145
|
- test/helper.rb
|