Commit a80f8584 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'allow-address-in-use-for-sidekiq-exporter' into 'master'

Allow sidekiq_exporter to fail on address in use

Closes gitlab-com/gl-infra/infrastructure#8194

See merge request gitlab-org/gitlab!18725
parents 01095e34 58eceb86
......@@ -14,6 +14,29 @@ module Gitlab
def log_filename
File.join(Rails.root, 'log', 'sidekiq_exporter.log')
end
private
# Sidekiq Exporter does not work properly in sidekiq-cluster
# mode. It tries to start the service on the same port for
# each of the cluster workers, this results in failure
# due to duplicate binding.
#
# For now we ignore this error, as metrics are still "kind of"
# valid as they are rendered from shared directory.
#
# Issue: https://gitlab.com/gitlab-org/gitlab/issues/5714
def start_working
super
rescue Errno::EADDRINUSE => e
Sidekiq.logger.error(
class: self.class.to_s,
message: 'Cannot start sidekiq_exporter',
exception: e.message
)
false
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Metrics::Exporter::SidekiqExporter do
let(:exporter) { described_class.new }
after do
exporter.stop
end
context 'with valid config' do
before do
stub_config(
monitoring: {
sidekiq_exporter: {
enabled: true,
port: 0,
address: '127.0.0.1'
}
}
)
end
it 'does start thread' do
expect(exporter.start).not_to be_nil
end
end
context 'when port is already taken' do
let(:first_exporter) { described_class.new }
before do
stub_config(
monitoring: {
sidekiq_exporter: {
enabled: true,
port: 9992,
address: '127.0.0.1'
}
}
)
first_exporter.start
end
after do
first_exporter.stop
end
it 'does print error message' do
expect(Sidekiq.logger).to receive(:error)
.with(
class: described_class.to_s,
message: 'Cannot start sidekiq_exporter',
exception: anything)
exporter.start
end
it 'does not start thread' do
expect(exporter.start).to be_nil
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