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
06def93b
Commit
06def93b
authored
Aug 10, 2020
by
Aishwarya Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Seperated Compliance related pages counts
Renamed ids to be more compliance related
parent
a9053d54
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
95 additions
and
32 deletions
+95
-32
ee/app/controllers/admin/audit_logs_controller.rb
ee/app/controllers/admin/audit_logs_controller.rb
+1
-1
ee/app/controllers/admin/credentials_controller.rb
ee/app/controllers/admin/credentials_controller.rb
+1
-1
ee/app/controllers/groups/audit_events_controller.rb
ee/app/controllers/groups/audit_events_controller.rb
+1
-1
ee/app/controllers/groups/security/compliance_dashboards_controller.rb
...llers/groups/security/compliance_dashboards_controller.rb
+1
-1
ee/spec/controllers/admin/audit_logs_controller_spec.rb
ee/spec/controllers/admin/audit_logs_controller_spec.rb
+1
-1
ee/spec/controllers/admin/credentials_controller_spec.rb
ee/spec/controllers/admin/credentials_controller_spec.rb
+1
-1
ee/spec/controllers/groups/audit_events_controller_spec.rb
ee/spec/controllers/groups/audit_events_controller_spec.rb
+1
-1
ee/spec/controllers/groups/security/compliance_dashboards_controller_spec.rb
.../groups/security/compliance_dashboards_controller_spec.rb
+1
-1
lib/gitlab/analytics/unique_visits.rb
lib/gitlab/analytics/unique_visits.rb
+18
-10
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+14
-3
spec/lib/gitlab/analytics/unique_visits_spec.rb
spec/lib/gitlab/analytics/unique_visits_spec.rb
+21
-4
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+34
-7
No files found.
ee/app/controllers/admin/audit_logs_controller.rb
View file @
06def93b
...
...
@@ -8,7 +8,7 @@ class Admin::AuditLogsController < Admin::ApplicationController
before_action
:check_license_admin_audit_log_available!
track_unique_visits
:index
,
target_id:
'i_
analytics
_audit_events'
track_unique_visits
:index
,
target_id:
'i_
compliance
_audit_events'
PER_PAGE
=
25
...
...
ee/app/controllers/admin/credentials_controller.rb
View file @
06def93b
...
...
@@ -9,7 +9,7 @@ class Admin::CredentialsController < Admin::ApplicationController
before_action
:check_license_credentials_inventory_available!
,
only:
[
:index
]
track_unique_visits
:index
,
target_id:
'i_
analytics
_credential_inventory'
track_unique_visits
:index
,
target_id:
'i_
compliance
_credential_inventory'
private
...
...
ee/app/controllers/groups/audit_events_controller.rb
View file @
06def93b
...
...
@@ -9,7 +9,7 @@ class Groups::AuditEventsController < Groups::ApplicationController
before_action
:authorize_admin_group!
before_action
:check_audit_events_available!
track_unique_visits
:index
,
target_id:
'g_
analytics
_audit_events'
track_unique_visits
:index
,
target_id:
'g_
compliance
_audit_events'
layout
'group_settings'
...
...
ee/app/controllers/groups/security/compliance_dashboards_controller.rb
View file @
06def93b
...
...
@@ -7,7 +7,7 @@ class Groups::Security::ComplianceDashboardsController < Groups::ApplicationCont
before_action
:authorize_compliance_dashboard!
track_unique_visits
:show
,
target_id:
'g_
analytics_
compliance_dashboard'
track_unique_visits
:show
,
target_id:
'g_compliance_dashboard'
def
show
@last_page
=
paginated_merge_requests
.
last_page?
...
...
ee/spec/controllers/admin/audit_logs_controller_spec.rb
View file @
06def93b
...
...
@@ -27,7 +27,7 @@ RSpec.describe Admin::AuditLogsController do
it_behaves_like
'tracking unique visits'
,
:index
do
let
(
:request_params
)
{
{
'entity_type'
:
'User'
}
}
let
(
:target_id
)
{
'i_
analytics
_audit_events'
}
let
(
:target_id
)
{
'i_
compliance
_audit_events'
}
end
end
end
...
...
ee/spec/controllers/admin/credentials_controller_spec.rb
View file @
06def93b
...
...
@@ -22,7 +22,7 @@ RSpec.describe Admin::CredentialsController do
it_behaves_like
'tracking unique visits'
,
:index
do
let
(
:request_params
)
{
{}
}
let
(
:target_id
)
{
'i_
analytics
_credential_inventory'
}
let
(
:target_id
)
{
'i_
compliance
_credential_inventory'
}
end
describe
'filtering by type of credential'
do
...
...
ee/spec/controllers/groups/audit_events_controller_spec.rb
View file @
06def93b
...
...
@@ -121,7 +121,7 @@ RSpec.describe Groups::AuditEventsController do
it_behaves_like
'tracking unique visits'
,
:index
do
let
(
:request_params
)
{
{
group_id:
group
.
to_param
,
sort:
sort
,
entity_type:
entity_type
,
entity_id:
entity_id
}
}
let
(
:target_id
)
{
'g_
analytics
_audit_events'
}
let
(
:target_id
)
{
'g_
compliance
_audit_events'
}
end
end
...
...
ee/spec/controllers/groups/security/compliance_dashboards_controller_spec.rb
View file @
06def93b
...
...
@@ -50,7 +50,7 @@ RSpec.describe Groups::Security::ComplianceDashboardsController do
it_behaves_like
'tracking unique visits'
,
:show
do
let
(
:request_params
)
{
{
group_id:
group
.
to_param
}
}
let
(
:target_id
)
{
'g_
analytics_
compliance_dashboard'
}
let
(
:target_id
)
{
'g_compliance_dashboard'
}
end
end
...
...
lib/gitlab/analytics/unique_visits.rb
View file @
06def93b
...
...
@@ -3,14 +3,12 @@
module
Gitlab
module
Analytics
class
UniqueVisits
TARGET
_IDS
=
Set
[
ANALYTICS
_IDS
=
Set
[
'g_analytics_contribution'
,
'g_analytics_insights'
,
'g_analytics_issues'
,
'g_analytics_productivity'
,
'g_analytics_valuestream'
,
'g_analytics_compliance_dashboard'
,
'g_analytics_audit_events'
,
'p_analytics_pipelines'
,
'p_analytics_code_reviews'
,
'p_analytics_valuestream'
,
...
...
@@ -18,9 +16,14 @@ module Gitlab
'p_analytics_issues'
,
'p_analytics_repo'
,
'i_analytics_cohorts'
,
'i_analytics_dev_ops_score'
,
'i_analytics_credential_inventory'
,
'i_analytics_audit_events'
'i_analytics_dev_ops_score'
]
COMPLIANCE_IDS
=
Set
[
'g_compliance_dashboard'
,
'g_compliance_audit_events'
,
'i_compliance_credential_inventory'
,
'i_compliance_audit_events'
].
freeze
KEY_EXPIRY_LENGTH
=
12
.
weeks
...
...
@@ -38,8 +41,10 @@ module Gitlab
# @param [Integer] weeks time frame length in weeks
# @return [Integer] number of unique visitors
def
unique_visits_for
(
targets
:,
start_week:
7
.
days
.
ago
,
weeks:
1
)
target_ids
=
if
targets
==
:any
TARGET_IDS
target_ids
=
if
targets
==
:analytics
ANALYTICS_IDS
elsif
targets
==
:compliance
COMPLIANCE_IDS
else
Array
(
targets
)
end
...
...
@@ -54,9 +59,12 @@ module Gitlab
private
def
key
(
target_id
,
time
)
raise
"Invalid target id
#{
target_id
}
"
unless
TARGET_IDS
.
include?
(
target_id
.
to_s
)
target_ids
=
ANALYTICS_IDS
+
COMPLIANCE_IDS
raise
"Invalid target id
#{
target_id
}
"
unless
target_ids
.
include?
(
target_id
.
to_s
)
target_key
=
target_id
.
to_s
.
gsub
(
'analytics'
,
'{analytics}'
).
gsub
(
'compliance'
,
'{compliance}'
)
target_key
=
target_id
.
to_s
.
gsub
(
'analytics'
,
'{analytics}'
)
year_week
=
time
.
strftime
(
'%G-%V'
)
"
#{
target_key
}
-
#{
year_week
}
"
...
...
lib/gitlab/usage_data.rb
View file @
06def93b
...
...
@@ -37,6 +37,7 @@ module Gitlab
.
merge
(
usage_activity_by_stage
)
.
merge
(
usage_activity_by_stage
(
:usage_activity_by_stage_monthly
,
last_28_days_time_period
))
.
merge
(
analytics_unique_visits_data
)
.
merge
(
compliance_unique_visits_data
)
end
end
...
...
@@ -582,15 +583,25 @@ module Gitlab
end
def
analytics_unique_visits_data
results
=
::
Gitlab
::
Analytics
::
UniqueVisits
::
TARGET
_IDS
.
each_with_object
({})
do
|
target_id
,
hash
|
results
=
::
Gitlab
::
Analytics
::
UniqueVisits
::
ANALYTICS
_IDS
.
each_with_object
({})
do
|
target_id
,
hash
|
hash
[
target_id
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets:
target_id
)
}
end
results
[
'analytics_unique_visits_for_any_target'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :an
y
)
}
results
[
'analytics_unique_visits_for_any_target_monthly'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :an
y
,
weeks:
4
)
}
results
[
'analytics_unique_visits_for_any_target'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :an
alytics
)
}
results
[
'analytics_unique_visits_for_any_target_monthly'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :an
alytics
,
weeks:
4
)
}
{
analytics_unique_visits:
results
}
end
def
compliance_unique_visits_data
results
=
::
Gitlab
::
Analytics
::
UniqueVisits
::
COMPLIANCE_IDS
.
each_with_object
({})
do
|
target_id
,
hash
|
hash
[
target_id
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets:
target_id
)
}
end
results
[
'compliance_unique_visits_for_any_target'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :compliance
)
}
results
[
'compliance_unique_visits_for_any_target_monthly'
]
=
redis_usage_data
{
unique_visit_service
.
unique_visits_for
(
targets: :compliance
,
weeks:
4
)
}
{
compliance_unique_visits:
results
}
end
def
action_monthly_active_users
(
time_period
)
return
{}
unless
Feature
.
enabled?
(
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
::
FEATURE_FLAG
)
...
...
spec/lib/gitlab/analytics/unique_visits_spec.rb
View file @
06def93b
...
...
@@ -7,8 +7,11 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state
let
(
:target1_id
)
{
'g_analytics_contribution'
}
let
(
:target2_id
)
{
'g_analytics_insights'
}
let
(
:target3_id
)
{
'g_analytics_issues'
}
let
(
:target4_id
)
{
'g_compliance_dashboard'
}
let
(
:target5_id
)
{
'i_compliance_credential_inventory'
}
let
(
:visitor1_id
)
{
'dfb9d2d2-f56c-4c77-8aeb-6cddc4a1f857'
}
let
(
:visitor2_id
)
{
'1dd9afb2-a3ee-4de1-8ae3-a405579c8584'
}
let
(
:visitor3_id
)
{
'34rfjuuy-ce56-sa35-ds34-dfer567dfrf2'
}
around
do
|
example
|
# We need to freeze to a reference time
...
...
@@ -29,18 +32,32 @@ RSpec.describe Gitlab::Analytics::UniqueVisits, :clean_gitlab_redis_shared_state
unique_visits
.
track_visit
(
visitor1_id
,
target2_id
,
8
.
days
.
ago
)
unique_visits
.
track_visit
(
visitor1_id
,
target2_id
,
15
.
days
.
ago
)
unique_visits
.
track_visit
(
visitor3_id
,
target4_id
,
7
.
days
.
ago
)
unique_visits
.
track_visit
(
visitor3_id
,
target5_id
,
15
.
days
.
ago
)
unique_visits
.
track_visit
(
visitor2_id
,
target5_id
,
15
.
days
.
ago
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target1_id
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target2_id
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target4_id
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target2_id
,
start_week:
15
.
days
.
ago
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target3_id
)).
to
eq
(
0
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :any
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :any
,
start_week:
15
.
days
.
ago
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :any
,
start_week:
30
.
days
.
ago
)).
to
eq
(
0
)
expect
(
unique_visits
.
unique_visits_for
(
targets:
target5_id
,
start_week:
15
.
days
.
ago
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :analytics
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :analytics
,
start_week:
15
.
days
.
ago
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :analytics
,
start_week:
30
.
days
.
ago
)).
to
eq
(
0
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :analytics
,
weeks:
4
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :compliance
)).
to
eq
(
1
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :compliance
,
start_week:
15
.
days
.
ago
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :compliance
,
start_week:
30
.
days
.
ago
)).
to
eq
(
0
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :
any
,
weeks:
4
)).
to
eq
(
2
)
expect
(
unique_visits
.
unique_visits_for
(
targets: :
compliance
,
weeks:
4
)).
to
eq
(
2
)
end
it
'sets the keys in Redis to expire automatically after 12 weeks'
do
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
06def93b
...
...
@@ -958,12 +958,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject
{
described_class
.
analytics_unique_visits_data
}
it
'returns the number of unique visits to pages with analytics features'
do
::
Gitlab
::
Analytics
::
UniqueVisits
::
TARGET
_IDS
.
each
do
|
target_id
|
::
Gitlab
::
Analytics
::
UniqueVisits
::
ANALYTICS
_IDS
.
each
do
|
target_id
|
expect_any_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
).
to
receive
(
:unique_visits_for
).
with
(
targets:
target_id
).
and_return
(
123
)
end
expect_any_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
).
to
receive
(
:unique_visits_for
).
with
(
targets: :an
y
).
and_return
(
543
)
expect_any_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
).
to
receive
(
:unique_visits_for
).
with
(
targets: :an
y
,
weeks:
4
).
and_return
(
987
)
expect_any_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
).
to
receive
(
:unique_visits_for
).
with
(
targets: :an
alytics
).
and_return
(
543
)
expect_any_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
).
to
receive
(
:unique_visits_for
).
with
(
targets: :an
alytics
,
weeks:
4
).
and_return
(
987
)
expect
(
subject
).
to
eq
({
analytics_unique_visits:
{
...
...
@@ -975,15 +975,11 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
'p_analytics_pipelines'
=>
123
,
'p_analytics_code_reviews'
=>
123
,
'p_analytics_valuestream'
=>
123
,
'g_analytics_compliance_dashboard'
=>
123
,
'g_analytics_audit_events'
=>
123
,
'p_analytics_insights'
=>
123
,
'p_analytics_issues'
=>
123
,
'p_analytics_repo'
=>
123
,
'i_analytics_cohorts'
=>
123
,
'i_analytics_dev_ops_score'
=>
123
,
'i_analytics_credential_inventory'
=>
123
,
'i_analytics_audit_events'
=>
123
,
'analytics_unique_visits_for_any_target'
=>
543
,
'analytics_unique_visits_for_any_target_monthly'
=>
987
}
...
...
@@ -991,6 +987,37 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
describe
'.compliance_unique_visits_data'
do
subject
{
described_class
.
compliance_unique_visits_data
}
before
do
described_class
.
clear_memoization
(
:unique_visit_service
)
allow_next_instance_of
(
::
Gitlab
::
Analytics
::
UniqueVisits
)
do
|
instance
|
::
Gitlab
::
Analytics
::
UniqueVisits
::
COMPLIANCE_IDS
.
each
do
|
target_id
|
allow
(
instance
).
to
receive
(
:unique_visits_for
).
with
(
targets:
target_id
).
and_return
(
123
)
end
allow
(
instance
).
to
receive
(
:unique_visits_for
).
with
(
targets: :compliance
).
and_return
(
543
)
allow
(
instance
).
to
receive
(
:unique_visits_for
).
with
(
targets: :compliance
,
weeks:
4
).
and_return
(
987
)
end
end
it
'returns the number of unique visits to pages with compliance features'
do
expect
(
subject
).
to
eq
({
compliance_unique_visits:
{
'g_compliance_dashboard'
=>
123
,
'g_compliance_audit_events'
=>
123
,
'i_compliance_credential_inventory'
=>
123
,
'i_compliance_audit_events'
=>
123
,
'compliance_unique_visits_for_any_target'
=>
543
,
'compliance_unique_visits_for_any_target_monthly'
=>
987
}
})
end
end
describe
'.service_desk_counts'
do
subject
{
described_class
.
send
(
:service_desk_counts
)
}
...
...
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