Skip to content

Commit

Permalink
Remove instrumentation
Browse files Browse the repository at this point in the history
Previously we used logplex to collect production performance statistics. It worked like this. We collect the stats, then stream them to a logplex app endpoint using l2met format. A logplex drain read from the data, serialized it into a Postgres database where we later wrote custom dashboards via SQL queries to find places to optimize.

That setup was ad-hoc. After we did the immediate perf work we decommissioned the drain and the Postgres database. We didn't remove the logplex integration or the instrumentation partially because we didn't know if we would need to do another round of performance analysis and partially because it was believed not removing it was "safer" (when this happened there were far fewer tests on the buildpack and developing on it was a far riskier endeavor).

We haven't used this in years and are in the process of re-writing the Ruby buildpack. Any future instrumentation and performance analysis will be done away from this codebase. We can safely remove the instrumentation, lpxc (used to send logs to the endpoint), dontenv (used to source the environment variable for logplex), and the logic around preserving and copying the `.env` file from prior builds.

#GUS-W-8216066
  • Loading branch information
schneems committed Nov 11, 2021
1 parent c7ee419 commit e315d44
Show file tree
Hide file tree
Showing 24 changed files with 711 additions and 1,118 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Main (unreleased)

* Remove instrumentation and LPXC logic (https://github.com/heroku/heroku-buildpack-ruby/pull/1229)

## v232 (11/9/2021)

* Deactivate LXPC (https://github.com/heroku/heroku-buildpack-ruby/pull/1228)
* Deactivate LPXC (https://github.com/heroku/heroku-buildpack-ruby/pull/1228)

## v231 (10/27/2021)

Expand Down
12 changes: 5 additions & 7 deletions bin/support/ruby_build
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ ENV_DIR="#{PLATFORM_DIR}/env"
PLAN=ARGV[3]

begin
LanguagePack::Instrument.trace 'compile', 'app.compile' do
LanguagePack::ShellHelpers.initialize_env(ENV_DIR)
if pack = LanguagePack.detect(ARGV[0], nil, LAYER_DIR)
pack.topic("Compiling #{pack.name}")
pack.log("compile") do
pack.build
end
LanguagePack::ShellHelpers.initialize_env(ENV_DIR)
if pack = LanguagePack.detect(ARGV[0], nil, LAYER_DIR)
pack.topic("Compiling #{pack.name}")
pack.log("compile") do
pack.build
end
end
rescue Exception => e
Expand Down
12 changes: 5 additions & 7 deletions bin/support/ruby_compile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ require "language_pack"
require "language_pack/shell_helpers"

begin
LanguagePack::Instrument.trace 'compile', 'app.compile' do
LanguagePack::ShellHelpers.initialize_env(ARGV[2])
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
pack.topic("Compiling #{pack.name}")
pack.log("compile") do
pack.compile
end
LanguagePack::ShellHelpers.initialize_env(ARGV[2])
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
pack.topic("Compiling #{pack.name}")
pack.log("compile") do
pack.compile
end
end
rescue Exception => e
Expand Down
12 changes: 5 additions & 7 deletions bin/support/ruby_test-compile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ require "language_pack/test"
include LanguagePack::ShellHelpers

begin
LanguagePack::Instrument.trace 'test_compile', 'app.test_compile' do
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
LanguagePack::ShellHelpers.initialize_env(ARGV[2])
pack.topic("Setting up Test for #{pack.name}")
pack.log("test_compile") do
pack.compile
end
if pack = LanguagePack.detect(ARGV[0], ARGV[1])
LanguagePack::ShellHelpers.initialize_env(ARGV[2])
pack.topic("Setting up Test for #{pack.name}")
pack.log("test_compile") do
pack.compile
end
end
rescue Exception => e
Expand Down
5 changes: 0 additions & 5 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ ruby_version = "2.7.4"
[publish.Ignore]
files = ["spec/"]

[[publish.Vendor]]
url = "https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/ruby.tgz"
dir = "."
files = ["./.env"]

[[publish.Vendor]]
url = "https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.7.4.tgz"
dir = "vendor/ruby/heroku-18"
Expand Down
15 changes: 5 additions & 10 deletions lib/language_pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,20 @@ module Helpers
# @param [Array] first argument is a String of the build directory
# @return [LanguagePack] the {LanguagePack} detected
def self.detect(*args)
Instrument.instrument 'detect' do
Dir.chdir(args.first)
Dir.chdir(args.first)

pack = [ NoLockfile, Rails7, Rails6, Rails5, Rails42, Rails41, Rails4, Rails3, Rails2, Rack, Ruby ].detect do |klass|
klass.use?
end

return pack ? pack.new(*args) : nil
pack = [ NoLockfile, Rails7, Rails6, Rails5, Rails42, Rails41, Rails4, Rails3, Rails2, Rack, Ruby ].detect do |klass|
klass.use?
end

return pack ? pack.new(*args) : nil
end
end


$:.unshift File.expand_path("../../vendor", __FILE__)
$:.unshift File.expand_path("..", __FILE__)

require 'dotenv'
require 'language_pack/shell_helpers'
require 'language_pack/instrument'
require "language_pack/helpers/plugin_installer"
require "language_pack/helpers/stale_file_cleaner"
require "language_pack/helpers/rake_runner"
Expand Down
73 changes: 29 additions & 44 deletions lib/language_pack/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require "language_pack/helpers/layer"
require "language_pack/metadata"
require "language_pack/fetcher"
require "language_pack/instrument"

Encoding.default_external = Encoding::UTF_8 if defined?(Encoding)
ENV["BPLOG_PREFIX"] = "buildpack.ruby"
Expand All @@ -28,26 +27,16 @@ class LanguagePack::Base
# @param [String] the path of the build dir
# @param [String] the path of the cache dir this is nil during detect and release
def initialize(build_path, cache_path = nil, layer_dir=nil)
self.class.instrument "base.initialize" do
@build_path = build_path
@stack = ENV.fetch("STACK")
@cache = LanguagePack::Cache.new(cache_path)
@metadata = LanguagePack::Metadata.new(@cache)
@bundler_cache = LanguagePack::BundlerCache.new(@cache, @stack)
@id = Digest::SHA1.hexdigest("#{Time.now.to_f}-#{rand(1000000)}")[0..10]
@fetchers = {:buildpack => LanguagePack::Fetcher.new(VENDOR_URL) }
@layer_dir = layer_dir

Dir.chdir build_path
end
end

def instrument(*args, &block)
self.class.instrument(*args, &block)
end

def self.instrument(*args, &block)
LanguagePack::Instrument.instrument(*args, &block)
@build_path = build_path
@stack = ENV.fetch("STACK")
@cache = LanguagePack::Cache.new(cache_path)
@metadata = LanguagePack::Metadata.new(@cache)
@bundler_cache = LanguagePack::BundlerCache.new(@cache, @stack)
@id = Digest::SHA1.hexdigest("#{Time.now.to_f}-#{rand(1000000)}")[0..10]
@fetchers = {:buildpack => LanguagePack::Fetcher.new(VENDOR_URL) }
@layer_dir = layer_dir

Dir.chdir build_path
end

def self.===(build_path)
Expand Down Expand Up @@ -82,40 +71,36 @@ def default_process_types
# this is called to build the slug
def compile
write_release_yaml
instrument 'base.compile' do
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
puts warning
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
puts warning
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
Kernel.puts ""
mcount "success"
end

def build
write_release_toml
instrument 'base.compile' do
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
puts warning
Kernel.puts ""
warnings.each do |warning|
Kernel.puts "\e[1m\e[33m###### WARNING:\e[0m"# Bold yellow
Kernel.puts ""
puts warning
Kernel.puts ""
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
Kernel.puts ""
end
if deprecations.any?
topic "DEPRECATIONS:"
puts @deprecations.join("\n")
end
Kernel.puts ""
mcount "success"
end

Expand Down
86 changes: 37 additions & 49 deletions lib/language_pack/helpers/bundler_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ def has_gem?(name)
end

def gem_version(name)
instrument "ruby.gem_version" do
if spec = specs[name]
spec.version
end
if spec = specs[name]
spec.version
end
end

Expand Down Expand Up @@ -131,29 +129,23 @@ def dir_name
"bundler-#{version}"
end

def instrument(*args, &block)
LanguagePack::Instrument.instrument(*args, &block)
end

def ruby_version
instrument 'detect_ruby_version' do
env = { "PATH" => "#{bundler_path}/bin:#{ENV['PATH']}",
"RUBYLIB" => File.join(bundler_path, "gems", dir_name, "lib"),
"GEM_PATH" => "#{bundler_path}:#{ENV["GEM_PATH"]}",
"BUNDLE_DISABLE_VERSION_CHECK" => "true"
}
command = "bundle platform --ruby"

# Silently check for ruby version
output = run_stdout(command, user_env: true, env: env).strip.lines.last

# If there's a gem in the Gemfile (i.e. syntax error) emit error
raise GemfileParseError.new(run("bundle check", user_env: true, env: env)) unless $?.success?
if output.match(/No ruby version specified/)
""
else
output.strip.sub('(', '').sub(')', '').sub(/(p-?\d+)/, ' \1').split.join('-')
end
env = { "PATH" => "#{bundler_path}/bin:#{ENV['PATH']}",
"RUBYLIB" => File.join(bundler_path, "gems", dir_name, "lib"),
"GEM_PATH" => "#{bundler_path}:#{ENV["GEM_PATH"]}",
"BUNDLE_DISABLE_VERSION_CHECK" => "true"
}
command = "bundle platform --ruby"

# Silently check for ruby version
output = run_stdout(command, user_env: true, env: env).strip.lines.last

# If there's a gem in the Gemfile (i.e. syntax error) emit error
raise GemfileParseError.new(run("bundle check", user_env: true, env: env)) unless $?.success?
if output.match(/No ruby version specified/)
""
else
output.strip.sub('(', '').sub(')', '').sub(/(p-?\d+)/, ' \1').split.join('-')
end
end

Expand All @@ -178,33 +170,29 @@ def bundler_version_escape_valve!

private
def fetch_bundler
instrument 'fetch_bundler' do
return true if Dir.exists?(bundler_path)

topic("Installing bundler #{@version}")
bundler_version_escape_valve!

# Install directory structure (as of Bundler 2.1.4):
# - cache
# - bin
# - gems
# - specifications
# - build_info
# - extensions
# - doc
FileUtils.mkdir_p(bundler_path)
Dir.chdir(bundler_path) do
@fetcher.fetch_untar(@bundler_tar)
end
Dir["bin/*"].each {|path| `chmod 755 #{path}` }
return true if Dir.exists?(bundler_path)

topic("Installing bundler #{@version}")
bundler_version_escape_valve!

# Install directory structure (as of Bundler 2.1.4):
# - cache
# - bin
# - gems
# - specifications
# - build_info
# - extensions
# - doc
FileUtils.mkdir_p(bundler_path)
Dir.chdir(bundler_path) do
@fetcher.fetch_untar(@bundler_tar)
end
Dir["bin/*"].each {|path| `chmod 755 #{path}` }
end

def parse_gemfile_lock
instrument 'parse_bundle' do
gemfile_contents = File.read(@gemfile_lock_path)
Bundler::LockfileParser.new(gemfile_contents)
end
gemfile_contents = File.read(@gemfile_lock_path)
Bundler::LockfileParser.new(gemfile_contents)
end

def major_bundler_version
Expand Down
12 changes: 3 additions & 9 deletions lib/language_pack/helpers/rake_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,10 @@ def rakefile_can_load?
@rakefile_can_load
end

def instrument(*args, &block)
LanguagePack::Instrument.instrument(*args, &block)
end

def load_rake_tasks(options = {})
instrument "ruby.rake_task_defined" do
@rake_tasks ||= RakeTask.new("-P --trace").invoke(options.merge(quiet: true)).output
@rakefile_can_load ||= $?.success?
@rake_tasks
end
@rake_tasks ||= RakeTask.new("-P --trace").invoke(options.merge(quiet: true)).output
@rakefile_can_load ||= $?.success?
@rake_tasks
end

def load_rake_tasks!(options = {}, raise_on_fail = false)
Expand Down
Loading

0 comments on commit e315d44

Please sign in to comment.