Commit 4cbfaa06 authored by nmilojevic1's avatar nmilojevic1

Move measurement to service layer

- Fix specs
- Add to ExportService
- Fix rake tasks
parent d3c9c616
......@@ -10,8 +10,13 @@ module Projects
@shared = project.import_export_shared
save_all!
execute_after_export_action(after_export_strategy)
measurement_enabled = !!options[:measurement_enabled]
measurement_logger = options[:measurement_logger]
::Gitlab::Utils::Measuring.execute_with(measurement_enabled, measurement_logger, base_data) do
save_all!
execute_after_export_action(after_export_strategy)
end
ensure
cleanup
end
......@@ -20,6 +25,15 @@ module Projects
attr_accessor :shared
def base_data
{
class: self.class.name,
current_user: current_user.name,
project_full_path: project.full_path,
file_path: @shared.export_path
}
end
def execute_after_export_action(after_export_strategy)
return unless after_export_strategy
......
......@@ -16,7 +16,7 @@ module Gitlab
with_export do
::Projects::ImportExport::ExportService.new(project, current_user)
.execute(Gitlab::ImportExport::AfterExportStrategies::MoveFileStrategy.new(archive_path: file_path))
.execute(Gitlab::ImportExport::AfterExportStrategies::MoveFileStrategy.new(archive_path: file_path), measurement_options)
end
success('Done!')
......@@ -33,7 +33,7 @@ module Gitlab
def with_export
with_request_store do
::Gitlab::GitalyClient.allow_n_plus_1_calls do
measurement_enabled? ? measurement.with_measuring { yield } : yield
yield
end
end
end
......
......@@ -177,5 +177,56 @@ describe Projects::ImportExport::ExportService do
expect { service.execute }.to raise_error(Gitlab::ImportExport::Error).with_message(expected_message)
end
end
context 'when measurable params are provided' do
let(:base_data) do
{
class: described_class.name,
current_user: user.name,
project_full_path: project.full_path,
file_path: shared.export_path
}
end
subject(:service) { described_class.new(project, user) }
context 'when measurement is enabled' do
let(:logger) { double(:logger) }
let(:measurable_options) do
{
measurement_enabled: true,
measurement_logger: logger
}
end
before do
allow(logger).to receive(:info)
end
it 'measure service execution with Gitlab::Utils::Measuring' do
expect(Gitlab::Utils::Measuring).to receive(:execute_with).with(true, logger, base_data).and_call_original
expect_next_instance_of(Gitlab::Utils::Measuring) do |measuring|
expect(measuring).to receive(:with_measuring).and_call_original
end
service.execute(after_export_strategy, measurable_options)
end
end
context 'when measurement is disabled' do
let(:measurable_options) do
{
measurement_enabled: false
}
end
it 'does not measure service execution' do
expect(Gitlab::Utils::Measuring).to receive(:execute_with).with(false, nil, base_data).and_call_original
expect(Gitlab::Utils::Measuring).not_to receive(:new)
service.execute(after_export_strategy, measurable_options)
end
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