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
0bcc4399
Commit
0bcc4399
authored
Mar 04, 2020
by
Doug Stull
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests and condition for license scan
- we want to capture the case of license failing for fallback
parent
14f9744f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
16 deletions
+61
-16
ee/lib/ee/gitlab/usage_data.rb
ee/lib/ee/gitlab/usage_data.rb
+23
-10
ee/spec/lib/ee/gitlab/usage_data_spec.rb
ee/spec/lib/ee/gitlab/usage_data_spec.rb
+38
-6
No files found.
ee/lib/ee/gitlab/usage_data.rb
View file @
0bcc4399
...
@@ -6,12 +6,25 @@ module EE
...
@@ -6,12 +6,25 @@ module EE
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
SECURE_PRODUCT_TYPES
=
{
SECURE_PRODUCT_TYPES
=
{
container_scanning: :container_scanning_jobs
,
container_scanning:
{
dast: :dast_jobs
,
name: :container_scanning_jobs
dependency_scanning: :dependency_scanning_jobs
,
},
license_management: :license_management_jobs
,
dast:
{
license_scanning: :license_scanning_jobs
,
name: :dast_jobs
sast: :sast_jobs
},
dependency_scanning:
{
name: :dependency_scanning_jobs
},
license_management:
{
name: :license_management_jobs
},
license_scanning:
{
name: :license_scanning_jobs
,
fallback:
0
},
sast:
{
name: :sast_jobs
}
}.
freeze
}.
freeze
class_methods
do
class_methods
do
...
@@ -108,7 +121,7 @@ module EE
...
@@ -108,7 +121,7 @@ module EE
results
[
"license_management"
]
+=
license_scan_count
results
[
"license_management"
]
+=
license_scan_count
end
end
results
.
each_with_object
({})
{
|
(
key
,
value
),
response
|
response
[
SECURE_PRODUCT_TYPES
[
key
.
to_sym
]]
=
value
}
results
.
each_with_object
({})
{
|
(
key
,
value
),
response
|
response
[
SECURE_PRODUCT_TYPES
[
key
.
to_sym
]
[
:name
]
]
=
value
}
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
@@ -320,8 +333,8 @@ module EE
...
@@ -320,8 +333,8 @@ module EE
user_preferences_group_overview_security_dashboard:
count
(
::
User
.
active
.
group_view_security_dashboard
.
where
(
time_period
))
user_preferences_group_overview_security_dashboard:
count
(
::
User
.
active
.
group_view_security_dashboard
.
where
(
time_period
))
}
}
SECURE_PRODUCT_TYPES
.
each
do
|
secure_type
,
type_with_name
|
SECURE_PRODUCT_TYPES
.
each
do
|
secure_type
,
attribs
|
results
[
"
#{
prefix
}#{
type_with_name
}
"
.
to_sym
]
=
distinct_count
(
::
Ci
::
Build
.
where
(
name:
secure_type
).
where
(
time_period
),
:user_id
)
results
[
"
#{
prefix
}#{
attribs
[
:name
]
}
"
.
to_sym
]
=
distinct_count
(
::
Ci
::
Build
.
where
(
name:
secure_type
).
where
(
time_period
),
:user_id
,
fallback:
attribs
.
fetch
(
:fallback
,
-
1
)
)
end
end
# handle license rename https://gitlab.com/gitlab-org/gitlab/issues/8911
# handle license rename https://gitlab.com/gitlab-org/gitlab/issues/8911
...
...
ee/spec/lib/ee/gitlab/usage_data_spec.rb
View file @
0bcc4399
...
@@ -344,16 +344,48 @@ describe Gitlab::UsageData do
...
@@ -344,16 +344,48 @@ describe Gitlab::UsageData do
end
end
context
'for secure'
do
context
'for secure'
do
let_it_be
(
:user
)
{
create
(
:user
,
group_view: :security_dashboard
)
}
let_it_be
(
:ci_build_container_scanning
)
{
create
(
:ci_build
,
name:
'container_scanning'
,
user:
user
)
}
let_it_be
(
:ci_build_dast
)
{
create
(
:ci_build
,
name:
'dast'
,
user:
user
)
}
let_it_be
(
:ci_build_dependency_scanning
)
{
create
(
:ci_build
,
name:
'dependency_scanning'
,
user:
user
)
}
let_it_be
(
:ci_build_license_management
)
{
create
(
:ci_build
,
name:
'license_management'
,
user:
user
)
}
let_it_be
(
:ci_build_sast
)
{
create
(
:ci_build
,
name:
'sast'
,
user:
user
)
}
it
'includes accurate usage_activity_by_stage data'
do
it
'includes accurate usage_activity_by_stage data'
do
create
(
:user
,
group_view: :security_dashboard
)
expect
(
described_class
.
uncached_data
[
:usage_activity_by_stage_monthly
][
:secure
]).
to
eq
(
user_preferences_group_overview_security_dashboard:
1
,
user_container_scanning_jobs:
1
,
user_dast_jobs:
1
,
user_dependency_scanning_jobs:
1
,
user_license_management_jobs:
1
,
user_sast_jobs:
1
)
end
it
'combines license_scanning into license_management'
do
create
(
:ci_build
,
name:
'license_scanning'
,
user:
user
)
expect
(
described_class
.
uncached_data
[
:usage_activity_by_stage_monthly
][
:secure
]).
to
eq
(
user_preferences_group_overview_security_dashboard:
1
,
user_container_scanning_jobs:
1
,
user_dast_jobs:
1
,
user_dependency_scanning_jobs:
1
,
user_license_management_jobs:
2
,
user_sast_jobs:
1
)
end
it
'has to resort to 0 for counting license scan'
do
allow
(
Gitlab
::
Database
::
BatchCount
).
to
receive
(
:batch_distinct_count
).
and_raise
(
ActiveRecord
::
StatementInvalid
)
allow
(
::
Ci
::
Build
).
to
receive
(
:distinct_count_by
).
and_raise
(
ActiveRecord
::
StatementInvalid
)
expect
(
described_class
.
uncached_data
[
:usage_activity_by_stage_monthly
][
:secure
]).
to
eq
(
expect
(
described_class
.
uncached_data
[
:usage_activity_by_stage_monthly
][
:secure
]).
to
eq
(
user_preferences_group_overview_security_dashboard:
1
,
user_preferences_group_overview_security_dashboard:
1
,
user_container_scanning_jobs:
0
,
user_container_scanning_jobs:
-
1
,
user_dast_jobs:
0
,
user_dast_jobs:
-
1
,
user_dependency_scanning_jobs:
0
,
user_dependency_scanning_jobs:
-
1
,
user_license_management_jobs:
0
,
user_license_management_jobs:
-
1
,
user_sast_jobs:
0
user_sast_jobs:
-
1
)
)
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