Commit 4ee15af6 authored by Sean McGivern's avatar Sean McGivern

Fix Sidekiq reporting to Sentry outside of job contexts

We have a module that processes Sidekiq job data before sending it to
Sentry. However, if Sentry is enabled (which means we'll use this class)
and Sidekiq encountered an error outside of a job's context, the
processor itself could break, which is extra-bad: we won't get anything
in Sentry and we actually have two problems.

Sidekiq will still log something like this:

    !!! ERROR HANDLER THREW AN ERROR !!!

But we shouldn't permit that to happen.

The motivating example for this case was having the Sidekiq metrics
server unable to bind to its port because something else was already
using this. By default it uses port 8082 so running this script will
bind to that port and prevent Sidekiq from using it:

    #!/usr/bin/env ruby

    require 'webrick'

    server = WEBrick::HTTPServer.new(BindAddress: "0.0.0.0",
                                     Port: 8082,
                                     DocumentRoot: ".")

    trap("INT") { server.shutdown }

    server.start

Changelog: fixed
parent f3b505ae
......@@ -53,6 +53,8 @@ module Gitlab
# 'args' in :job => from default error handler
job_holder = sidekiq.key?('args') ? sidekiq : sidekiq[:job]
return event unless job_holder
if job_holder['args']
job_holder['args'] = filter_arguments(job_holder['args'], job_holder['class']).to_a
end
......
......@@ -178,5 +178,14 @@ RSpec.describe Gitlab::ErrorTracking::Processor::SidekiqProcessor do
expect(result_hash.dig(:extra, :sidekiq)).to be_nil
end
end
context 'when there is Sidekiq data but no job' do
let(:value) { { other: 'foo' } }
let(:wrapped_value) { { extra: { sidekiq: value } } }
it 'does nothing' do
expect(result_hash.dig(:extra, :sidekiq)).to eq(value)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment