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
7e4ce995
Commit
7e4ce995
authored
Mar 25, 2021
by
Rajendra Kadam
Committed by
Mikołaj Wawrzyniak
Mar 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return 0 early if there are no events
Add specs for the zero check
parent
f6c065c0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
lib/gitlab/usage_data_counters/hll_redis_counter.rb
lib/gitlab/usage_data_counters/hll_redis_counter.rb
+3
-0
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
.../lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
+10
-0
No files found.
lib/gitlab/usage_data_counters/hll_redis_counter.rb
View file @
7e4ce995
...
...
@@ -151,6 +151,9 @@ module Gitlab
aggregation
=
events
.
first
[
:aggregation
]
keys
=
keys_for_aggregation
(
aggregation
,
events:
events
,
start_date:
start_date
,
end_date:
end_date
,
context:
context
)
return
FALLBACK
unless
keys
.
any?
redis_usage_data
{
Gitlab
::
Redis
::
HLL
.
count
(
keys:
keys
)
}
end
...
...
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
View file @
7e4ce995
...
...
@@ -307,6 +307,11 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
described_class
.
track_event
(
daily_event
,
values:
entity4
,
time:
29
.
days
.
ago
)
end
it
'returns 0 if there are no keys for the given events'
do
expect
(
Gitlab
::
Redis
::
HLL
).
not_to
receive
(
:count
)
expect
(
described_class
.
unique_events
(
event_names:
[
weekly_event
],
start_date:
Date
.
current
,
end_date:
4
.
weeks
.
ago
)).
to
eq
(
-
1
)
end
it
'raise error if metrics are not in the same slot'
do
expect
do
described_class
.
unique_events
(
event_names:
[
compliance_slot_event
,
analytics_slot_event
],
start_date:
4
.
weeks
.
ago
,
end_date:
Date
.
current
)
...
...
@@ -526,6 +531,11 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
expect
{
described_class
.
calculate_events_union
(
**
time_range
.
merge
(
event_names:
%w[event1_slot event4]
))
}.
to
raise_error
described_class
::
SlotMismatch
expect
{
described_class
.
calculate_events_union
(
**
time_range
.
merge
(
event_names:
%w[event5_slot event3_slot]
))
}.
to
raise_error
described_class
::
AggregationMismatch
end
it
'returns 0 if there are no keys for given events'
do
expect
(
Gitlab
::
Redis
::
HLL
).
not_to
receive
(
:count
)
expect
(
described_class
.
calculate_events_union
(
event_names:
%w[event1_slot event2_slot event3_slot]
,
start_date:
Date
.
current
,
end_date:
4
.
weeks
.
ago
)).
to
eq
(
-
1
)
end
end
describe
'.weekly_time_range'
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