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
0618e0b2
Commit
0618e0b2
authored
Oct 01, 2019
by
Alex Buijs
Committed by
Mayra Cabrera
Oct 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add usage statistics data for create stage
Added usage activity data for the create stage
parent
79b9bb18
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
100 additions
and
0 deletions
+100
-0
ee/app/models/ee/key.rb
ee/app/models/ee/key.rb
+2
-0
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+1
-0
ee/app/models/ee/note.rb
ee/app/models/ee/note.rb
+1
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+3
-0
ee/app/models/ee/snippet.rb
ee/app/models/ee/snippet.rb
+1
-0
ee/lib/ee/gitlab/usage_data.rb
ee/lib/ee/gitlab/usage_data.rb
+17
-0
ee/spec/factories/projects.rb
ee/spec/factories/projects.rb
+4
-0
ee/spec/lib/ee/gitlab/usage_data_spec.rb
ee/spec/lib/ee/gitlab/usage_data_spec.rb
+29
-0
ee/spec/models/ee/note_spec.rb
ee/spec/models/ee/note_spec.rb
+12
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+30
-0
No files found.
ee/app/models/ee/key.rb
View file @
0618e0b2
...
...
@@ -5,6 +5,8 @@ module EE
extend
ActiveSupport
::
Concern
prepended
do
include
UsageStatistics
scope
:ldap
,
->
{
where
(
type:
'LDAPKey'
)
}
end
...
...
ee/app/models/ee/merge_request.rb
View file @
0618e0b2
...
...
@@ -13,6 +13,7 @@ module EE
prepended
do
include
Elastic
::
ApplicationVersionedSearch
include
DeprecatedApprovalsBeforeMerge
include
UsageStatistics
has_many
:reviews
,
inverse_of: :merge_request
has_many
:approvals
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
...
...
ee/app/models/ee/note.rb
View file @
0618e0b2
...
...
@@ -14,6 +14,7 @@ module EE
scope
:searchable
,
->
{
where
(
system:
false
).
includes
(
:noteable
)
}
scope
:by_humans
,
->
{
user
.
joins
(
:author
).
merge
(
::
User
.
humans
)
}
scope
:with_suggestions
,
->
{
joins
(
:suggestions
)
}
after_commit
:notify_after_create
,
on: :create
after_commit
:notify_after_destroy
,
on: :destroy
...
...
ee/app/models/ee/project.rb
View file @
0618e0b2
...
...
@@ -112,6 +112,9 @@ module EE
scope
:with_jira_dvcs_cloud
,
->
{
joins
(
:feature_usage
).
merge
(
ProjectFeatureUsage
.
with_jira_dvcs_integration_enabled
(
cloud:
true
))
}
scope
:with_jira_dvcs_server
,
->
{
joins
(
:feature_usage
).
merge
(
ProjectFeatureUsage
.
with_jira_dvcs_integration_enabled
(
cloud:
false
))
}
scope
:service_desk_enabled
,
->
{
where
(
service_desk_enabled:
true
)
}
scope
:github_imported
,
->
{
where
(
import_type:
'github'
)
}
scope
:with_protected_branches
,
->
{
joins
(
:protected_branches
)
}
scope
:with_repositories_enabled
,
->
{
joins
(
:project_feature
).
where
(
project_features:
{
repository_access_level:
::
ProjectFeature
::
ENABLED
})
}
scope
:with_security_reports_stored
,
->
{
where
(
'EXISTS (?)'
,
::
Vulnerabilities
::
Occurrence
.
scoped_project
.
select
(
1
))
}
scope
:with_security_reports
,
->
{
where
(
'EXISTS (?)'
,
::
Ci
::
JobArtifact
.
security_reports
.
scoped_project
.
select
(
1
))
}
...
...
ee/app/models/ee/snippet.rb
View file @
0618e0b2
...
...
@@ -6,6 +6,7 @@ module EE
prepended
do
include
Elastic
::
SnippetsSearch
include
UsageStatistics
end
end
end
ee/lib/ee/gitlab/usage_data.rb
View file @
0618e0b2
...
...
@@ -183,12 +183,29 @@ module EE
def
usage_activity_by_stage
{
usage_activity_by_stage:
{
create:
usage_activity_by_stage_create
,
manage:
usage_activity_by_stage_manage
,
plan:
usage_activity_by_stage_plan
}
}
end
# Omitted because no user, creator or author associated: `lfs_objects`, `pool_repositories`, `web_hooks`
def
usage_activity_by_stage_create
{
deploy_keys:
::
DeployKey
.
distinct_count_by
(
:user_id
),
keys:
::
Key
.
regular_keys
.
distinct_count_by
(
:user_id
),
merge_requests:
::
MergeRequest
.
distinct_count_by
(
:author_id
),
projects_enforcing_code_owner_approval:
::
Project
.
requiring_code_owner_approval
.
distinct_count_by
(
:creator_id
),
projects_imported_from_github:
::
Project
.
github_imported
.
distinct_count_by
(
:creator_id
),
projects_with_repositories_enabled:
::
Project
.
with_repositories_enabled
.
distinct_count_by
(
:creator_id
),
protected_branches:
::
Project
.
with_protected_branches
.
distinct_count_by
(
:creator_id
),
remote_mirrors:
::
Project
.
with_remote_mirrors
.
distinct_count_by
(
:creator_id
),
snippets:
::
Snippet
.
distinct_count_by
(
:author_id
),
suggestions:
::
Note
.
with_suggestions
.
distinct_count_by
(
:author_id
)
}
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
def
usage_activity_by_stage_manage
{
...
...
ee/spec/factories/projects.rb
View file @
0618e0b2
...
...
@@ -81,5 +81,9 @@ FactoryBot.modify do
trait
:service_desk_disabled
do
service_desk_enabled
nil
end
trait
:github_imported
do
import_type
'github'
end
end
end
ee/spec/lib/ee/gitlab/usage_data_spec.rb
View file @
0618e0b2
...
...
@@ -88,6 +88,35 @@ describe Gitlab::UsageData do
)
end
end
context
'for create'
do
it
'includes accurate usage_activity_by_stage data'
do
user
=
create
(
:user
)
project
=
create
(
:project
,
:repository_private
,
:requiring_code_owner_approval
,
:github_imported
,
:test_repo
,
:remote_mirror
,
creator:
user
)
create
(
:deploy_key
,
user:
user
)
create
(
:key
,
user:
user
)
create
(
:merge_request
,
source_project:
project
)
create
(
:project
,
creator:
user
)
create
(
:protected_branch
,
project:
project
)
create
(
:remote_mirror
,
project:
project
)
create
(
:snippet
,
author:
user
)
create
(
:suggestion
,
note:
create
(
:note
,
project:
project
))
expect
(
described_class
.
uncached_data
[
:usage_activity_by_stage
][
:create
]).
to
eq
(
deploy_keys:
1
,
keys:
1
,
merge_requests:
1
,
projects_enforcing_code_owner_approval:
1
,
projects_imported_from_github:
1
,
projects_with_repositories_enabled:
1
,
protected_branches:
1
,
remote_mirrors:
1
,
snippets:
1
,
suggestions:
1
)
end
end
end
end
end
ee/spec/models/ee/note_spec.rb
View file @
0618e0b2
...
...
@@ -9,6 +9,18 @@ describe Note do
it
{
is_expected
.
to
belong_to
(
:review
).
inverse_of
(
:notes
)
}
end
describe
'scopes'
do
describe
'.with_suggestions'
do
it
'returns the correct note'
do
note_with_suggestion
=
create
(
:note
,
suggestions:
[
create
(
:suggestion
)])
note_without_suggestion
=
create
(
:note
)
expect
(
described_class
.
with_suggestions
).
to
include
(
note_with_suggestion
)
expect
(
described_class
.
with_suggestions
).
not_to
include
(
note_without_suggestion
)
end
end
end
describe
'callbacks'
do
describe
'#notify_after_create'
do
it
'calls #after_note_created on the noteable'
do
...
...
ee/spec/models/project_spec.rb
View file @
0618e0b2
...
...
@@ -112,6 +112,36 @@ describe Project do
expect
(
described_class
.
with_jira_dvcs_server
).
not_to
include
(
jira_dvcs_cloud_project
)
end
end
describe
'.github_imported'
do
it
'returns the correct project'
do
project_imported_from_github
=
create
(
:project
,
:github_imported
)
project_not_imported_from_github
=
create
(
:project
)
expect
(
described_class
.
github_imported
).
to
include
(
project_imported_from_github
)
expect
(
described_class
.
github_imported
).
not_to
include
(
project_not_imported_from_github
)
end
end
describe
'.with_protected_branches'
do
it
'returns the correct project'
do
project_with_protected_branches
=
create
(
:project
,
protected_branches:
[
create
(
:protected_branch
)])
project_without_protected_branches
=
create
(
:project
)
expect
(
described_class
.
with_protected_branches
).
to
include
(
project_with_protected_branches
)
expect
(
described_class
.
with_protected_branches
).
not_to
include
(
project_without_protected_branches
)
end
end
describe
'.with_repositories_enabled'
do
it
'returns the correct project'
do
project_with_repositories_enabled
=
create
(
:project
,
:repository_enabled
)
project_with_repositories_disabled
=
create
(
:project
,
:repository_disabled
)
expect
(
described_class
.
with_repositories_enabled
).
to
include
(
project_with_repositories_enabled
)
expect
(
described_class
.
with_repositories_enabled
).
not_to
include
(
project_with_repositories_disabled
)
end
end
end
describe
'validations'
do
...
...
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