Class: HttpLoader::CliArgs::ClientParser

Inherits:
Object
  • Object
show all
Defined in:
lib/http_loader/cli_args.rb

Overview

ClientParser configures OptionParser mapping specifically for Client configurations

Class Method Summary collapse

Class Method Details

.parse(opts, options) ⇒ Object



11
12
13
14
15
# File 'lib/http_loader/cli_args.rb', line 11

def self.parse(opts, options)
  parse_core(opts, options)
  parse_ping(opts, options)
  parse_timeouts(opts, options)
end

.parse_advanced(opts, options) ⇒ Object



36
37
38
39
40
41
# File 'lib/http_loader/cli_args.rb', line 36

def self.parse_advanced(opts, options)
  opts.on('--reopen_closed_connections', 'Reopen') { options[:reopen_closed_connections] = true }
  opts.on('--reopen_interval=S', Float, 'Reopen delay') { |v| options[:reopen_interval] = v }
  opts.on('--read_timeout=S', Float, 'Read timeout') { |v| options[:read_timeout] = v }
  parse_tracking(opts, options)
end

.parse_core(opts, options) ⇒ Object



17
18
19
20
21
22
# File 'lib/http_loader/cli_args.rb', line 17

def self.parse_core(opts, options)
  opts.on('--connections_count=COUNT', Integer, 'Total') { |v| options[:connections] = v }
  opts.on('--https', 'Use HTTPS natively') { options[:use_https] = true }
  opts.on('--url=URL', String, 'URLs') { |v| options[:target_urls] = v.split(',') }
  opts.on('--verbose', 'Verbose logging') { options[:verbose] = true }
end

.parse_endpoints(opts, options) ⇒ Object



50
51
52
53
54
55
# File 'lib/http_loader/cli_args.rb', line 50

def self.parse_endpoints(opts, options)
  opts.on('--ramp_up=S', Float, 'Smoothly scale') { |val| options[:ramp_up] = val }
  opts.on('--bind_ips=IPS', String, 'IPs') { |val| options[:bind_ips] = val.split(',') }
  opts.on('--proxy_pool=U', String, 'URI pool') { |val| options[:proxy_pool] = val.split(',') }
  parse_slowloris(opts, options)
end

.parse_ping(opts, options) ⇒ Object



24
25
26
27
# File 'lib/http_loader/cli_args.rb', line 24

def self.parse_ping(opts, options)
  opts.on('--[no-]ping', 'Ping') { |v| options[:ping] = v }
  opts.on('--ping_period=SECONDS', Integer, 'Ping period') { |v| options[:ping_period] = v }
end

.parse_slowloris(opts, options) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/http_loader/cli_args.rb', line 57

def self.parse_slowloris(opts, options)
  opts.on('--qps_per_connection=R', Integer, 'Active QPS') { |val| options[:qps_per_connection] = val }
  opts.on('--headers=LIST', String, 'Headers') do |val|
    val.split(',').each do |pair|
      key, value = pair.split(':', 2)
      options[:headers][key.strip] = value.strip if key && value
    end
  end
  parse_slowloris_delays(opts, options)
end

.parse_slowloris_delays(opts, options) ⇒ Object



68
69
70
71
72
# File 'lib/http_loader/cli_args.rb', line 68

def self.parse_slowloris_delays(opts, options)
  opts.on('--slowloris_delay=S', Float, 'Gap') { |v| options[:slowloris_delay] = v }
  opts.on('--export_json=FILE', String) { nil }
  opts.on('--target_duration=S', Float) { nil }
end

.parse_timeouts(opts, options) ⇒ Object



29
30
31
32
33
34
# File 'lib/http_loader/cli_args.rb', line 29

def self.parse_timeouts(opts, options)
  opts.on('--http_loader_timeout=S', Float, 'Keep') { |v| options[:http_loader_timeout] = v }
  opts.on('--connections_per_second=R', Integer, 'Rate') { |v| options[:connections_per_second] = v }
  opts.on('--max_concurrent_connections=C', Integer, 'Max') { |v| options[:max_concurrent_connections] = v }
  parse_advanced(opts, options)
end

.parse_tracking(opts, options) ⇒ Object



43
44
45
46
47
48
# File 'lib/http_loader/cli_args.rb', line 43

def self.parse_tracking(opts, options)
  opts.on('--user_agent=A', String, 'User Agent') { |v| options[:user_agent] = v }
  opts.on('--jitter=F', Float, 'Randomize sleep') { |v| options[:jitter] = v }
  opts.on('--track_status_codes', 'Track HTTP codes') { options[:track_status_codes] = true }
  parse_endpoints(opts, options)
end