debian-mirror-gitlab/lib/api/usage_data.rb

52 lines
1.3 KiB
Ruby
Raw Normal View History

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-03-08 18:12:59 +05:30
feature_category :usage_ping
2021-01-29 00:20:46 +05:30
2020-11-24 15:15:51 +05:30
namespace 'usage_data' do
before do
2021-04-29 21:17:54 +05:30
not_found! unless Feature.enabled?(:usage_data_api, default_enabled: :yaml, type: :ops)
2020-11-24 15:15:51 +05:30
forbidden!('Invalid CSRF token is provided') unless verified_request?
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
2021-02-22 17:27:13 +05:30
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-11-24 15:15:51 +05:30
post 'increment_unique_users' do
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.'
end
get 'metric_definitions' do
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