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
92e3de76
Commit
92e3de76
authored
Aug 10, 2020
by
Marc Shaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make TrackUniqueActions methods clearer
Merge Request: gitlab.com/gitlab-org/gitlab/-/merge_requests/39158
parent
82678ecc
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
46 deletions
+46
-46
app/services/event_create_service.rb
app/services/event_create_service.rb
+3
-3
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+3
-3
lib/gitlab/usage_data_counters/track_unique_actions.rb
lib/gitlab/usage_data_counters/track_unique_actions.rb
+2
-2
spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb
...b/gitlab/usage_data_counters/track_unique_actions_spec.rb
+25
-25
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+8
-8
spec/services/event_create_service_spec.rb
spec/services/event_create_service_spec.rb
+5
-5
No files found.
app/services/event_create_service.rb
View file @
92e3de76
...
...
@@ -109,7 +109,7 @@ class EventCreateService
def
wiki_event
(
wiki_page_meta
,
author
,
action
,
fingerprint
)
raise
IllegalActionError
,
action
unless
Event
::
WIKI_ACTIONS
.
include?
(
action
)
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
action
(
event_action:
action
,
event_target:
wiki_page_meta
.
class
,
author_id:
author
.
id
)
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
event
(
event_action:
action
,
event_target:
wiki_page_meta
.
class
,
author_id:
author
.
id
)
duplicate
=
Event
.
for_wiki_meta
(
wiki_page_meta
).
for_fingerprint
(
fingerprint
).
first
return
duplicate
if
duplicate
.
present?
...
...
@@ -154,7 +154,7 @@ class EventCreateService
result
=
Event
.
insert_all
(
attribute_sets
,
returning:
%w[id]
)
tuples
.
each
do
|
record
,
status
,
_
|
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
action
(
event_action:
status
,
event_target:
record
.
class
,
author_id:
current_user
.
id
)
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
event
(
event_action:
status
,
event_target:
record
.
class
,
author_id:
current_user
.
id
)
end
result
...
...
@@ -172,7 +172,7 @@ class EventCreateService
new_event
end
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
action
(
event_action: :pushed
,
event_target:
Project
,
author_id:
current_user
.
id
)
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
.
track_
event
(
event_action: :pushed
,
event_target:
Project
,
author_id:
current_user
.
id
)
Users
::
LastPushEventService
.
new
(
current_user
)
.
cache_last_push_event
(
event
)
...
...
lib/gitlab/usage_data.rb
View file @
92e3de76
...
...
@@ -597,7 +597,7 @@ module Gitlab
counter
=
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
project_count
=
redis_usage_data
do
counter
.
count_unique
_events
(
counter
.
count_unique
(
event_action:
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
::
PUSH_ACTION
,
date_from:
time_period
[
:created_at
].
first
,
date_to:
time_period
[
:created_at
].
last
...
...
@@ -605,7 +605,7 @@ module Gitlab
end
design_count
=
redis_usage_data
do
counter
.
count_unique
_events
(
counter
.
count_unique
(
event_action:
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
::
DESIGN_ACTION
,
date_from:
time_period
[
:created_at
].
first
,
date_to:
time_period
[
:created_at
].
last
...
...
@@ -613,7 +613,7 @@ module Gitlab
end
wiki_count
=
redis_usage_data
do
counter
.
count_unique
_events
(
counter
.
count_unique
(
event_action:
Gitlab
::
UsageDataCounters
::
TrackUniqueActions
::
WIKI_ACTION
,
date_from:
time_period
[
:created_at
].
first
,
date_to:
time_period
[
:created_at
].
last
...
...
lib/gitlab/usage_data_counters/track_unique_actions.rb
View file @
92e3de76
...
...
@@ -27,7 +27,7 @@ module Gitlab
}).
freeze
class
<<
self
def
track_
action
(
event_action
:,
event_target
:,
author_id
:,
time:
Time
.
zone
.
now
)
def
track_
event
(
event_action
:,
event_target
:,
author_id
:,
time:
Time
.
zone
.
now
)
return
unless
Gitlab
::
CurrentSettings
.
usage_ping_enabled
return
unless
Feature
.
enabled?
(
FEATURE_FLAG
)
return
unless
valid_target?
(
event_target
)
...
...
@@ -40,7 +40,7 @@ module Gitlab
Gitlab
::
Redis
::
HLL
.
add
(
key:
target_key
,
value:
author_id
,
expiry:
KEY_EXPIRY_LENGTH
)
end
def
count_unique
_events
(
event_action
:,
date_from
:,
date_to
:)
def
count_unique
(
event_action
:,
date_from
:,
date_to
:)
keys
=
(
date_from
.
to_date
..
date_to
.
to_date
).
map
{
|
date
|
key
(
event_action
,
date
)
}
Gitlab
::
Redis
::
HLL
.
count
(
keys:
keys
)
...
...
spec/lib/gitlab/usage_data_counters/track_unique_actions_spec.rb
View file @
92e3de76
...
...
@@ -7,12 +7,12 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
let
(
:time
)
{
Time
.
zone
.
now
}
def
track_
action
(
params
)
track_unique_events
.
track_
action
(
params
)
def
track_
event
(
params
)
track_unique_events
.
track_
event
(
params
)
end
def
count_unique
_events
(
params
)
track_unique_events
.
count_unique
_events
(
params
)
def
count_unique
(
params
)
track_unique_events
.
count_unique
(
params
)
end
context
'tracking an event'
do
...
...
@@ -29,28 +29,28 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
design
=
Event
::
TARGET_TYPES
[
:design
]
wiki
=
Event
::
TARGET_TYPES
[
:wiki
]
expect
(
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
2
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
3
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
4
,
time:
time
-
3
.
days
)).
to
be_truthy
expect
(
track_
action
(
event_action: :created
,
event_target:
project
,
author_id:
5
,
time:
time
-
3
.
days
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
2
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
3
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
4
,
time:
time
-
3
.
days
)).
to
be_truthy
expect
(
track_
event
(
event_action: :created
,
event_target:
project
,
author_id:
5
,
time:
time
-
3
.
days
)).
to
be_truthy
expect
(
track_
action
(
event_action: :destroyed
,
event_target:
design
,
author_id:
3
)).
to
be_truthy
expect
(
track_
action
(
event_action: :created
,
event_target:
design
,
author_id:
4
)).
to
be_truthy
expect
(
track_
action
(
event_action: :updated
,
event_target:
design
,
author_id:
5
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
design
,
author_id:
6
)).
to
be_truthy
expect
(
track_
event
(
event_action: :destroyed
,
event_target:
design
,
author_id:
3
)).
to
be_truthy
expect
(
track_
event
(
event_action: :created
,
event_target:
design
,
author_id:
4
)).
to
be_truthy
expect
(
track_
event
(
event_action: :updated
,
event_target:
design
,
author_id:
5
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
design
,
author_id:
6
)).
to
be_truthy
expect
(
track_
action
(
event_action: :destroyed
,
event_target:
wiki
,
author_id:
5
)).
to
be_truthy
expect
(
track_
action
(
event_action: :created
,
event_target:
wiki
,
author_id:
3
)).
to
be_truthy
expect
(
track_
action
(
event_action: :updated
,
event_target:
wiki
,
author_id:
4
)).
to
be_truthy
expect
(
track_
action
(
event_action: :pushed
,
event_target:
wiki
,
author_id:
6
)).
to
be_truthy
expect
(
track_
event
(
event_action: :destroyed
,
event_target:
wiki
,
author_id:
5
)).
to
be_truthy
expect
(
track_
event
(
event_action: :created
,
event_target:
wiki
,
author_id:
3
)).
to
be_truthy
expect
(
track_
event
(
event_action: :updated
,
event_target:
wiki
,
author_id:
4
)).
to
be_truthy
expect
(
track_
event
(
event_action: :pushed
,
event_target:
wiki
,
author_id:
6
)).
to
be_truthy
expect
(
count_unique
_events
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
_events
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
tomorrow
)).
to
eq
(
4
)
expect
(
count_unique
_events
(
event_action:
described_class
::
DESIGN_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
_events
(
event_action:
described_class
::
WIKI_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
_events
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
time
-
2
.
days
)).
to
eq
(
1
)
expect
(
count_unique
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
tomorrow
)).
to
eq
(
4
)
expect
(
count_unique
(
event_action:
described_class
::
DESIGN_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
(
event_action:
described_class
::
WIKI_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
Date
.
today
)).
to
eq
(
3
)
expect
(
count_unique
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
-
5
.
days
,
date_to:
time
-
2
.
days
)).
to
eq
(
1
)
end
end
end
...
...
@@ -73,8 +73,8 @@ RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redi
end
it
'returns the expected values'
do
expect
(
track_
action
(
event_action:
action
,
event_target:
target
,
author_id:
2
)).
to
be_nil
expect
(
count_unique
_events
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
,
date_to:
Date
.
today
)).
to
eq
(
0
)
expect
(
track_
event
(
event_action:
action
,
event_target:
target
,
author_id:
2
)).
to
be_nil
expect
(
count_unique
(
event_action:
described_class
::
PUSH_ACTION
,
date_from:
time
,
date_to:
Date
.
today
)).
to
eq
(
0
)
end
end
end
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
92e3de76
...
...
@@ -924,14 +924,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
wiki
=
Event
::
TARGET_TYPES
[
:wiki
]
design
=
Event
::
TARGET_TYPES
[
:design
]
counter
.
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)
counter
.
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)
counter
.
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
2
)
counter
.
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
3
)
counter
.
track_
action
(
event_action: :pushed
,
event_target:
project
,
author_id:
4
,
time:
time
-
3
.
days
)
counter
.
track_
action
(
event_action: :created
,
event_target:
project
,
author_id:
5
,
time:
time
-
3
.
days
)
counter
.
track_
action
(
event_action: :created
,
event_target:
wiki
,
author_id:
3
)
counter
.
track_
action
(
event_action: :created
,
event_target:
design
,
author_id:
3
)
counter
.
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)
counter
.
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
1
)
counter
.
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
2
)
counter
.
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
3
)
counter
.
track_
event
(
event_action: :pushed
,
event_target:
project
,
author_id:
4
,
time:
time
-
3
.
days
)
counter
.
track_
event
(
event_action: :created
,
event_target:
project
,
author_id:
5
,
time:
time
-
3
.
days
)
counter
.
track_
event
(
event_action: :created
,
event_target:
wiki
,
author_id:
3
)
counter
.
track_
event
(
event_action: :created
,
event_target:
design
,
author_id:
3
)
end
it
'returns the distinct count of user actions within the specified time period'
do
...
...
spec/services/event_create_service_spec.rb
View file @
92e3de76
...
...
@@ -207,7 +207,7 @@ RSpec.describe EventCreateService do
tracking_params
=
{
event_action:
counter_class
::
WIKI_ACTION
,
date_from:
Date
.
yesterday
,
date_to:
Date
.
today
}
expect
{
create_event
}
.
to
change
{
counter_class
.
count_unique
_events
(
tracking_params
)
}
.
to
change
{
counter_class
.
count_unique
(
tracking_params
)
}
.
by
(
1
)
end
end
...
...
@@ -249,7 +249,7 @@ RSpec.describe EventCreateService do
tracking_params
=
{
event_action:
counter_class
::
PUSH_ACTION
,
date_from:
Date
.
yesterday
,
date_to:
Date
.
today
}
expect
{
subject
}
.
to
change
{
counter_class
.
count_unique
_events
(
tracking_params
)
}
.
to
change
{
counter_class
.
count_unique
(
tracking_params
)
}
.
from
(
0
).
to
(
1
)
end
end
...
...
@@ -273,7 +273,7 @@ RSpec.describe EventCreateService do
tracking_params
=
{
event_action:
counter_class
::
PUSH_ACTION
,
date_from:
Date
.
yesterday
,
date_to:
Date
.
today
}
expect
{
subject
}
.
to
change
{
counter_class
.
count_unique
_events
(
tracking_params
)
}
.
to
change
{
counter_class
.
count_unique
(
tracking_params
)
}
.
from
(
0
).
to
(
1
)
end
end
...
...
@@ -328,7 +328,7 @@ RSpec.describe EventCreateService do
tracking_params
=
{
event_action:
counter_class
::
DESIGN_ACTION
,
date_from:
Date
.
yesterday
,
date_to:
Date
.
today
}
expect
{
result
}
.
to
change
{
counter_class
.
count_unique
_events
(
tracking_params
)
}
.
to
change
{
counter_class
.
count_unique
(
tracking_params
)
}
.
from
(
0
).
to
(
1
)
end
end
...
...
@@ -356,7 +356,7 @@ RSpec.describe EventCreateService do
tracking_params
=
{
event_action:
counter_class
::
DESIGN_ACTION
,
date_from:
Date
.
yesterday
,
date_to:
Date
.
today
}
expect
{
result
}
.
to
change
{
counter_class
.
count_unique
_events
(
tracking_params
)
}
.
to
change
{
counter_class
.
count_unique
(
tracking_params
)
}
.
from
(
0
).
to
(
1
)
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