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
0cd40a9f
Commit
0cd40a9f
authored
Sep 21, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert to using suffix monthly, weekly
parent
750296a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
53 deletions
+30
-53
lib/gitlab/usage_data_counters/hll_redis_counter.rb
lib/gitlab/usage_data_counters/hll_redis_counter.rb
+10
-25
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
.../lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
+12
-20
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+8
-8
No files found.
lib/gitlab/usage_data_counters/hll_redis_counter.rb
View file @
0cd40a9f
...
...
@@ -12,7 +12,6 @@ module Gitlab
KNOWN_EVENTS_PATH
=
'lib/gitlab/usage_data_counters/known_events.yml'
.
freeze
ALLOWED_AGGREGATIONS
=
%i(daily weekly)
.
freeze
COUNTS_TYPES
=
%i(weekly monthly)
.
freeze
# Track event on entity_id
# Increment a Redis HLL counter for unique event_name and entity_id
...
...
@@ -69,43 +68,29 @@ module Gitlab
end
def
unique_events_data
{
counts_weekly:
counts_for
(
:weekly
),
counts_monthly:
counts_for
(
:monthly
)
}
end
def
known_event?
(
event_name
)
event_for
(
event_name
).
present?
end
private
# type is one of weekly, monthly
def
counts_for
(
type
)
return
unless
type
.
in?
(
COUNTS_TYPES
)
period
=
if
type
==
:weekly
{
start_date:
7
.
days
.
ago
.
to_date
,
end_date:
Date
.
current
}
else
{
start_date:
4
.
weeks
.
ago
.
to_date
,
end_date:
Date
.
current
}
end
categories
.
each_with_object
({})
do
|
category
,
category_results
|
events_names
=
events_for_category
(
category
)
event_results
=
events_names
.
each_with_object
({})
do
|
event
,
hash
|
hash
[
"
#{
event
}
"
]
=
unique_events
(
period
.
merge
(
event_names:
event
))
hash
[
"
#{
event
}
_weekly"
]
=
unique_events
(
event_names:
event
,
start_date:
7
.
days
.
ago
.
to_date
,
end_date:
Date
.
current
)
hash
[
"
#{
event
}
_monthly"
]
=
unique_events
(
event_names:
event
,
start_date:
4
.
weeks
.
ago
.
to_date
,
end_date:
Date
.
current
)
end
if
eligible_for_totals?
(
events_names
)
event_results
[
"total_unique_counts"
]
=
unique_events
(
period
.
merge
(
event_names:
events_names
))
event_results
[
"
#{
category
}
_total_unique_counts_weekly"
]
=
unique_events
(
event_names:
events_names
,
start_date:
7
.
days
.
ago
.
to_date
,
end_date:
Date
.
current
)
event_results
[
"
#{
category
}
_total_unique_counts_monthly"
]
=
unique_events
(
event_names:
events_names
,
start_date:
4
.
weeks
.
ago
.
to_date
,
end_date:
Date
.
current
)
end
category_results
[
"
#{
category
}
"
]
=
event_results
end
end
def
known_event?
(
event_name
)
event_for
(
event_name
).
present?
end
private
# Allow to add totals for events that are in the same redis slot, category and have the same aggregation level
# and if there are more than 1 event
def
eligible_for_totals?
(
events_names
)
...
...
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
View file @
0cd40a9f
...
...
@@ -238,27 +238,19 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
it
'returns the number of unique events for all known events'
do
results
=
{
counts_weekly:
{
"category1"
=>
{
"event1_slot"
=>
1
,
"event2_slot"
=>
1
,
"total_unique_counts"
=>
2
},
"category2"
=>
{
"event3"
=>
1
,
"event4"
=>
1
}
"category1"
=>
{
"event1_slot_weekly"
=>
1
,
"event1_slot_monthly"
=>
1
,
"event2_slot_weekly"
=>
1
,
"event2_slot_monthly"
=>
2
,
"category1_total_unique_counts_weekly"
=>
2
,
"category1_total_unique_counts_monthly"
=>
3
},
counts_monthly:
{
"category1"
=>
{
"event1_slot"
=>
1
,
"event2_slot"
=>
2
,
"total_unique_counts"
=>
3
},
"category2"
=>
{
"event3"
=>
1
,
"event4"
=>
1
}
"category2"
=>
{
"event3_weekly"
=>
1
,
"event3_monthly"
=>
1
,
"event4_weekly"
=>
1
,
"event4_monthly"
=>
1
}
}
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
0cd40a9f
...
...
@@ -1167,18 +1167,18 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
it
'has all know_events'
do
expect
(
subject
).
to
have_key
(
:redis_hll_counters
)
expect
(
subject
[
:redis_hll_counters
].
keys
).
to
match_array
(
[
:counts_weekly
,
:counts_monthly
]
)
expect
(
subject
[
:redis_hll_counters
].
keys
).
to
match_array
(
categories
)
[
:counts_weekly
,
:counts_monthly
].
each
do
|
type
|
categories
.
each
do
|
category
|
metrics
=
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
events_for_category
(
category
)
categories
.
each
do
|
category
|
keys
=
::
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
events_for_category
(
category
)
if
ineligible_total_categories
.
exclude?
(
category
)
metrics
.
append
(
"total_unique_counts"
)
end
metrics
=
keys
.
map
{
|
key
|
"
#{
key
}
_weekly"
}
+
keys
.
map
{
|
key
|
"
#{
key
}
_monthly"
}
expect
(
subject
[
:redis_hll_counters
][
type
][
category
].
keys
).
to
match_array
(
metrics
)
if
ineligible_total_categories
.
exclude?
(
category
)
metrics
.
append
(
"
#{
category
}
_total_unique_counts_weekly"
,
"
#{
category
}
_total_unique_counts_monthly"
)
end
expect
(
subject
[
:redis_hll_counters
][
category
].
keys
).
to
match_array
(
metrics
)
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