2020-09-10 08:08:54 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class UsageData < ::API::Base
|
2021-04-09 05:09:10 -04:00
|
|
|
before { authenticate_non_get! }
|
2020-09-10 08:08:54 -04:00
|
|
|
|
2021-07-06 14:08:17 -04:00
|
|
|
feature_category :service_ping
|
2020-10-30 14:08:56 -04:00
|
|
|
|
2020-09-10 08:08:54 -04:00
|
|
|
namespace 'usage_data' do
|
|
|
|
before do
|
2021-03-26 08:09:15 -04:00
|
|
|
not_found! unless Feature.enabled?(:usage_data_api, default_enabled: :yaml, type: :ops)
|
2020-09-11 08:08:50 -04:00
|
|
|
forbidden!('Invalid CSRF token is provided') unless verified_request?
|
2020-09-10 08:08:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Track usage data events' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.4.'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :event, type: String, desc: 'The event name that should be tracked'
|
|
|
|
end
|
2020-11-19 10:09:13 -05:00
|
|
|
post 'increment_counter' do
|
|
|
|
event_name = params[:event]
|
|
|
|
|
|
|
|
increment_counter(event_name)
|
|
|
|
|
|
|
|
status :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :event, type: String, desc: 'The event name that should be tracked'
|
|
|
|
end
|
2020-09-10 08:08:54 -04:00
|
|
|
post 'increment_unique_users' do
|
|
|
|
event_name = params[:event]
|
|
|
|
|
|
|
|
increment_unique_values(event_name, current_user.id)
|
|
|
|
|
|
|
|
status :ok
|
|
|
|
end
|
2021-04-09 05:09:10 -04:00
|
|
|
|
|
|
|
desc 'Get a list of all metric definitions' do
|
|
|
|
detail 'This feature was introduced in GitLab 13.11.'
|
|
|
|
end
|
|
|
|
get 'metric_definitions' do
|
|
|
|
content_type 'application/yaml'
|
|
|
|
env['api.format'] = :binary
|
|
|
|
|
|
|
|
Gitlab::Usage::MetricDefinition.dump_metrics_yaml
|
|
|
|
end
|
2020-09-10 08:08:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|