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
56c29ef1
Commit
56c29ef1
authored
Mar 17, 2022
by
Niko Belokolodov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate g_analytics_valuestream metric to Snowplow
Route controller metrics to RedisHLL and Snowplow
parent
1862e8f1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
230 additions
and
3 deletions
+230
-3
app/controllers/concerns/product_analytics_tracking.rb
app/controllers/concerns/product_analytics_tracking.rb
+27
-0
config/feature_flags/development/route_hll_to_snowplow.yml
config/feature_flags/development/route_hll_to_snowplow.yml
+8
-0
ee/app/controllers/groups/analytics/application_controller.rb
...pp/controllers/groups/analytics/application_controller.rb
+1
-1
ee/app/controllers/groups/analytics/cycle_analytics_controller.rb
...ontrollers/groups/analytics/cycle_analytics_controller.rb
+4
-2
ee/spec/controllers/groups/analytics/cycle_analytics_controller_spec.rb
...llers/groups/analytics/cycle_analytics_controller_spec.rb
+19
-0
spec/controllers/concerns/product_analytics_tracking_spec.rb
spec/controllers/concerns/product_analytics_tracking_spec.rb
+171
-0
No files found.
app/controllers/concerns/product_analytics_tracking.rb
0 → 100644
View file @
56c29ef1
# frozen_string_literal: true
module
ProductAnalyticsTracking
include
Gitlab
::
Tracking
::
Helpers
include
RedisTracking
extend
ActiveSupport
::
Concern
class_methods
do
def
track_event
(
*
controller_actions
,
name
:,
conditions:
nil
,
destinations:
[
:redis_hll
],
&
block
)
custom_conditions
=
[
:trackable_html_request?
,
*
conditions
]
after_action
only:
controller_actions
,
if:
custom_conditions
do
route_events_to
(
destinations
,
name
,
&
block
)
end
end
end
private
def
route_events_to
(
destinations
,
name
,
&
block
)
track_unique_redis_hll_event
(
name
,
&
block
)
if
destinations
.
include?
(
:redis_hll
)
if
destinations
.
include?
(
:snowplow
)
&&
Feature
.
enabled?
(
:route_hll_to_snowplow
,
tracking_namespace_source
,
default_enabled: :yaml
)
Gitlab
::
Tracking
.
event
(
self
.
class
.
to_s
,
name
,
namespace:
tracking_namespace_source
,
user:
current_user
)
end
end
end
config/feature_flags/development/route_hll_to_snowplow.yml
0 → 100644
View file @
56c29ef1
---
name
:
route_hll_to_snowplow
introduced_by_url
:
https://gitlab.com/gitlab-org/product-intelligence/-/issues/498
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/354442
milestone
:
'
14.9'
type
:
development
group
:
group::product intelligence
default_enabled
:
false
ee/app/controllers/groups/analytics/application_controller.rb
View file @
56c29ef1
...
...
@@ -23,7 +23,7 @@ class Groups::Analytics::ApplicationController < ApplicationController
def
load_group
return
unless
params
[
'group_id'
]
@group
=
find_routable!
(
Group
,
params
[
'group_id'
],
request
.
fullpath
)
@group
||
=
find_routable!
(
Group
,
params
[
'group_id'
],
request
.
fullpath
)
end
def
load_project
...
...
ee/app/controllers/groups/analytics/cycle_analytics_controller.rb
View file @
56c29ef1
...
...
@@ -2,7 +2,7 @@
class
Groups::Analytics::CycleAnalyticsController
<
Groups
::
Analytics
::
ApplicationController
include
CycleAnalyticsParams
include
Redi
sTracking
include
ProductAnalytic
sTracking
extend
::
Gitlab
::
Utils
::
Override
increment_usage_counter
Gitlab
::
UsageDataCounters
::
CycleAnalyticsCounter
,
:views
,
only: :show
...
...
@@ -22,7 +22,7 @@ class Groups::Analytics::CycleAnalyticsController < Groups::Analytics::Applicati
layout
'group'
track_
redis_hll_event
:show
,
name:
'g_analytics_valuestream'
track_
event
:show
,
name:
'g_analytics_valuestream'
,
destinations:
[
:redis_hll
,
:snowplow
]
def
show
epic_link_start
=
'<a href="%{url}" target="_blank" rel="noopener noreferrer">'
.
html_safe
%
{
url:
"https://gitlab.com/groups/gitlab-org/-/epics/6046"
}
...
...
@@ -55,4 +55,6 @@ class Groups::Analytics::CycleAnalyticsController < Groups::Analytics::Applicati
@group
.
value_streams
.
find
(
params
[
:value_stream_id
])
end
end
alias_method
:tracking_namespace_source
,
:load_group
end
ee/spec/controllers/groups/analytics/cycle_analytics_controller_spec.rb
View file @
56c29ef1
...
...
@@ -57,6 +57,25 @@ RSpec.describe Groups::Analytics::CycleAnalyticsController do
end
end
end
describe
'tracking events'
,
:snowplow
do
it
'tracks redis hll event'
do
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
receive
(
:track_event
).
with
(
'g_analytics_valuestream'
,
{
values:
anything
})
get
(
:show
,
params:
{
group_id:
group
})
end
it
'tracks snowplow event'
do
get
(
:show
,
params:
{
group_id:
group
})
expect_snowplow_event
(
category:
'Groups::Analytics::CycleAnalyticsController'
,
action:
'g_analytics_valuestream'
,
namespace:
group
,
user:
user
)
end
end
end
context
'when the license is missing'
do
...
...
spec/controllers/concerns/product_analytics_tracking_spec.rb
0 → 100644
View file @
56c29ef1
# frozen_string_literal: true
require
"spec_helper"
RSpec
.
describe
ProductAnalyticsTracking
,
:snowplow
do
include
TrackingHelpers
include
SnowplowHelpers
let
(
:user
)
{
create
(
:user
)
}
let!
(
:group
)
{
create
(
:group
)
}
before
do
allow
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
receive
(
:track_event
)
end
controller
(
ApplicationController
)
do
include
ProductAnalyticsTracking
skip_before_action
:authenticate_user!
,
only: :show
track_event
(
:index
,
:show
,
name:
'g_analytics_valuestream'
,
destinations:
[
:redis_hll
,
:snowplow
],
conditions:
[
:custom_condition_one?
,
:custom_condition_two?
])
{
|
controller
|
controller
.
get_custom_id
}
def
index
render
html:
'index'
end
def
new
render
html:
'new'
end
def
show
render
html:
'show'
end
def
get_custom_id
'some_custom_id'
end
private
def
tracking_namespace_source
Group
.
first
end
def
custom_condition_one?
true
end
def
custom_condition_two?
true
end
end
def
expect_tracking
(
user:
self
.
user
)
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
have_received
(
:track_event
)
.
with
(
'g_analytics_valuestream'
,
values:
instance_of
(
String
))
expect_snowplow_event
(
category:
anything
,
action:
'g_analytics_valuestream'
,
namespace:
group
,
user:
user
)
end
def
expect_no_tracking
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
receive
(
:track_event
)
expect_no_snowplow_event
end
context
'when user is logged in'
do
before
do
sign_in
(
user
)
end
it
'tracks the event'
do
get
:index
expect_tracking
end
context
'when FF is disabled'
do
before
do
stub_feature_flags
(
route_hll_to_snowplow:
false
)
end
it
'doesnt track snowplow event'
do
get
:index
expect_no_snowplow_event
end
end
it
'tracks the event if DNT is not enabled'
do
stub_do_not_track
(
'0'
)
get
:index
expect_tracking
end
it
'does not track the event if DNT is enabled'
do
stub_do_not_track
(
'1'
)
get
:index
expect_no_tracking
end
it
'does not track the event if the format is not HTML'
do
get
:index
,
format: :json
expect_no_tracking
end
it
'does not track the event if a custom condition returns false'
do
allow
(
controller
).
to
receive
(
:custom_condition_two?
).
and_return
(
false
)
get
:index
expect_no_tracking
end
it
'does not track the event for untracked actions'
do
get
:new
expect_no_tracking
end
end
context
'when user is not logged in'
do
let
(
:visitor_id
)
{
SecureRandom
.
uuid
}
it
'tracks the event when there is a visitor id'
do
cookies
[
:visitor_id
]
=
{
value:
visitor_id
,
expires:
24
.
months
}
get
:show
,
params:
{
id:
1
}
expect_tracking
(
user:
nil
)
end
end
context
'when user is not logged in and there is no visitor_id'
do
it
'does not track the event'
do
get
:index
expect_no_tracking
end
it
'tracks the event when there is custom id'
do
get
:show
,
params:
{
id:
1
}
expect_tracking
(
user:
nil
)
end
it
'does not track the HLL event when there is no custom id'
do
allow
(
controller
).
to
receive
(
:get_custom_id
).
and_return
(
nil
)
get
:show
,
params:
{
id:
2
}
expect
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
receive
(
:track_event
)
expect_snowplow_event
(
category:
anything
,
action:
'g_analytics_valuestream'
,
namespace:
group
,
user:
nil
)
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