Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4cbfaa06
Commit
4cbfaa06
authored
Apr 21, 2020
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move measurement to service layer
- Fix specs - Add to ExportService - Fix rake tasks
parent
d3c9c616
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
4 deletions
+69
-4
app/services/projects/import_export/export_service.rb
app/services/projects/import_export/export_service.rb
+16
-2
lib/gitlab/import_export/project/export_task.rb
lib/gitlab/import_export/project/export_task.rb
+2
-2
spec/services/projects/import_export/export_service_spec.rb
spec/services/projects/import_export/export_service_spec.rb
+51
-0
No files found.
app/services/projects/import_export/export_service.rb
View file @
4cbfaa06
...
...
@@ -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
...
...
lib/gitlab/import_export/project/export_task.rb
View file @
4cbfaa06
...
...
@@ -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
...
...
spec/services/projects/import_export/export_service_spec.rb
View file @
4cbfaa06
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment