Skip to content
This repository has been archived by the owner on Mar 14, 2018. It is now read-only.

Commit

Permalink
Auto merge of #174 - bundler:aa-rework-errors, r=segiddins
Browse files Browse the repository at this point in the history
Rework error handling for more information and less log spam

None
  • Loading branch information
homu committed Aug 22, 2016
2 parents 7b5d926 + e60d85b commit 72d4928
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 30 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -8,7 +8,6 @@ git_source(:github) do |repo|
"https://github.com/#{repo}.git"
end

gem 'appsignal', '0.11.6.beta.0'
gem 'librato-metrics'
gem 'metriks-librato_metrics', github: 'indirect/metriks-librato_metrics'
gem 'metriks-middleware'
Expand Down
5 changes: 0 additions & 5 deletions Gemfile.lock
Expand Up @@ -15,9 +15,6 @@ GEM
remote: https://rubygems.org/
specs:
aggregate (0.2.2)
appsignal (0.11.6.beta.0)
rack
thread_safe
artifice (0.6)
rack-test
ast (2.2.0)
Expand Down Expand Up @@ -100,15 +97,13 @@ GEM
tilt (>= 1.3, < 3)
slop (3.6.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.2)
unicode-display_width (0.3.1)

PLATFORMS
ruby

DEPENDENCIES
appsignal (= 0.11.6.beta.0)
artifice
compact_index
dalli
Expand Down
8 changes: 2 additions & 6 deletions lib/bundler_api/agent_reporting.rb
Expand Up @@ -55,12 +55,8 @@ def known_id?(id)

BundlerApi.redis.setex(id, 120, true)
false
rescue => ex
# Sometimes we get these, and there's no point throwing out a perfectly
# good metric. We still, however, want to report it in Appsignal so that
# we know what's up.
Appsignal.add_exception(ex) if defined?(Appsignal)

rescue => e
STDERR.puts "[Error][AgentReporting] `known_id?` raised #{e.class}: #{e.message}"
false
end
end
11 changes: 0 additions & 11 deletions lib/bundler_api/appsignal.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/bundler_api/gem_helper.rb
Expand Up @@ -31,6 +31,10 @@ def download_spec
@mutex.synchronize do
@gemspec ||= Marshal.load(Gem.inflate(fetch(url)))
end
rescue => e
raise(e) if e.is_a?(BundlerApi::HTTPError)
STDERR.puts "[Error] Downloading gemspec #{full_name} failed! #{e.class}: #{e.message}"
STDERR.puts e.backtrace.join("\n ")
end

def download_checksum
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler_api/metriks.rb
Expand Up @@ -35,7 +35,7 @@ def source_name(worker = nil)

def error_handler
-> (e) do
STDOUT.puts("[Metriks][Librato] #{e.class} raised during metric submission: #{e.message}")
STDOUT.puts("[Error][Librato] #{e.class} raised during metric submission: #{e.message}")

if e.is_a?(::Metriks::LibratoMetricsReporter::RequestFailedError)
STDOUT.puts(" Response body: #{e.res.body}")
Expand Down
3 changes: 3 additions & 0 deletions lib/bundler_api/update/job.rb
Expand Up @@ -27,7 +27,10 @@ def run
return if @db_helper.exists?(@payload) && !@fix_deps
return if !@db_helper.exists?(@payload) && @fix_deps
log "Adding: #{@payload.full_name}\n"

spec = @payload.download_spec
return unless spec

checksum = @payload.download_checksum unless @fix_deps
@mutex.synchronize do
deps_added = insert_spec(spec, checksum)
Expand Down
10 changes: 4 additions & 6 deletions lib/bundler_api/web.rb
Expand Up @@ -6,7 +6,6 @@
require 'bundler_api/agent_reporting'
require 'bundler_api/checksum'
require 'bundler_api/gem_info'
require 'bundler_api/appsignal'
require 'bundler_api/cache'
require 'bundler_api/metriks'
require 'bundler_api/runtime_instrumentation'
Expand All @@ -22,8 +21,6 @@ class BundlerApi::Web < Sinatra::Base
NEW_INDEX_ENABLED = ENV['NEW_INDEX_DISABLED'].nil?

unless ENV['RACK_ENV'] == 'test'
use Appsignal::Rack::Listener, name: 'bundler-api'
use Appsignal::Rack::SinatraInstrumentation
use Metriks::Middleware
use BundlerApi::AgentReporting
end
Expand Down Expand Up @@ -103,7 +100,7 @@ def json_payload(payload)
content_type 'application/octet-stream'

deps = with_metriks { get_cached_dependencies }
ActiveSupport::Notifications.instrument('marshal.deps') { Marshal.dump(deps) }
Marshal.dump(deps)
end

get "/api/v1/dependencies.json" do
Expand All @@ -115,7 +112,7 @@ def json_payload(payload)
content_type 'application/json;charset=UTF-8'

deps = with_metriks { get_cached_dependencies }
ActiveSupport::Notifications.instrument('json.deps') { deps.to_json }
deps.to_json
end

post "/api/v1/add_spec.json" do
Expand Down Expand Up @@ -277,7 +274,8 @@ def in_background
begin
yield
rescue => e
Appsignal.send_exception(e)
STDOUT.puts "[Error][Web] #{e.class} raised during background task: #{e.message}"
STDERR.puts e.backtrace.join("\n ")
end
end
end
Expand Down

0 comments on commit 72d4928

Please sign in to comment.