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
b6cb0e6e
Commit
b6cb0e6e
authored
Sep 08, 2020
by
Alina Mihaila
Committed by
Sean McGivern
Sep 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for usage ping enabled when tracking using Redis HLL
parent
3c96d96d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
38 deletions
+61
-38
changelogs/unreleased/245247-check-for-usage-ping-enabled-when-tracking-using-redis-hll.yml
...-for-usage-ping-enabled-when-tracking-using-redis-hll.yml
+5
-0
lib/gitlab/usage_data_counters/hll_redis_counter.rb
lib/gitlab/usage_data_counters/hll_redis_counter.rb
+2
-0
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
.../lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
+54
-38
No files found.
changelogs/unreleased/245247-check-for-usage-ping-enabled-when-tracking-using-redis-hll.yml
0 → 100644
View file @
b6cb0e6e
---
title
:
Check if usage ping enabled for all tracking using Redis HLL
merge_request
:
41562
author
:
type
:
added
lib/gitlab/usage_data_counters/hll_redis_counter.rb
View file @
b6cb0e6e
...
...
@@ -34,6 +34,8 @@ module Gitlab
# * Get unique counts per user: Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: 'g_compliance_dashboard', start_date: 28.days.ago, end_date: Date.current)
class
<<
self
def
track_event
(
entity_id
,
event_name
,
time
=
Time
.
zone
.
now
)
return
unless
Gitlab
::
CurrentSettings
.
usage_ping_enabled?
event
=
event_for
(
event_name
)
raise
UnknownEvent
.
new
(
"Unknown event
#{
event_name
}
"
)
unless
event
.
present?
...
...
spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb
View file @
b6cb0e6e
...
...
@@ -62,65 +62,81 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
describe
'.track_event'
do
it
"raise error if metrics don't have same aggregation"
do
expect
{
described_class
.
track_event
(
entity1
,
different_aggregation
,
Date
.
current
)
}
.
to
raise_error
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
::
UnknownAggregation
)
end
context
'when usage_ping is disabled'
do
it
'does not track the event'
do
stub_application_setting
(
usage_ping_enabled:
false
)
it
'raise error if metrics of unknown aggregation'
do
expect
{
described_class
.
track_event
(
entity1
,
'unknown'
,
Date
.
current
)
}
.
to
raise_error
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
::
UnknownEvent
)
described_class
.
track_event
(
entity1
,
weekly_event
,
Date
.
current
)
expect
(
Gitlab
::
Redis
::
HLL
).
not_to
receive
(
:add
)
end
end
context
'for weekly events'
do
it
'sets the keys in Redis to expire automatically after the given expiry time'
do
described_class
.
track_event
(
entity1
,
"g_analytics_contribution"
)
context
'when usage_ping is enabled'
do
before
do
stub_application_setting
(
usage_ping_enabled:
true
)
end
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"g_{analytics}_contribution-*"
).
to_a
expect
(
keys
).
not_to
be_empty
it
"raise error if metrics don't have same aggregation"
do
expect
{
described_class
.
track_event
(
entity1
,
different_aggregation
,
Date
.
current
)
}
.
to
raise_error
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
::
UnknownAggregation
)
end
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
12
.
weeks
)
it
'raise error if metrics of unknown aggregation'
do
expect
{
described_class
.
track_event
(
entity1
,
'unknown'
,
Date
.
current
)
}
.
to
raise_error
(
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
::
UnknownEvent
)
end
context
'for weekly events'
do
it
'sets the keys in Redis to expire automatically after the given expiry time'
do
described_class
.
track_event
(
entity1
,
"g_analytics_contribution"
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"g_{analytics}_contribution-*"
).
to_a
expect
(
keys
).
not_to
be_empty
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
12
.
weeks
)
end
end
end
end
it
'sets the keys in Redis to expire automatically after 6 weeks by default'
do
described_class
.
track_event
(
entity1
,
"g_compliance_dashboard"
)
it
'sets the keys in Redis to expire automatically after 6 weeks by default'
do
described_class
.
track_event
(
entity1
,
"g_compliance_dashboard"
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"g_{compliance}_dashboard-*"
).
to_a
expect
(
keys
).
not_to
be_empty
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"g_{compliance}_dashboard-*"
).
to_a
expect
(
keys
).
not_to
be_empty
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
6
.
weeks
)
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
6
.
weeks
)
end
end
end
end
end
context
'for daily events'
do
it
'sets the keys in Redis to expire after the given expiry time'
do
described_class
.
track_event
(
entity1
,
"g_analytics_search"
)
context
'for daily events'
do
it
'sets the keys in Redis to expire after the given expiry time'
do
described_class
.
track_event
(
entity1
,
"g_analytics_search"
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"*-g_{analytics}_search"
).
to_a
expect
(
keys
).
not_to
be_empty
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"*-g_{analytics}_search"
).
to_a
expect
(
keys
).
not_to
be_empty
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
84
.
days
)
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
84
.
days
)
end
end
end
end
it
'sets the keys in Redis to expire after 29 days by default'
do
described_class
.
track_event
(
entity1
,
"no_slot"
)
it
'sets the keys in Redis to expire after 29 days by default'
do
described_class
.
track_event
(
entity1
,
"no_slot"
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"*-{no_slot}"
).
to_a
expect
(
keys
).
not_to
be_empty
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
keys
=
redis
.
scan_each
(
match:
"*-{no_slot}"
).
to_a
expect
(
keys
).
not_to
be_empty
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
29
.
days
)
keys
.
each
do
|
key
|
expect
(
redis
.
ttl
(
key
)).
to
be_within
(
5
.
seconds
).
of
(
29
.
days
)
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