mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- try to make monkeypatching more obvious and contained
- add locales/en.yml to the jar builds - don't bother doing 'jar i' anymore, JRuby doesn't even look at the manifest index. Just wastes time during the build :)
This commit is contained in:
parent
4caeefc26f
commit
f5e6e04960
6 changed files with 107 additions and 35 deletions
2
Makefile
2
Makefile
|
@ -74,6 +74,7 @@ copy-ruby-files: | build/ruby
|
|||
@# Copy lib/ and test/ files to the root
|
||||
$(QUIET)rsync -av --include "*/" --include "*.rb" --exclude "*" ./lib/ ./test/ ./build/ruby
|
||||
$(QUIET)rsync -av ./spec ./build/ruby
|
||||
$(QUIET)rsync -av ./locales ./build/ruby
|
||||
@# Delete any empty directories copied by rsync.
|
||||
$(QUIET)find ./build/ruby -type d -empty -delete
|
||||
|
||||
|
@ -231,7 +232,6 @@ build/jar: | build build/flatgems build/monolith
|
|||
build/logstash-$(VERSION)-flatjar.jar: | build/jar
|
||||
$(QUIET)rm -f $@
|
||||
$(QUIET)jar cfe $@ logstash.runner -C build/jar .
|
||||
$(QUIET)jar i $@
|
||||
@echo "Created $@"
|
||||
|
||||
update-jar: copy-ruby-files compile build/ruby/logstash/runner.class
|
||||
|
|
21
lib/logstash/JRUBY-6970-openssl.rb
Normal file
21
lib/logstash/JRUBY-6970-openssl.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# TODO(sissel): require "openssl" takes *ages* from the logstash jar
|
||||
# TODO(sissel): monkeypatch Kernel.require to apply this monkeypatch only after
|
||||
# a 'require "openssl" has occurred.
|
||||
class OpenSSL::SSL::SSLContext
|
||||
alias_method :ca_path_JRUBY_6970=, :ca_path=
|
||||
alias_method :ca_file_JRUBY_6970=, :ca_file=
|
||||
|
||||
def ca_file=(arg)
|
||||
if arg =~ /^jar:file:\//
|
||||
return ca_file_JRUBY_6970=(arg.gsub(/^jar:/, ""))
|
||||
end
|
||||
return ca_file_JRUBY_6970=(arg)
|
||||
end
|
||||
|
||||
def ca_path=(arg)
|
||||
if arg =~ /^jar:file:\//
|
||||
return ca_path_JRUBY_6970=(arg.gsub(/^jar:/, ""))
|
||||
end
|
||||
return ca_path_JRUBY_6970=(arg)
|
||||
end
|
||||
end
|
|
@ -10,27 +10,13 @@ module Kernel
|
|||
|
||||
# JRUBY-7065
|
||||
path = File.expand_path(path) if path.include?("/../")
|
||||
return require_JRUBY_6970_hack(path)
|
||||
end
|
||||
end
|
||||
rc = require_JRUBY_6970_hack(path)
|
||||
|
||||
require "openssl"
|
||||
class OpenSSL::SSL::SSLContext
|
||||
alias_method :ca_path_JRUBY_6970=, :ca_path=
|
||||
alias_method :ca_file_JRUBY_6970=, :ca_file=
|
||||
|
||||
def ca_file=(arg)
|
||||
if arg =~ /^jar:file:\//
|
||||
return ca_file_JRUBY_6970=(arg.gsub(/^jar:/, ""))
|
||||
# Only monkeypatch openssl after it's been loaded.
|
||||
if path == "openssl"
|
||||
require "logstash/JRUBY-6970-openssl"
|
||||
end
|
||||
return ca_file_JRUBY_6970=(arg)
|
||||
end
|
||||
|
||||
def ca_path=(arg)
|
||||
if arg =~ /^jar:file:\//
|
||||
return ca_path_JRUBY_6970=(arg.gsub(/^jar:/, ""))
|
||||
end
|
||||
return ca_path_JRUBY_6970=(arg)
|
||||
return rc
|
||||
end
|
||||
end
|
||||
|
||||
|
|
1
lib/logstash/monkeypatches-for-bugs.rb
Normal file
1
lib/logstash/monkeypatches-for-bugs.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require "logstash/JRUBY-6970"
|
63
lib/logstash/monkeypatches-for-performance.rb
Normal file
63
lib/logstash/monkeypatches-for-performance.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
class << File
|
||||
# mpp == monkey patch for performance
|
||||
alias_method :mpp_file?, :file?
|
||||
alias_method :mpp_exist?, :exist?
|
||||
alias_method :mpp_exists?, :exists?
|
||||
|
||||
JAR_RE = /^(?:jar:)?file:(\/.*\.jar)!(\/.*$)/
|
||||
def file?(path)
|
||||
#return mpp_file?(path)
|
||||
# If path is in a jar (file://blah/foo.jar!/some/path)
|
||||
# - create a cache for this jar of all files
|
||||
# - return cached results only
|
||||
if RUBY_PLATFORM == "java"
|
||||
m = JAR_RE.match(path)
|
||||
return mpp_file?(path) if !m # not a jar file
|
||||
c = __zipcache(m[1], m[2]) # m[1] == the jar path
|
||||
# ZipEntry has only 'isDirectory()' so I assume any
|
||||
# non-directories are files.
|
||||
rc = (!c.nil? && !c.isDirectory)
|
||||
#p path => rc
|
||||
return rc
|
||||
end
|
||||
return mpp_file?(path)
|
||||
end
|
||||
|
||||
def exist?(path)
|
||||
#return mpp_exist?(path)
|
||||
# If path is in a jar (file://blah/foo.jar!/some/path)
|
||||
# - create a cache for this jar of all files
|
||||
# - return cached results only
|
||||
if RUBY_PLATFORM == "java"
|
||||
m = JAR_RE.match(path)
|
||||
return mpp_file?(path) if !m # not a jar file
|
||||
c = __zipcache(m[1], m[2]) # m[1] == the jar path
|
||||
return !c.nil?
|
||||
end
|
||||
return mpp_file?(path)
|
||||
end
|
||||
|
||||
def exists?(path)
|
||||
return exist?(path)
|
||||
end
|
||||
|
||||
def __zipcache(jarpath, path)
|
||||
@jarcache ||= Hash.new { |h,k| h[k] = {} }
|
||||
|
||||
if @jarcache[jarpath].empty?
|
||||
puts "Caching file entries for #{jarpath}"
|
||||
s = Time.now
|
||||
zip = java.util.zip.ZipFile.new(jarpath)
|
||||
zip.entries.each do |entry|
|
||||
#puts "Caching file entries for #{jarpath}: /#{entry.name}"
|
||||
# Prefix entry name with "/" because that's what the jar path looks
|
||||
# like in jruby: file://some.jar!/some/path
|
||||
@jarcache[jarpath]["/" + entry.name] = entry
|
||||
end
|
||||
end
|
||||
|
||||
entry = @jarcache[jarpath][path]
|
||||
#puts "Serving cached file info #{path}: #{entry}"
|
||||
return entry
|
||||
end
|
||||
end
|
|
@ -1,15 +1,7 @@
|
|||
require "logstash/namespace"
|
||||
require "logstash/program"
|
||||
require "logstash/util"
|
||||
require "logstash/JRUBY-6970"
|
||||
require "stud/trap"
|
||||
|
||||
require "i18n" # gem 'i18n'
|
||||
I18n.load_path << File.expand_path(
|
||||
File.join(File.dirname(__FILE__), "../../locales/en.yml")
|
||||
)
|
||||
|
||||
if ENV["PROFILE_BAD_LOG_CALLS"]
|
||||
$START = Time.now
|
||||
$DEBUGLIST = (ENV["DEBUG"] || "").split(",")
|
||||
if ENV["PROFILE_BAD_LOG_CALLS"] || $DEBUGLIST.include?("log")
|
||||
# Set PROFILE_BAD_LOG_CALLS=1 in your environment if you want
|
||||
# to track down logger calls that cause performance problems
|
||||
#
|
||||
|
@ -44,24 +36,33 @@ if ENV["PROFILE_BAD_LOG_CALLS"]
|
|||
end
|
||||
end
|
||||
|
||||
require "logstash/monkeypatches-for-performance"
|
||||
require "logstash/monkeypatches-for-bugs"
|
||||
require "logstash/namespace"
|
||||
require "logstash/program"
|
||||
require "i18n" # gem 'i18n'
|
||||
I18n.load_path << File.expand_path(
|
||||
File.join(File.dirname(__FILE__), "../../locales/en.yml")
|
||||
)
|
||||
|
||||
class LogStash::Runner
|
||||
include LogStash::Program
|
||||
|
||||
def main(args)
|
||||
require "logstash/util"
|
||||
require "stud/trap"
|
||||
@startup_interruption_trap = Stud::trap("INT") { puts "Interrupted"; exit 0 }
|
||||
|
||||
LogStash::Util::set_thread_name(self.class.name)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
|
||||
if args.empty?
|
||||
$stderr.puts "No arguments given."
|
||||
exit(1)
|
||||
return 1
|
||||
end
|
||||
|
||||
if RUBY_VERSION < "1.9.2"
|
||||
$stderr.puts "Ruby 1.9.2 or later is required. (You are running: " + RUBY_VERSION + ")"
|
||||
$stderr.puts "Options for fixing this: "
|
||||
$stderr.puts " * If doing 'ruby bin/logstash ...' add --1.9 flag to 'ruby'"
|
||||
$stderr.puts " * If doing 'java -jar ... ' add -Djruby.compat.version=RUBY1_9 to java flags"
|
||||
return 1
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue