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
3ce22f05
Commit
3ce22f05
authored
Jan 07, 2021
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send gitlab_standard context with issue promotion event
- Create helper object to build gitlab_standard context
parent
4e2a2eff
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
139 additions
and
18 deletions
+139
-18
ee/app/services/epics/issue_promote_service.rb
ee/app/services/epics/issue_promote_service.rb
+2
-3
ee/spec/services/epics/issue_promote_service_spec.rb
ee/spec/services/epics/issue_promote_service_spec.rb
+6
-3
lib/gitlab/tracking.rb
lib/gitlab/tracking.rb
+3
-1
lib/gitlab/tracking/standard_context.rb
lib/gitlab/tracking/standard_context.rb
+41
-0
spec/lib/gitlab/tracking/standard_context_spec.rb
spec/lib/gitlab/tracking/standard_context_spec.rb
+55
-0
spec/lib/gitlab/tracking_spec.rb
spec/lib/gitlab/tracking_spec.rb
+32
-11
No files found.
ee/app/services/epics/issue_promote_service.rb
View file @
3ce22f05
...
...
@@ -32,9 +32,8 @@ module Epics
end
def
track_event
::
Gitlab
::
Tracking
.
event
(
'epics'
,
'promote'
,
property:
'issue_id'
,
value:
original_entity
.
id
)
::
Gitlab
::
Tracking
.
event
(
'epics'
,
'promote'
,
property:
'issue_id'
,
value:
original_entity
.
id
,
standard_context:
::
Gitlab
::
Tracking
::
StandardContext
.
new
(
namespace:
@parent_group
,
project:
issue
.
project
))
end
def
create_new_entity
...
...
ee/spec/services/epics/issue_promote_service_spec.rb
View file @
3ce22f05
...
...
@@ -64,7 +64,8 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
before
do
subject
.
execute
(
issue
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
,
standard_context:
kind_of
(
Gitlab
::
Tracking
::
StandardContext
))
end
it
'creates a new epic with correct attributes'
do
...
...
@@ -199,7 +200,8 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
expect
(
epic
.
notes
.
count
).
to
eq
(
issue
.
notes
.
count
)
expect
(
epic
.
notes
.
where
(
discussion_id:
discussion
.
discussion_id
).
count
).
to
eq
(
0
)
expect
(
issue
.
notes
.
where
(
discussion_id:
discussion
.
discussion_id
).
count
).
to
eq
(
1
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
,
standard_context:
kind_of
(
Gitlab
::
Tracking
::
StandardContext
))
end
it
'copies note attachments'
do
...
...
@@ -208,7 +210,8 @@ RSpec.describe Epics::IssuePromoteService, :aggregate_failures do
epic
=
subject
.
execute
(
issue
)
expect
(
epic
.
notes
.
user
.
first
.
attachment
).
to
be_kind_of
(
AttachmentUploader
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
)
expect_snowplow_event
(
category:
'epics'
,
action:
'promote'
,
property:
'issue_id'
,
value:
issue
.
id
,
standard_context:
kind_of
(
Gitlab
::
Tracking
::
StandardContext
))
end
end
...
...
lib/gitlab/tracking.rb
View file @
3ce22f05
...
...
@@ -24,7 +24,9 @@ module Gitlab
Gitlab
::
CurrentSettings
.
snowplow_enabled?
end
def
event
(
category
,
action
,
label:
nil
,
property:
nil
,
value:
nil
,
context:
nil
)
def
event
(
category
,
action
,
label:
nil
,
property:
nil
,
value:
nil
,
context:
[],
standard_context:
nil
)
context
.
push
(
standard_context
.
to_context
)
if
standard_context
snowplow
.
event
(
category
,
action
,
label:
label
,
property:
property
,
value:
value
,
context:
context
)
product_analytics
.
event
(
category
,
action
,
label:
label
,
property:
property
,
value:
value
,
context:
context
)
end
...
...
lib/gitlab/tracking/standard_context.rb
0 → 100644
View file @
3ce22f05
# frozen_string_literal: true
module
Gitlab
module
Tracking
class
StandardContext
GITLAB_STANDARD_SCHEMA_URL
=
'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-1'
.
freeze
def
initialize
(
namespace:
nil
,
project:
nil
,
**
data
)
@namespace
=
namespace
@project
=
project
@data
=
data
end
def
namespace_id
namespace
&
.
id
end
def
project_id
@project
&
.
id
end
def
to_context
SnowplowTracker
::
SelfDescribingJson
.
new
(
GITLAB_STANDARD_SCHEMA_URL
,
to_h
)
end
private
def
namespace
@namespace
||
@project
&
.
namespace
end
def
to_h
public_methods
(
false
).
each_with_object
({})
do
|
method
,
hash
|
next
if
method
==
:to_context
hash
[
method
]
=
public_send
(
method
)
# rubocop:disable GitlabSecurity/PublicSend
end
.
merge
(
@data
)
end
end
end
end
spec/lib/gitlab/tracking/standard_context_spec.rb
0 → 100644
View file @
3ce22f05
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Tracking
::
StandardContext
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:snowplow_context
)
{
subject
.
to_context
}
describe
'#to_context'
do
context
'with no arguments'
do
it
'creates a Snowplow context with no data'
do
snowplow_context
.
to_json
[
:data
].
each
do
|
_
,
v
|
expect
(
v
).
to
be_nil
end
end
end
context
'with extra data'
do
subject
{
described_class
.
new
(
foo:
'bar'
)
}
it
'creates a Snowplow context with the given data'
do
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:foo
)).
to
eq
(
'bar'
)
end
end
context
'with namespace'
do
subject
{
described_class
.
new
(
namespace:
namespace
)
}
it
'creates a Snowplow context using the given data'
do
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:namespace_id
)).
to
eq
(
namespace
.
id
)
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:project_id
)).
to
be_nil
end
end
context
'with project'
do
subject
{
described_class
.
new
(
project:
project
)
}
it
'creates a Snowplow context using the given data'
do
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:namespace_id
)).
to
eq
(
project
.
namespace
.
id
)
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:project_id
)).
to
eq
(
project
.
id
)
end
end
context
'with project and namespace'
do
subject
{
described_class
.
new
(
namespace:
namespace
,
project:
project
)
}
it
'creates a Snowplow context using the given data'
do
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:namespace_id
)).
to
eq
(
namespace
.
id
)
expect
(
snowplow_context
.
to_json
.
dig
(
:data
,
:project_id
)).
to
eq
(
project
.
id
)
end
end
end
end
spec/lib/gitlab/tracking_spec.rb
View file @
3ce22f05
...
...
@@ -41,21 +41,42 @@ RSpec.describe Gitlab::Tracking do
allow_any_instance_of
(
Gitlab
::
Tracking
::
Destinations
::
ProductAnalytics
).
to
receive
(
:event
)
end
it
'delegates to snowplow destination'
do
expect_any_instance_of
(
Gitlab
::
Tracking
::
Destinations
::
Snowplow
)
.
to
receive
(
:event
)
.
with
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
,
context:
nil
)
shared_examples
'delegates to destination'
do
|
klass
|
context
'with standard context'
do
it
"delegates to
#{
klass
}
destination"
do
expect_any_instance_of
(
klass
).
to
receive
(
:event
)
do
|
_
,
category
,
action
,
args
|
expect
(
category
).
to
eq
(
'category'
)
expect
(
action
).
to
eq
(
'action'
)
expect
(
args
[
:label
]).
to
eq
(
'label'
)
expect
(
args
[
:property
]).
to
eq
(
'property'
)
expect
(
args
[
:value
]).
to
eq
(
1.5
)
expect
(
args
[
:context
].
length
).
to
eq
(
1
)
expect
(
args
[
:context
].
first
.
to_json
[
:schema
]).
to
eq
(
Gitlab
::
Tracking
::
StandardContext
::
GITLAB_STANDARD_SCHEMA_URL
)
expect
(
args
[
:context
].
first
.
to_json
[
:data
]).
to
include
(
foo:
'bar'
)
end
described_class
.
event
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
)
end
described_class
.
event
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
,
standard_context:
Gitlab
::
Tracking
::
StandardContext
.
new
(
foo:
'bar'
))
end
end
it
'delegates to ProductAnalytics destination'
do
expect_any_instance_of
(
Gitlab
::
Tracking
::
Destinations
::
ProductAnalytics
)
.
to
receive
(
:event
)
.
with
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
,
context:
nil
)
context
'without standard context'
do
it
"delegates to
#{
klass
}
destination"
do
expect_any_instance_of
(
klass
).
to
receive
(
:event
)
do
|
_
,
category
,
action
,
args
|
expect
(
category
).
to
eq
(
'category'
)
expect
(
action
).
to
eq
(
'action'
)
expect
(
args
[
:label
]).
to
eq
(
'label'
)
expect
(
args
[
:property
]).
to
eq
(
'property'
)
expect
(
args
[
:value
]).
to
eq
(
1.5
)
end
described_class
.
event
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
)
described_class
.
event
(
'category'
,
'action'
,
label:
'label'
,
property:
'property'
,
value:
1.5
)
end
end
end
include_examples
'delegates to destination'
,
Gitlab
::
Tracking
::
Destinations
::
Snowplow
include_examples
'delegates to destination'
,
Gitlab
::
Tracking
::
Destinations
::
ProductAnalytics
end
describe
'.self_describing_event'
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