Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab
Commits
c1d8da59
Verified
Commit
c1d8da59
authored
11 months ago
by
Michał Wielich
Browse files
Options
Downloads
Patches
Plain Diff
Remove additional properties mapping
Remove additional properties mapping
parent
19d1ee9a
No related branches found
No related tags found
1 merge request
!146474
Remove Internal Events additional properties mapping
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/gitlab/internal_events.rb
+2
-40
2 additions, 40 deletions
lib/gitlab/internal_events.rb
spec/lib/gitlab/internal_events_spec.rb
+0
-80
0 additions, 80 deletions
spec/lib/gitlab/internal_events_spec.rb
with
2 additions
and
120 deletions
lib/gitlab/internal_events.rb
+
2
−
40
View file @
c1d8da59
...
...
@@ -21,9 +21,7 @@ class << self
def
track_event
(
event_name
,
category:
nil
,
send_snowplow_event:
true
,
additional_properties:
{},
**
kwargs
)
raise
UnknownEventError
,
"Unknown event:
#{
event_name
}
"
unless
EventDefinitions
.
known_event?
(
event_name
)
mapped_additional_properties
=
map_additional_properties
(
event_name
,
additional_properties
)
validate_properties!
(
mapped_additional_properties
,
kwargs
)
validate_properties!
(
additional_properties
,
kwargs
)
project
=
kwargs
[
:project
]
kwargs
[
:namespace
]
||=
project
.
namespace
if
project
...
...
@@ -32,7 +30,7 @@ def track_event(event_name, category: nil, send_snowplow_event: true, additional
increase_weekly_total_counter
(
event_name
)
update_unique_counters
(
event_name
,
kwargs
)
trigger_snowplow_event
(
event_name
,
category
,
mapped_
additional_properties
,
kwargs
)
if
send_snowplow_event
trigger_snowplow_event
(
event_name
,
category
,
additional_properties
,
kwargs
)
if
send_snowplow_event
if
Feature
.
enabled?
(
:internal_events_for_product_analytics
)
send_application_instrumentation_event
(
event_name
,
additional_properties
,
kwargs
)
...
...
@@ -180,42 +178,6 @@ def gitlab_sdk_client
GitlabSDK
::
Client
.
new
(
app_id:
app_id
,
host:
host
,
buffer_size:
SNOWPLOW_EMITTER_BUFFER_SIZE
)
end
strong_memoize_attr
:gitlab_sdk_client
def
map_additional_properties
(
event_name
,
additional_properties
)
return
{}
if
additional_properties
.
empty?
properties_mapping
=
additional_properties_mapping
(
event_name
)
additional_properties
.
transform_keys
do
|
key
|
properties_mapping
.
fetch
(
key
,
key
)
end
end
def
additional_properties_mapping
(
event_name
)
definition
=
event_definitions
.
find
do
|
definition
|
definition
.
attributes
[
:action
]
==
event_name
end
return
unless
definition
mapping
=
definition
.
attributes
.
fetch
(
:additional_properties
,
{}).
filter_map
do
|
name
,
config
|
external_key
=
config
[
:external_key
]
next
unless
external_key
[
external_key
.
to_sym
,
name
]
end
.
to_h
base_property_mapping
.
merge
(
mapping
).
invert
end
def
base_property_mapping
keys
=
ALLOWED_ADDITIONAL_PROPERTIES
.
keys
keys
.
zip
(
keys
).
to_h
end
def
event_definitions
@_event_definitions
||=
Gitlab
::
Tracking
::
EventDefinition
.
definitions
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/internal_events_spec.rb
+
0
−
80
View file @
c1d8da59
...
...
@@ -30,39 +30,6 @@
end
end
shared_context
'with mapped additional properties'
do
let
(
:additional_properties
)
do
{
author:
'author_name'
,
age:
28
}
end
let
(
:aditional_event_config
)
{
{}
}
before
do
config
=
{
action:
event_name
,
additional_properties:
{
author:
{
external_key:
'label'
},
age:
{
external_key:
'value'
}
}.
merge
(
aditional_event_config
)
}
wrong_config
=
config
.
deep_merge
(
properties:
{
author:
{
external_key:
'property'
}
})
event_definition1
=
Gitlab
::
Tracking
::
EventDefinition
.
new
(
'path'
,
config
)
event_definition2
=
Gitlab
::
Tracking
::
EventDefinition
.
new
(
'path'
,
wrong_config
.
merge
(
action:
"action2"
))
event_definition3
=
Gitlab
::
Tracking
::
EventDefinition
.
new
(
'path'
,
wrong_config
.
merge
(
action:
"action3"
))
event_definitions
=
[
event_definition3
,
event_definition1
,
event_definition2
]
allow
(
Gitlab
::
Tracking
::
EventDefinition
).
to
receive
(
:definitions
).
and_return
(
event_definitions
)
described_class
.
instance_variable_set
(
:@_event_definitions
,
nil
)
end
end
def
expect_redis_hll_tracking
(
value_override
=
nil
,
property_name_override
=
nil
)
expected_value
=
value_override
||
unique_value
expected_property_name
=
property_name_override
||
property_name
...
...
@@ -205,42 +172,6 @@ def validate_service_ping_context(service_ping_context)
expect_snowplow_tracking
(
nil
,
additional_properties
)
end
context
"when additional properties have mapped names"
do
include_context
'with mapped additional properties'
it
'is sent to Snowplow'
do
described_class
.
track_event
(
event_name
,
additional_properties:
additional_properties
,
user:
user
,
project:
project
)
expect_snowplow_tracking
(
nil
,
{
label:
'author_name'
,
value:
28
})
end
context
"when there's an additional attribute config without external_key"
do
let
(
:aditional_event_config
)
do
{
another_attribute:
{
description:
'lorem ipsum'
}
}
end
it
'is sent to Snowplow'
do
described_class
.
track_event
(
event_name
,
additional_properties:
additional_properties
,
user:
user
,
project:
project
)
expect_snowplow_tracking
(
nil
,
{
label:
'author_name'
,
value:
28
})
end
end
end
end
context
'when arguments are invalid'
do
...
...
@@ -544,17 +475,6 @@ def validate_service_ping_context(service_ping_context)
track_event
end
context
"when additional properties have mapped names"
do
include_context
'with mapped additional properties'
it
'passes unmapped additional_properties to Product Analytics Ruby SDK'
,
:aggregate_failures
do
expect
(
sdk_client
).
to
receive
(
:identify
).
with
(
user
.
id
)
expect
(
sdk_client
).
to
receive
(
:track
).
with
(
event_name
,
tracked_attributes
)
track_event
end
end
end
context
'when GITLAB_ANALYTICS_ID is nil'
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment