Commit 58eceb86 authored by Kamil Trzciński's avatar Kamil Trzciński

Allow sidekiq_exporter to fail on address in use

The https://gitlab.com/gitlab-org/gitlab/merge_requests/18575
make the exporters to fail hard, where previously it was allowed
to fail softly.

This retains the previous behavior and properly validates that
this is allowed.

This is needed due to lack of mechanism to support shared port
binding when running sidekiq-cluster mode.
parent a7c66cac
......@@ -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