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
bdc3587f
Commit
bdc3587f
authored
Nov 23, 2020
by
ggelatti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Triggers package guest events
Triggers pkg guest event tracking using redis counter.
parent
465e5f66
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
5 deletions
+70
-5
app/services/packages/create_event_service.rb
app/services/packages/create_event_service.rb
+3
-1
changelogs/unreleased/205578-trigger-pkg-guest-events.yml
changelogs/unreleased/205578-trigger-pkg-guest-events.yml
+5
-0
lib/gitlab/usage_data_counters/guest_package_events.yml
lib/gitlab/usage_data_counters/guest_package_events.yml
+34
-0
spec/services/packages/create_event_service_spec.rb
spec/services/packages/create_event_service_spec.rb
+24
-0
spec/tasks/gitlab/packages/events_rake_spec.rb
spec/tasks/gitlab/packages/events_rake_spec.rb
+4
-4
No files found.
app/services/packages/create_event_service.rb
View file @
bdc3587f
...
@@ -4,7 +4,9 @@ module Packages
...
@@ -4,7 +4,9 @@ module Packages
class
CreateEventService
<
BaseService
class
CreateEventService
<
BaseService
def
execute
def
execute
if
Feature
.
enabled?
(
:collect_package_events_redis
)
&&
redis_event_name
if
Feature
.
enabled?
(
:collect_package_events_redis
)
&&
redis_event_name
unless
guest?
if
guest?
::
Gitlab
::
UsageDataCounters
::
GuestPackageEventCounter
.
count
(
redis_event_name
)
else
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
track_event
(
current_user
.
id
,
redis_event_name
)
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
track_event
(
current_user
.
id
,
redis_event_name
)
end
end
end
end
...
...
changelogs/unreleased/205578-trigger-pkg-guest-events.yml
0 → 100644
View file @
bdc3587f
---
title
:
Tracks guest package events
merge_request
:
48547
author
:
type
:
added
lib/gitlab/usage_data_counters/guest_package_events.yml
0 → 100644
View file @
bdc3587f
---
-
i_package_composer_guest_delete
-
i_package_composer_guest_pull
-
i_package_composer_guest_push
-
i_package_conan_guest_delete
-
i_package_conan_guest_pull
-
i_package_conan_guest_push
-
i_package_container_guest_delete
-
i_package_container_guest_pull
-
i_package_container_guest_push
-
i_package_debian_guest_delete
-
i_package_debian_guest_pull
-
i_package_debian_guest_push
-
i_package_generic_guest_delete
-
i_package_generic_guest_pull
-
i_package_generic_guest_push
-
i_package_golang_guest_delete
-
i_package_golang_guest_pull
-
i_package_golang_guest_push
-
i_package_maven_guest_delete
-
i_package_maven_guest_pull
-
i_package_maven_guest_push
-
i_package_npm_guest_delete
-
i_package_npm_guest_pull
-
i_package_npm_guest_push
-
i_package_nuget_guest_delete
-
i_package_nuget_guest_pull
-
i_package_nuget_guest_push
-
i_package_pypi_guest_delete
-
i_package_pypi_guest_pull
-
i_package_pypi_guest_push
-
i_package_tag_guest_delete
-
i_package_tag_guest_pull
-
i_package_tag_guest_push
spec/services/packages/create_event_service_spec.rb
View file @
bdc3587f
...
@@ -70,12 +70,34 @@ RSpec.describe Packages::CreateEventService do
...
@@ -70,12 +70,34 @@ RSpec.describe Packages::CreateEventService do
end
end
it
'tracks the event'
do
it
'tracks the event'
do
expect
(
::
Gitlab
::
UsageDataCounters
::
GuestPackageEventCounter
).
not_to
receive
(
:count
)
expect
(
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
receive
(
:track_event
).
with
(
user
.
id
,
Packages
::
Event
.
allowed_event_name
(
expected_scope
,
event_name
,
originator_type
))
expect
(
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
to
receive
(
:track_event
).
with
(
user
.
id
,
Packages
::
Event
.
allowed_event_name
(
expected_scope
,
event_name
,
originator_type
))
subject
subject
end
end
end
end
shared_examples
'redis package guest event creation'
do
|
originator_type
,
expected_scope
|
context
'with feature flag disabled'
do
before
do
stub_feature_flags
(
collect_package_events_redis:
false
)
end
it
'does not track the event'
do
expect
(
::
Gitlab
::
UsageDataCounters
::
GuestPackageEventCounter
).
not_to
receive
(
:count
)
subject
end
end
it
'tracks the event'
do
expect
(
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
).
not_to
receive
(
:track_event
)
expect
(
::
Gitlab
::
UsageDataCounters
::
GuestPackageEventCounter
).
to
receive
(
:count
).
with
(
Packages
::
Event
.
allowed_event_name
(
expected_scope
,
event_name
,
originator_type
))
subject
end
end
context
'with a user'
do
context
'with a user'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
@@ -94,6 +116,7 @@ RSpec.describe Packages::CreateEventService do
...
@@ -94,6 +116,7 @@ RSpec.describe Packages::CreateEventService do
let
(
:user
)
{
nil
}
let
(
:user
)
{
nil
}
it_behaves_like
'db package event creation'
,
'guest'
,
'container'
it_behaves_like
'db package event creation'
,
'guest'
,
'container'
it_behaves_like
'redis package guest event creation'
,
'guest'
,
'container'
end
end
context
'with a package as scope'
do
context
'with a package as scope'
do
...
@@ -103,6 +126,7 @@ RSpec.describe Packages::CreateEventService do
...
@@ -103,6 +126,7 @@ RSpec.describe Packages::CreateEventService do
let
(
:user
)
{
nil
}
let
(
:user
)
{
nil
}
it_behaves_like
'db package event creation'
,
'guest'
,
'npm'
it_behaves_like
'db package event creation'
,
'guest'
,
'npm'
it_behaves_like
'redis package guest event creation'
,
'guest'
,
'npm'
end
end
context
'with user'
do
context
'with user'
do
...
...
spec/tasks/gitlab/packages/events_rake_spec.rb
View file @
bdc3587f
...
@@ -27,14 +27,14 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
...
@@ -27,14 +27,14 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
end
end
Packages
::
Event
::
EVENT_SCOPES
.
keys
.
each
do
|
event_scope
|
Packages
::
Event
::
EVENT_SCOPES
.
keys
.
each
do
|
event_scope
|
it
"includes
includes
`
#{
event_scope
}
` scope"
do
it
"includes `
#{
event_scope
}
` scope"
do
expect
(
subject
.
find
{
|
event
|
event
[
'name'
].
include?
(
event_scope
)
}).
not_to
be_nil
expect
(
subject
.
find
{
|
event
|
event
[
'name'
].
include?
(
event_scope
)
}).
not_to
be_nil
end
end
end
end
it
'excludes some event types'
do
it
'excludes some event types'
do
expect
(
subject
.
find
{
|
event
|
event
[
'name'
].
include?
(
"search_package"
)
}).
to
be_nil
expect
(
subject
.
grep
(
/search_package/
)).
to
be_empty
expect
(
subject
.
find
{
|
event
|
event
[
'name'
].
include?
(
"list_package"
)
}).
to
be_nil
expect
(
subject
.
grep
(
/list_package/
)).
to
be_empty
end
end
end
end
...
@@ -42,7 +42,7 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
...
@@ -42,7 +42,7 @@ RSpec.describe 'gitlab:packages:events namespace rake task' do
let
(
:task
)
{
'generate_guest'
}
let
(
:task
)
{
'generate_guest'
}
Packages
::
Event
::
EVENT_SCOPES
.
keys
.
each
do
|
event_scope
|
Packages
::
Event
::
EVENT_SCOPES
.
keys
.
each
do
|
event_scope
|
it
"includes
includes
`
#{
event_scope
}
` scope"
do
it
"includes `
#{
event_scope
}
` scope"
do
expect
(
subject
.
find
{
|
event
|
event
.
include?
(
event_scope
)
}).
not_to
be_nil
expect
(
subject
.
find
{
|
event
|
event
.
include?
(
event_scope
)
}).
not_to
be_nil
end
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