Permalink
Browse files

make the ruby work again for a timing check

  • Loading branch information...
indirect committed Oct 25, 2018
1 parent bc5a63d commit 2cabdd4cad0038d1bdbb029bf4ded689cfa4e8c2
Showing with 24 additions and 25 deletions.
  1. +24 −25 previously/00_fastly_to_s3/parse_user_agents.rb
@@ -1,33 +1,32 @@
#!/usr/bin/env ruby
require 'json'

input = ARGF.read.lines
input.shift
input.sort!
input.uniq!
require "zlib"

agents = {}

input.each do |line|
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>.+))?"$/)

if match.nil?
puts "No match! Line was:\n#{line}"
next
end

info = match.named_captures
options = info.delete("options")

options.split(",").each do |name|
agents["options"] ||= Hash.new(0)
agents["options"][name] += 1
end if options

info.each do |name, value|
next if value.nil?
agents[name] ||= Hash.new(0)
agents[name][value] += 1
Zlib::GzipReader.open(ARGV.first) do |file|
file.each_line do |line|
data = JSON.parse(line)
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>.+))?$/)

if match.nil?
# puts "No match! Line was:\n#{line}"
next
end

info = match.named_captures
options = info.delete("options")

options.split(",").each do |name|
agents["options"] ||= Hash.new(0)
agents["options"][name] += 1
end if options

info.each do |name, value|
next if value.nil?
agents[name] ||= Hash.new(0)
agents[name][value] += 1
end
end
end

0 comments on commit 2cabdd4

Please sign in to comment.