Skip to content

Commit 2cabdd4

Browse files
committed
make the ruby work again for a timing check
1 parent bc5a63d commit 2cabdd4

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

previously/00_fastly_to_s3/parse_user_agents.rb

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
#!/usr/bin/env ruby
22
require 'json'
3-
4-
input = ARGF.read.lines
5-
input.shift
6-
input.sort!
7-
input.uniq!
3+
require "zlib"
84

95
agents = {}
106

11-
input.each do |line|
12-
match = line.match(/^"bundler\/(?<bundler>[a-z0-9.]+) rubygems\/(?<rubygems>[a-z0-9.]+) ruby\/(?<ruby>[a-z0-9.]+) \((?<cpu>[^-]+)-(?<vendor>[^-]+)-(?<os>.+)\) command\/(?<command>.*?) (jruby\/(?<jruby>[a-z0-9.]+) )?(options\/(?<options>.+?) )?(ci\/(?<ci>.+) )?[a-f0-9]+( (?<extra>.+))?"$/)
13-
14-
if match.nil?
15-
puts "No match! Line was:\n#{line}"
16-
next
17-
end
18-
19-
info = match.named_captures
20-
options = info.delete("options")
21-
22-
options.split(",").each do |name|
23-
agents["options"] ||= Hash.new(0)
24-
agents["options"][name] += 1
25-
end if options
26-
27-
info.each do |name, value|
28-
next if value.nil?
29-
agents[name] ||= Hash.new(0)
30-
agents[name][value] += 1
7+
Zlib::GzipReader.open(ARGV.first) do |file|
8+
file.each_line do |line|
9+
data = JSON.parse(line)
10+
match = data["user_agent"].match(/^bundler\/(?<bundler>[a-z0-9.]+) rubygems\/(?<rubygems>[a-z0-9.]+) ruby\/(?<ruby>[a-z0-9.]+) \((?<cpu>[^-]+)-(?<vendor>[^-]+)-(?<os>.+)\) command\/(?<command>.*?) (jruby\/(?<jruby>[a-z0-9.]+) )?(options\/(?<options>.+?) )?(ci\/(?<ci>.+) )?[a-f0-9]+( (?<extra>.+))?$/)
11+
12+
if match.nil?
13+
# puts "No match! Line was:\n#{line}"
14+
next
15+
end
16+
17+
info = match.named_captures
18+
options = info.delete("options")
19+
20+
options.split(",").each do |name|
21+
agents["options"] ||= Hash.new(0)
22+
agents["options"][name] += 1
23+
end if options
24+
25+
info.each do |name, value|
26+
next if value.nil?
27+
agents[name] ||= Hash.new(0)
28+
agents[name][value] += 1
29+
end
3130
end
3231
end
3332

0 commit comments

Comments
 (0)