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
603cbbe0
Commit
603cbbe0
authored
Sep 04, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make tests consistent
Update docs
parent
95cf4a76
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
4 deletions
+15
-4
doc/development/telemetry/usage_ping.md
doc/development/telemetry/usage_ping.md
+1
-1
lib/api/helpers.rb
lib/api/helpers.rb
+4
-1
spec/lib/api/helpers_spec.rb
spec/lib/api/helpers_spec.rb
+10
-2
No files found.
doc/development/telemetry/usage_ping.md
View file @
603cbbe0
...
...
@@ -295,7 +295,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
Arguments:
-
`event_name`
: event name.
-
`values`
: values
we count unique events
-
`values`
: values
counted, one value or array of values.
Example usage:
...
...
lib/api/helpers.rb
View file @
603cbbe0
...
...
@@ -537,11 +537,14 @@ module API
)
end
# @param event_name [String] the event name
# @param values [Array|String] the values counted
def
increment_unique_values
(
event_name
,
values
)
raise
"values is empty"
unless
values
.
present?
feature_name
=
"usage_data_
#{
event_name
}
"
raise
"Feature
#{
feature_name
}
not enabled"
unless
Feature
.
enabled?
(
feature_name
)
raise
"Usage ping not enabled"
unless
Gitlab
::
CurrentSettings
.
usage_ping_enabled?
raise
"values is empty"
unless
values
.
present?
Gitlab
::
UsageDataCounters
::
HLLRedisCounter
.
track_event
(
values
,
event_name
)
rescue
=>
error
...
...
spec/lib/api/helpers_spec.rb
View file @
603cbbe0
...
...
@@ -190,7 +190,7 @@ RSpec.describe API::Helpers do
end
describe
'#increment_unique_values'
do
let
(
:value
)
{
"9f302fea-f828-4ca9-aef4-e10bd723c0b3"
}
let
(
:value
)
{
'9f302fea-f828-4ca9-aef4-e10bd723c0b3'
}
let
(
:event_name
)
{
'my_event'
}
let
(
:unknown_event
)
{
'unknown'
}
let
(
:feature
)
{
"usage_data_
#{
event_name
}
"
}
...
...
@@ -222,6 +222,14 @@ RSpec.describe API::Helpers do
subject
.
increment_unique_values
(
unknown_event
,
value
)
end
it
'log an exception for nil values'
do
stub_application_setting
(
usage_ping_enabled:
true
)
expect
(
Rails
.
logger
).
to
receive
(
:warn
).
with
(
"Redis tracking event failed for event:
#{
unknown_event
}
, message: values is empty"
)
subject
.
increment_unique_values
(
unknown_event
,
nil
)
end
end
context
'with feature disabled'
do
...
...
@@ -229,7 +237,7 @@ RSpec.describe API::Helpers do
stub_feature_flags
(
feature
=>
false
)
end
it
"logs an exception"
do
it
'logs an exception'
do
expect
(
Rails
.
logger
).
to
receive
(
:warn
).
with
(
"Redis tracking event failed for event:
#{
event_name
}
, message: Feature
#{
feature
}
not enabled"
)
subject
.
increment_unique_values
(
event_name
,
value
)
...
...
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