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
aa7f162b
Commit
aa7f162b
authored
Sep 07, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UsageData API
- Add increment_unique_values
parent
f9e2925d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
0 deletions
+100
-0
doc/development/telemetry/usage_ping.md
doc/development/telemetry/usage_ping.md
+28
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/usage_data.rb
lib/api/usage_data.rb
+26
-0
spec/requests/api/usage_data_spec.rb
spec/requests/api/usage_data_spec.rb
+45
-0
No files found.
doc/development/telemetry/usage_ping.md
View file @
aa7f162b
...
...
@@ -312,6 +312,34 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
end
```
1.
Track event using
`UsageData`
API
Increment unique values 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.
```
plaintext
POST /usage_data/increment_unique_values
```
| Attribute | Type | Required | Description |
| :-------- | :--- | :------- | :---------- |
|
`name`
| string | yes | The event name it should be tracked |
|
`values`
| array | yes | The values counted |
Response
Return 200 if tracking failed for any reason.
-
`401 Unauthorized`
if not authorized
-
`400 Bad request`
if name parameter is missing
-
`200`
if event was tracked or any errors
Example usage:
```
shell
curl
--header
"Authorization: Bearer OAUTH-TOKEN"
"https://gitlab.example.com/api/v4/usage_data/increment_unique_users"
--data
"name=event_name&values[]=value1&values[]=value2"
```
1.
Track event using base module
`Gitlab::UsageDataCounters::HLLRedisCounter.track_event(entity_id, event_name)`
.
Arguments:
...
...
lib/api/api.rb
View file @
aa7f162b
...
...
@@ -235,6 +235,7 @@ module API
mount
::
API
::
Templates
mount
::
API
::
Todos
mount
::
API
::
Triggers
mount
::
API
::
UsageData
mount
::
API
::
UserCounts
mount
::
API
::
Users
mount
::
API
::
Variables
...
...
lib/api/usage_data.rb
0 → 100644
View file @
aa7f162b
# frozen_string_literal: true
module
API
class
UsageData
<
Grape
::
API
::
Instance
before
{
authenticate!
}
namespace
'usage_data'
do
desc
'Track usage data events'
do
detail
'This feature was introduced in GitLab 13.4.'
end
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_values'
do
event_name
=
params
[
:name
]
values
=
params
[
:values
]
increment_unique_values
(
event_name
,
values
)
status
:ok
end
end
end
end
spec/requests/api/usage_data_spec.rb
0 → 100644
View file @
aa7f162b
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
API
::
UsageData
do
let_it_be
(
:user
)
{
create
(
:user
)
}
describe
'POST /usage_data/increment_unique_values'
do
let
(
:endpoint
)
{
'/usage_data/increment_unique_values'
}
let
(
:known_event
)
{
'g_compliance_dashboard'
}
let
(
:unknown_event
)
{
'unknown'
}
context
'when unauthenticated'
do
it
'retruns 401 response'
do
post
api
(
endpoint
),
params:
{
values:
[
user
.
id
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
context
'when name is missing from params'
do
it
'returns bad request'
do
post
api
(
endpoint
,
user
),
params:
{
values:
[
user
.
id
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with correct params'
do
it
'returns status ok'
do
post
api
(
endpoint
,
user
),
params:
{
name:
known_event
,
values:
[
user
.
id
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
context
'with unknown event'
do
it
'returns status ok'
do
post
api
(
endpoint
,
user
),
params:
{
name:
unknown_event
,
values:
[
user
.
id
]
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
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