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
c8c6f528
Commit
c8c6f528
authored
Sep 09, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API will incremnt users only
parent
5c9d7ca2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
47 deletions
+14
-47
doc/development/telemetry/usage_ping.md
doc/development/telemetry/usage_ping.md
+4
-6
lib/api/usage_data.rb
lib/api/usage_data.rb
+2
-17
spec/requests/api/usage_data_spec.rb
spec/requests/api/usage_data_spec.rb
+8
-24
No files found.
doc/development/telemetry/usage_ping.md
View file @
c8c6f528
...
...
@@ -314,27 +314,25 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
1.
Track event using
`UsageData`
API
Increment unique
value
s count using Redis HLL, for given event name.
Increment unique
user
s count using Redis HLL, for given event name.
In order to be able to increment the values the related feature
`usage_data<event_name>`
should be enabled.
It is allowed to send an array of maximum 10 strings of maximum size 36.
```
plaintext
POST /usage_data/increment_unique_
value
s
POST /usage_data/increment_unique_
user
s
```
| Attribute | Type | Required | Description |
| :-------- | :--- | :------- | :---------- |
|
`name`
| string | yes | The event name it should be tracked |
|
`values`
| array | yes | The values counted, maximum 10 string elements of size 36 |
Response
Return 200 if tracking failed for any reason.
-
`401 Unauthorized`
if user is not authenticated
-
`400 Bad request`
if name parameter is missing
, or validation errors
-
`400 Bad request`
if name parameter is missing
-
`200`
if event was tracked or any errors
1.
Track event using base module
`Gitlab::UsageDataCounters::HLLRedisCounter.track_event(entity_id, event_name)`
.
...
...
lib/api/usage_data.rb
View file @
c8c6f528
...
...
@@ -4,15 +4,6 @@ module API
class
UsageData
<
Grape
::
API
::
Instance
before
{
authenticate!
}
ALLOWED_ARRAY_SIZE
=
10
ALLOWED_VALUE_SIZE
=
36
helpers
do
def
valid_values
(
values
)
values
.
size
<=
ALLOWED_ARRAY_SIZE
&&
values
.
all?
{
|
value
|
value
.
is_a?
(
String
)
&&
value
.
size
<=
ALLOWED_VALUE_SIZE
}
end
end
namespace
'usage_data'
do
before
do
not_found!
unless
Feature
.
enabled?
(
:usage_data_api
,
default_enabled:
true
)
...
...
@@ -24,18 +15,12 @@ module API
params
do
requires
:name
,
type:
String
,
desc:
'The event name it should be tracked'
requires
:values
,
type:
Array
,
desc:
'The values counted'
end
post
'increment_unique_
value
s'
do
post
'increment_unique_
user
s'
do
event_name
=
params
[
:name
]
values
=
params
[
:values
]
unless
valid_values
(
values
)
render_api_error!
(
'values needs to be an array of maxim 10 elements of strings of size maximum 36'
,
400
)
end
increment_unique_values
(
event_name
,
values
)
increment_unique_values
(
event_name
,
current_user
.
id
)
status
:ok
end
...
...
spec/requests/api/usage_data_spec.rb
View file @
c8c6f528
...
...
@@ -5,16 +5,16 @@ require 'spec_helper'
RSpec
.
describe
API
::
UsageData
do
let_it_be
(
:user
)
{
create
(
:user
)
}
describe
'POST /usage_data/increment_unique_
value
s'
do
let
(
:endpoint
)
{
'/usage_data/increment_unique_
value
s'
}
describe
'POST /usage_data/increment_unique_
user
s'
do
let
(
:endpoint
)
{
'/usage_data/increment_unique_
user
s'
}
let
(
:known_event
)
{
'g_compliance_dashboard'
}
let
(
:unknown_event
)
{
'unknown'
}
context
'usage_data_api feature not enabled'
do
it
'ret
ur
ns not_found'
do
it
'ret
ru
ns not_found'
do
stub_feature_flags
(
usage_data_api:
false
)
post
api
(
endpoint
,
user
),
params:
{
values:
[
user
.
id
]
}
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
}
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
...
...
@@ -22,7 +22,7 @@ RSpec.describe API::UsageData do
context
'without authentication'
do
it
'returns 401 response'
do
post
api
(
endpoint
),
params:
{
values:
[
user
.
id
]
}
post
api
(
endpoint
),
params:
{
name:
known_event
}
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
...
...
@@ -35,7 +35,7 @@ RSpec.describe API::UsageData do
context
'when name is missing from params'
do
it
'returns bad request'
do
post
api
(
endpoint
,
user
),
params:
{
values:
[
user
.
id
]
}
post
api
(
endpoint
,
user
),
params:
{}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
...
...
@@ -43,7 +43,7 @@ RSpec.describe API::UsageData do
context
'with correct params'
do
it
'returns status ok'
do
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
,
values:
[
user
.
id
]
}
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
...
...
@@ -51,27 +51,11 @@ RSpec.describe API::UsageData do
context
'with unknown event'
do
it
'returns status ok'
do
post
api
(
endpoint
,
user
),
params:
{
name:
unknown_event
,
values:
[
user
.
id
]
}
post
api
(
endpoint
,
user
),
params:
{
name:
unknown_event
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
context
'with 11 elements'
do
it
'returns bad request'
do
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
,
values:
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with value of 37 chars'
do
it
'returns bad request'
do
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
,
values:
[
'48ee87e2-7da5-4299-a56d-0424d5c5dab1e'
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
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