Welcome to mirror list, hosted at ThFree Co, Russian Federation.

usage_data.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e81a578d4a20e95d67896c46590c6bbd0b76c56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module API
  class UsageData < ::API::Base
    before { authenticate_non_get! }

    feature_category :service_ping

    namespace 'usage_data' do
      before do
        not_found! unless Feature.enabled?(:usage_data_api, type: :ops)
        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
      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
      post 'increment_unique_users' do
        event_name = params[:event]

        increment_unique_values(event_name, current_user.id)

        status :ok
      end

      desc 'Get a list of all metric definitions' do
        detail 'This feature was introduced in GitLab 13.11.'
      end
      get 'metric_definitions', urgency: :low do
        content_type 'application/yaml'
        env['api.format'] = :binary

        Gitlab::Usage::MetricDefinition.dump_metrics_yaml
      end
    end
  end
end