2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2021-01-03 14:25:43 +05:30
|
|
|
class UsageData < ::API::Base
|
2021-04-29 21:17:54 +05:30
|
|
|
before { authenticate_non_get! }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
feature_category :service_ping
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
namespace 'usage_data' do
|
|
|
|
before do
|
2022-07-16 23:28:13 +05:30
|
|
|
not_found! unless Feature.enabled?(:usage_data_api, type: :ops)
|
2020-11-24 15:15:51 +05:30
|
|
|
forbidden!('Invalid CSRF token is provided') unless verified_request?
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
desc 'Track usage data event' do
|
2020-11-24 15:15:51 +05:30
|
|
|
detail 'This feature was introduced in GitLab 13.4.'
|
2023-03-04 22:38:38 +05:30
|
|
|
success code: 200
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Invalid CSRF token is provided' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[usage_data]
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
params do
|
2023-03-04 22:38:38 +05:30
|
|
|
requires :event, type: String, desc: 'The event name that should be tracked',
|
|
|
|
documentation: { example: 'i_quickactions_page' }
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
post 'increment_counter' do
|
|
|
|
event_name = params[:event]
|
|
|
|
|
|
|
|
increment_counter(event_name)
|
|
|
|
|
|
|
|
status :ok
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
desc 'Track usage data event for the current user' do
|
|
|
|
success code: 200
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Invalid CSRF token is provided' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
tags %w[usage_data]
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
params do
|
2023-03-04 22:38:38 +05:30
|
|
|
requires :event, type: String, desc: 'The event name that should be tracked',
|
|
|
|
documentation: { example: 'i_quickactions_page' }
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
post 'increment_unique_users', urgency: :low do
|
2020-11-24 15:15:51 +05:30
|
|
|
event_name = params[:event]
|
|
|
|
|
|
|
|
increment_unique_values(event_name, current_user.id)
|
|
|
|
|
|
|
|
status :ok
|
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
desc 'Get a list of all metric definitions' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.11.'
|
2023-03-04 22:38:38 +05:30
|
|
|
success code: 200
|
|
|
|
failure [
|
|
|
|
{ code: 403, message: 'Invalid CSRF token is provided' },
|
|
|
|
{ code: 404, message: 'Not found' }
|
|
|
|
]
|
|
|
|
produces ['application/yaml']
|
|
|
|
tags %w[usage_data metrics]
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2022-07-16 23:28:13 +05:30
|
|
|
get 'metric_definitions', urgency: :low do
|
2021-04-29 21:17:54 +05:30
|
|
|
content_type 'application/yaml'
|
|
|
|
env['api.format'] = :binary
|
|
|
|
|
|
|
|
Gitlab::Usage::MetricDefinition.dump_metrics_yaml
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|