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
f557ea9f
Commit
f557ea9f
authored
Mar 16, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove self-describing events
Part of Snowplow standardization effort
parent
2cc6c22f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
43 additions
and
77 deletions
+43
-77
app/controllers/groups/email_campaigns_controller.rb
app/controllers/groups/email_campaigns_controller.rb
+4
-2
doc/development/snowplow.md
doc/development/snowplow.md
+1
-1
ee/app/controllers/survey_responses_controller.rb
ee/app/controllers/survey_responses_controller.rb
+3
-1
ee/spec/controllers/survey_responses_controller_spec.rb
ee/spec/controllers/survey_responses_controller_spec.rb
+10
-9
lib/gitlab/tracking.rb
lib/gitlab/tracking.rb
+0
-4
lib/gitlab/tracking/destinations/snowplow.rb
lib/gitlab/tracking/destinations/snowplow.rb
+0
-7
spec/lib/gitlab/tracking/destinations/snowplow_spec.rb
spec/lib/gitlab/tracking/destinations/snowplow_spec.rb
+0
-23
spec/lib/gitlab/tracking_spec.rb
spec/lib/gitlab/tracking_spec.rb
+0
-10
spec/requests/groups/email_campaigns_controller_spec.rb
spec/requests/groups/email_campaigns_controller_spec.rb
+25
-8
spec/support/matchers/track_self_describing_event_matcher.rb
spec/support/matchers/track_self_describing_event_matcher.rb
+0
-12
No files found.
app/controllers/groups/email_campaigns_controller.rb
View file @
f557ea9f
...
...
@@ -19,12 +19,14 @@ class Groups::EmailCampaignsController < Groups::ApplicationController
def
track_click
data
=
{
namespace_id:
group
.
id
,
track:
@track
,
track:
@track
.
to_s
,
series:
@series
,
subject_line:
subject_line
(
@track
,
@series
)
}
::
Gitlab
::
Tracking
.
self_describing_event
(
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data:
data
)
context
=
SnowplowTracker
::
SelfDescribingJson
.
new
(
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data
)
::
Gitlab
::
Tracking
.
event
(
self
.
class
.
name
,
'click'
,
context:
[
context
])
end
def
redirect_link
...
...
doc/development/snowplow.md
View file @
f557ea9f
...
...
@@ -468,7 +468,7 @@ Snowplow Micro is a Docker-based solution for testing frontend and backend event
1.
Send a test Snowplow event from the Rails console:
```
ruby
Gitlab
::
Tracking
.
self_describing_event
(
'iglu:com.gitlab/pageview_context/jsonschema/1-0-0'
,
data:
{
page_type:
'MY_TYPE'
},
context:
nil
)
Gitlab
::
Tracking
.
event
(
'category'
,
'action'
)
```
1.
Navigate to
`localhost:9090/micro/good`
to see the event.
...
...
ee/app/controllers/survey_responses_controller.rb
View file @
f557ea9f
...
...
@@ -26,7 +26,9 @@ class SurveyResponsesController < ApplicationController
response:
params
[
:response
]
}.
compact
::
Gitlab
::
Tracking
.
self_describing_event
(
SURVEY_RESPONSE_SCHEMA_URL
,
data:
data
)
context
=
SnowplowTracker
::
SelfDescribingJson
.
new
(
SURVEY_RESPONSE_SCHEMA_URL
,
data
)
::
Gitlab
::
Tracking
.
event
(
self
.
class
.
name
,
'submit_response'
,
context:
[
context
])
end
def
to_number
(
param
)
...
...
ee/spec/controllers/survey_responses_controller_spec.rb
View file @
f557ea9f
...
...
@@ -20,21 +20,22 @@ RSpec.describe SurveyResponsesController do
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
end
it
'tracks a survey_response event'
do
expect
(
Gitlab
::
Tracking
).
to
receive
(
:self_describing_event
).
with
(
SurveyResponsesController
::
SURVEY_RESPONSE_SCHEMA_URL
,
data:
{
survey_id:
1
,
response:
'bar'
}
)
it
'tracks a survey_response event'
,
:snowplow
do
subject
expect_snowplow_event
(
category:
described_class
.
name
,
action:
'submit_response'
,
context:
[{
schema:
described_class
::
SURVEY_RESPONSE_SCHEMA_URL
,
data:
{
response:
'bar'
,
survey_id:
1
}
}]
)
end
end
context
'not on GitLab.com'
do
it
'does not track a survey_response event'
do
expect
(
Gitlab
::
Tracking
).
not_to
receive
(
:self_describing_event
)
it
'does not track a survey_response event'
,
:snowplow
do
subject
expect_no_snowplow_event
end
end
end
...
...
lib/gitlab/tracking.rb
View file @
f557ea9f
...
...
@@ -18,10 +18,6 @@ module Gitlab
Gitlab
::
ErrorTracking
.
track_and_raise_for_dev_exception
(
error
,
snowplow_category:
category
,
snowplow_action:
action
)
end
def
self_describing_event
(
schema_url
,
data
:,
context:
nil
)
snowplow
.
self_describing_event
(
schema_url
,
data:
data
,
context:
context
)
end
def
snowplow_options
(
group
)
additional_features
=
Feature
.
enabled?
(
:additional_snowplow_tracking
,
group
)
{
...
...
lib/gitlab/tracking/destinations/snowplow.rb
View file @
f557ea9f
...
...
@@ -15,13 +15,6 @@ module Gitlab
tracker
.
track_struct_event
(
category
,
action
,
label
,
property
,
value
,
context
,
(
Time
.
now
.
to_f
*
1000
).
to_i
)
end
def
self_describing_event
(
schema_url
,
data
:,
context:
nil
)
return
unless
enabled?
event_json
=
SnowplowTracker
::
SelfDescribingJson
.
new
(
schema_url
,
data
)
tracker
.
track_self_describing_event
(
event_json
,
context
,
(
Time
.
now
.
to_f
*
1000
).
to_i
)
end
private
def
enabled?
...
...
spec/lib/gitlab/tracking/destinations/snowplow_spec.rb
View file @
f557ea9f
...
...
@@ -41,21 +41,6 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
.
with
(
'category'
,
'action'
,
'label'
,
'property'
,
1.5
,
nil
,
(
Time
.
now
.
to_f
*
1000
).
to_i
)
end
end
describe
'#self_describing_event'
do
it
'sends event to tracker'
do
allow
(
tracker
).
to
receive
(
:track_self_describing_event
).
and_call_original
subject
.
self_describing_event
(
'iglu:com.gitlab/foo/jsonschema/1-0-0'
,
data:
{
foo:
'bar'
})
expect
(
tracker
).
to
have_received
(
:track_self_describing_event
)
do
|
event
,
context
,
timestamp
|
expect
(
event
.
to_json
[
:schema
]).
to
eq
(
'iglu:com.gitlab/foo/jsonschema/1-0-0'
)
expect
(
event
.
to_json
[
:data
]).
to
eq
(
foo:
'bar'
)
expect
(
context
).
to
eq
(
nil
)
expect
(
timestamp
).
to
eq
((
Time
.
now
.
to_f
*
1000
).
to_i
)
end
end
end
end
context
'when snowplow is not enabled'
do
...
...
@@ -66,13 +51,5 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
subject
.
event
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
)
end
end
describe
'#self_describing_event'
do
it
'does not send event to tracker'
do
expect_any_instance_of
(
SnowplowTracker
::
Tracker
).
not_to
receive
(
:track_self_describing_event
)
subject
.
self_describing_event
(
'iglu:com.gitlab/foo/jsonschema/1-0-0'
,
data:
{
foo:
'bar'
})
end
end
end
end
spec/lib/gitlab/tracking_spec.rb
View file @
f557ea9f
...
...
@@ -82,14 +82,4 @@ RSpec.describe Gitlab::Tracking do
described_class
.
event
(
nil
,
'some_action'
)
end
end
describe
'.self_describing_event'
do
it
'delegates to snowplow destination'
do
expect_any_instance_of
(
Gitlab
::
Tracking
::
Destinations
::
Snowplow
)
.
to
receive
(
:self_describing_event
)
.
with
(
'iglu:com.gitlab/foo/jsonschema/1-0-0'
,
data:
{
foo:
'bar'
},
context:
nil
)
described_class
.
self_describing_event
(
'iglu:com.gitlab/foo/jsonschema/1-0-0'
,
data:
{
foo:
'bar'
})
end
end
end
spec/requests/groups/email_campaigns_controller_spec.rb
View file @
f557ea9f
...
...
@@ -13,19 +13,19 @@ RSpec.describe Groups::EmailCampaignsController do
let
(
:track
)
{
'create'
}
let
(
:series
)
{
'0'
}
let
(
:schema
)
{
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
}
let
(
:subject_line_text
)
{
subject_line
(
track
.
to_sym
,
series
.
to_i
)
}
let
(
:data
)
do
{
namespace_id:
group
.
id
,
track:
track
.
to_sym
,
series:
series
.
to_i
,
subject_line:
subject_line
(
track
.
to_sym
,
series
.
to_i
)
subject_line:
subject_line
_text
}
end
before
do
sign_in
(
user
)
group
.
add_developer
(
user
)
allow
(
Gitlab
::
Tracking
).
to
receive
(
:self_describing_event
)
end
subject
do
...
...
@@ -34,16 +34,33 @@ RSpec.describe Groups::EmailCampaignsController do
end
shared_examples
'track and redirect'
do
it
do
is_expected
.
to
track_self_describing_event
(
schema
,
data
)
is_expected
.
to
have_gitlab_http_status
(
:redirect
)
it
'redirects'
do
expect
(
subject
).
to
have_gitlab_http_status
(
:redirect
)
end
it
'emits a snowplow event'
,
:snowplow
do
subject
expect_snowplow_event
(
category:
described_class
.
name
,
action:
'click'
,
context:
[{
schema:
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data:
{
namespace_id:
group
.
id
,
series:
series
.
to_i
,
subject_line:
subject_line_text
,
track:
track
.
to_s
}
}]
)
end
end
shared_examples
'no track and 404'
do
it
do
is_expected
.
not_to
track_self_describing_event
is_expected
.
to
have_gitlab_http_status
(
:not_found
)
it
'returns 404'
do
expect
(
subject
).
to
have_gitlab_http_status
(
:not_found
)
end
it
'does not emit a snowplow event'
,
:snowplow
do
subject
expect_no_snowplow_event
end
end
...
...
spec/support/matchers/track_self_describing_event_matcher.rb
deleted
100644 → 0
View file @
2cc6c22f
# frozen_string_literal: true
RSpec
::
Matchers
.
define
:track_self_describing_event
do
|
schema
,
data
|
match
do
expect
(
Gitlab
::
Tracking
).
to
have_received
(
:self_describing_event
)
.
with
(
schema
,
data:
data
)
end
match_when_negated
do
expect
(
Gitlab
::
Tracking
).
not_to
have_received
(
:self_describing_event
)
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