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
47525c09
Commit
47525c09
authored
Aug 27, 2020
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use batch sum counter to sum jira imported issues
- Add usage data helper for sum - Use the method for one metric
parent
c4440a96
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
5 deletions
+41
-5
app/models/jira_import_state.rb
app/models/jira_import_state.rb
+0
-4
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+1
-1
lib/gitlab/usage_data_queries.rb
lib/gitlab/usage_data_queries.rb
+6
-0
lib/gitlab/utils/usage_data.rb
lib/gitlab/utils/usage_data.rb
+6
-0
spec/lib/gitlab/usage_data_queries_spec.rb
spec/lib/gitlab/usage_data_queries_spec.rb
+6
-0
spec/lib/gitlab/utils/usage_data_spec.rb
spec/lib/gitlab/utils/usage_data_spec.rb
+22
-0
No files found.
app/models/jira_import_state.rb
View file @
47525c09
...
...
@@ -110,10 +110,6 @@ class JiraImportState < ApplicationRecord
)
end
def
self
.
finished_imports_count
finished
.
sum
(
:imported_issues_count
)
end
def
mark_as_failed
(
error_message
)
sanitized_message
=
Gitlab
::
UrlSanitizer
.
sanitize
(
error_message
)
...
...
lib/gitlab/usage_data.rb
View file @
47525c09
...
...
@@ -428,7 +428,7 @@ module Gitlab
{
jira_imports_total_imported_count:
count
(
finished_jira_imports
),
jira_imports_projects_count:
distinct_count
(
finished_jira_imports
,
:project_id
),
jira_imports_total_imported_issues_count:
alt_usage_data
{
JiraImportState
.
finished_imports_count
}
jira_imports_total_imported_issues_count:
sum
(
JiraImportState
.
finished
,
:imported_issues_count
)
}
# rubocop: enable UsageData/LargeTable
end
...
...
lib/gitlab/usage_data_queries.rb
View file @
47525c09
# frozen_string_literal: true
module
Gitlab
# This class is used by the `gitlab:usage_data:dump_sql` rake tasks to output SQL instead of running it.
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class
UsageDataQueries
<
UsageData
class
<<
self
def
count
(
relation
,
column
=
nil
,
*
rest
)
...
...
@@ -19,6 +21,10 @@ module Gitlab
end
end
def
sum
(
relation
,
column
,
*
rest
)
relation
.
select
(
relation
.
all
.
table
[
column
].
sum
).
to_sql
# rubocop:disable CodeReuse/ActiveRecord
end
private
def
raw_sql
(
relation
,
column
,
distinct
=
nil
)
...
...
lib/gitlab/utils/usage_data.rb
View file @
47525c09
...
...
@@ -59,6 +59,12 @@ module Gitlab
FALLBACK
end
def
sum
(
relation
,
column
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
Gitlab
::
Database
::
BatchCount
.
batch_sum
(
relation
,
column
,
batch_size:
batch_size
,
start:
start
,
finish:
finish
)
rescue
ActiveRecord
::
StatementInvalid
FALLBACK
end
def
alt_usage_data
(
value
=
nil
,
fallback:
FALLBACK
,
&
block
)
if
block_given?
yield
...
...
spec/lib/gitlab/usage_data_queries_spec.rb
View file @
47525c09
...
...
@@ -32,4 +32,10 @@ RSpec.describe Gitlab::UsageDataQueries do
expect
(
redis_usage_data
[
:redis_usage_data_block
]).
to
start_with
(
'#<Proc:'
)
end
end
describe
'.sum'
do
it
'returns the raw SQL'
do
expect
(
described_class
.
sum
(
Issue
,
:weight
)).
to
eq
(
'SELECT SUM("issues"."weight") FROM "issues"'
)
end
end
end
spec/lib/gitlab/utils/usage_data_spec.rb
View file @
47525c09
...
...
@@ -37,6 +37,28 @@ RSpec.describe Gitlab::Utils::UsageData do
end
end
describe
'#sum'
do
let
(
:relation
)
{
double
(
:relation
)
}
it
'returns the count when counting succeeds'
do
allow
(
Gitlab
::
Database
::
BatchCount
)
.
to
receive
(
:batch_sum
)
.
with
(
relation
,
:column
,
batch_size:
100
,
start:
2
,
finish:
3
)
.
and_return
(
1
)
expect
(
described_class
.
sum
(
relation
,
:column
,
batch_size:
100
,
start:
2
,
finish:
3
)).
to
eq
(
1
)
end
it
'returns the fallback value when counting fails'
do
stub_const
(
"Gitlab::Utils::UsageData::FALLBACK"
,
15
)
allow
(
Gitlab
::
Database
::
BatchCount
)
.
to
receive
(
:batch_sum
)
.
and_raise
(
ActiveRecord
::
StatementInvalid
.
new
(
''
))
expect
(
described_class
.
sum
(
relation
,
:column
)).
to
eq
(
15
)
end
end
describe
'#alt_usage_data'
do
it
'returns the fallback when it gets an error'
do
expect
(
described_class
.
alt_usage_data
{
raise
StandardError
}
).
to
eq
(
-
1
)
...
...
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